stylelint

  • Version 16.18.0
  • Published
  • 1.64 MB
  • 38 dependencies
  • MIT license

Install

npm i stylelint
yarn add stylelint
pnpm add stylelint

Overview

A mighty CSS linter that helps you avoid errors and enforce conventions.

Index

Variables

variable stylelint

const stylelint: any;

    Type Aliases

    type AutofixMessage

    type AutofixMessage = { expected: (actual: string, expected: string) => string };

      type Config

      type Config = {
      /**
      * Allows to extend an existing configuration. Configurations can bundle plugins, custom syntaxes,
      * options, and configure rules. They can also extend other configurations
      *
      * @see [extends](https://stylelint.io/user-guide/configure/#extends)
      */
      extends?: ConfigExtends;
      /**
      * Custom rules or sets of custom rules built to support methodologies, toolsets,
      * non-standard CSS features, or very specific use cases
      *
      * @see [plugins](https://stylelint.io/user-guide/configure/#plugins)
      */
      plugins?: ConfigPlugins;
      pluginFunctions?: {
      [pluginName: string]: Rule;
      };
      /**
      * A glob or array of globs to ignore specific files
      *
      * @default 'node_modules'
      *
      * @see [ignoreFiles](https://stylelint.io/user-guide/configure/#ignorefiles)
      */
      ignoreFiles?: ConfigIgnoreFiles;
      ignorePatterns?: string;
      /**
      * An object containing the configured rules
      *
      * @see [rules](https://stylelint.io/user-guide/configure/#rules)
      */
      rules?: ConfigRules;
      /**
      * Only register problems for rules with an "error"-level severity (ignore "warning"-level)
      *
      * @see [quiet](https://stylelint.io/user-guide/options/#quiet)
      */
      quiet?: boolean;
      /**
      * A string to specify the name of a formatter or a path to a custom formatter function
      *
      * @see [formatter](https://stylelint.io/user-guide/configure#formatter)
      */
      formatter?: FormatterType | Formatter;
      /**
      * A string to set the default severity level for all rules that do not have a severity
      * specified in their secondary options
      *
      * @see [defaultSeverity](https://stylelint.io/user-guide/configure#defaultseverity)
      */
      defaultSeverity?: Severity;
      /**
      * A boolean value indicating if 'stylelint-disable' comments will be ignored
      *
      * @see [ignoreDisables](https://stylelint.io/user-guide/configure#ignoredisables)
      */
      ignoreDisables?: boolean;
      /**
      * Report configuration comments that don't match any lints that need to be disabled
      *
      * @see [reportNeedlessDisables](https://stylelint.io/user-guide/configure#reportneedlessdisables)
      */
      reportNeedlessDisables?: DisableSettings;
      /**
      * Report configuration comments that don't match rules that are specified in the configuration object
      *
      * @see [reportInvalidScopeDisables](https://stylelint.io/user-guide/configure#reportinvalidscopedisables)
      */
      reportInvalidScopeDisables?: DisableSettings;
      /**
      * Report configuration comments without a description
      *
      * @see [reportDescriptionlessDisables](https://stylelint.io/user-guide/configure#reportdescriptionlessdisables)
      */
      reportDescriptionlessDisables?: DisableSettings;
      /**
      * Report configuration comments that are not scoped to at least one rule
      *
      * @see [reportUnscopedDisables](https://stylelint.io/user-guide/configure#reportunscopeddisables)
      */
      reportUnscopedDisables?: DisableSettings;
      /**
      * A string to set what configuration comments like 'stylelint-disable' start with.
      * Сan be useful when using multiple instances of Stylelint with different configurations.
      *
      * @see [configurationComment](https://stylelint.io/user-guide/configure#configurationcomment)
      */
      configurationComment?: string;
      /**
      * An array of objects to specify what subset of files to apply a configuration to
      *
      * @see [overrides](https://stylelint.io/user-guide/configure#overrides)
      */
      overrides?: ConfigOverride[];
      /**
      * Allows to specify a custom syntax to use in code
      *
      * @see [customSyntax](https://stylelint.io/user-guide/configure#customsyntax)
      */
      customSyntax?: CustomSyntax;
      /**
      * Functions that allow to hook into Stylelint's pipeline
      *
      * @experimental
      *
      * @see [processors](https://stylelint.io/user-guide/configure#processors)
      */
      processors?: ConfigProcessors;
      languageOptions?: LanguageOptions;
      /** @internal */
      _processorFunctions?: Map<string, ReturnType<Processor>['postprocess']>;
      /**
      * If true, Stylelint does not throw an error when the glob pattern matches no files.
      *
      * Should not be overridden on a per-file basis
      *
      * @see [allowEmptyInput](https://stylelint.io/user-guide/configure#allowemptyinput)
      */
      allowEmptyInput?: boolean;
      /**
      * If true, store the results of processed files so that Stylelint only operates on the changed ones.
      *
      * Should not be overridden on a per-file basis
      *
      * @see [cache](https://stylelint.io/user-guide/configure#cache)
      */
      cache?: boolean;
      /**
      * If true, automatically fix, where possible, problems reported by rules.
      *
      * Should not be overridden on a per-file basis
      *
      * @see [fix](https://stylelint.io/user-guide/configure#fix)
      */
      fix?: boolean;
      computeEditInfo?: boolean;
      /**
      * Force enable/disable the validation of the rules' options
      *
      * @default true
      *
      * @see [validate](https://stylelint.io/user-guide/options/#validate)
      */
      validate?: boolean;
      };
      • Configuration.

      type CoreRule

      type CoreRule<
      P extends Primary,
      S extends Secondary = Secondary,
      M extends Messages = Messages
      > = Rule<P, S, M>;

        type CssSyntaxError

        type CssSyntaxError = {
        file?: string;
        input: {
        column: number;
        file?: string;
        line: number;
        source: string;
        };
        /**
        * The line of the inclusive start position of the error.
        */
        line: number;
        /**
        * The column of the inclusive start position of the error.
        */
        column: number;
        /**
        * The line of the exclusive end position of the error.
        */
        endLine?: number;
        /**
        * The column of the exclusive end position of the error.
        */
        endColumn?: number;
        message: string;
        name: string;
        reason: string;
        source: string;
        };
        • A CSS syntax error.

        type EditInfo

        type EditInfo = {
        /**
        * The pair of 0-based indices in source code text to remove.
        */
        range: [number, number];
        /**
        * The text to add.
        */
        text: string;
        };

          type FixCallback

          type FixCallback = () => void | undefined | never;

            type FixObject

            type FixObject = {
            apply?: FixCallback;
            node?: PostCSS.Node;
            };

              type Formatters

              type Formatters = {
              readonly compact: Promise<Formatter>;
              /** @deprecated */
              readonly github: Promise<Formatter>;
              readonly json: Promise<Formatter>;
              readonly string: Promise<Formatter>;
              readonly tap: Promise<Formatter>;
              readonly unix: Promise<Formatter>;
              readonly verbose: Promise<Formatter>;
              };

                type LanguageOptions

                type LanguageOptions = {
                syntax?: {
                atRules?: Record<
                string,
                {
                comment?: string;
                prelude?: string;
                descriptors?: Record<string, string>;
                }
                >;
                cssWideKeywords?: string[];
                properties?: Record<string, string>;
                types?: Record<string, string>;
                };
                };

                  type LinterOptions

                  type LinterOptions = {
                  files?: OneOrMany<string>;
                  globbyOptions?: GlobbyOptions;
                  cache?: boolean;
                  cacheLocation?: string;
                  cacheStrategy?: string;
                  code?: string;
                  codeFilename?: string;
                  config?: Config;
                  configFile?: string;
                  configBasedir?: string;
                  /**
                  * The working directory to resolve files from. Defaults to the
                  * current working directory.
                  */
                  cwd?: string;
                  ignoreDisables?: boolean;
                  ignorePath?: OneOrMany<string>;
                  ignorePattern?: string[];
                  reportDescriptionlessDisables?: boolean;
                  reportNeedlessDisables?: boolean;
                  reportInvalidScopeDisables?: boolean;
                  reportUnscopedDisables?: boolean;
                  maxWarnings?: number;
                  customSyntax?: CustomSyntax;
                  /** @internal */
                  _defaultFormatter?: FormatterType;
                  formatter?: FormatterType | Formatter;
                  disableDefaultIgnores?: boolean;
                  fix?: boolean | FixMode;
                  computeEditInfo?: boolean;
                  allowEmptyInput?: boolean;
                  quiet?: boolean;
                  quietDeprecationWarnings?: boolean;
                  validate?: boolean;
                  };
                  • Linter options.

                  type LinterResult

                  type LinterResult = {
                  /**
                  * The working directory from which the linter was run when the
                  * results were generated.
                  */
                  cwd: string;
                  results: LintResult[];
                  errored: boolean;
                  /**
                  * @deprecated Use `report` for the formatted problems, or use `code`
                  * for the autofixed code instead. This will be removed in the next major version.
                  */
                  output: string;
                  /** @internal To show the deprecation warning. */
                  _output?: string;
                  /** @internal To show the deprecation warning. */
                  _outputWarned?: boolean;
                  /**
                  * A string that contains the formatted problems.
                  */
                  report: string;
                  /**
                  * A string that contains the autofixed code, if the `fix` option is set to `true`
                  * and the `code` option is provided.
                  */
                  code?: string;
                  maxWarningsExceeded?: {
                  maxWarnings: number;
                  foundWarnings: number;
                  };
                  reportedDisables: DisableOptionsReport;
                  descriptionlessDisables?: DisableOptionsReport;
                  needlessDisables?: DisableOptionsReport;
                  invalidScopeDisables?: DisableOptionsReport;
                  /**
                  * Each rule metadata by name.
                  */
                  ruleMetadata: { [ruleName: string]: Partial<RuleMeta> };
                  };
                  • A linter result.

                  type LintResult

                  type LintResult = {
                  source?: string;
                  deprecations: {
                  text: string;
                  reference?: string;
                  }[];
                  invalidOptionWarnings: {
                  text: string;
                  }[];
                  parseErrors: (PostCSS.Warning & {
                  stylelintType: Extract<StylelintWarningType, 'parseError'>;
                  })[];
                  errored?: boolean;
                  warnings: Warning[];
                  ignored?: boolean;
                  /**
                  * Internal use only. Do not use or rely on this property. It may
                  * change at any time.
                  * @internal
                  */
                  _postcssResult?: PostcssResult;
                  };
                  • A lint result.

                  type Messages

                  type Messages = {
                  [key in `expected${string}` | `rejected${string}`]: RuleMessage;
                  };

                    type OneOrMany

                    type OneOrMany<S> = S | S[];

                      type Plugin

                      type Plugin =
                      | { default?: { ruleName: string; rule: Rule } }
                      | { ruleName: string; rule: Rule };
                      • A Stylelint plugin.

                      type Position

                      type Position = {
                      line: number;
                      column: number;
                      };

                        type Primary

                        type Primary = number | true | OneOrMany<StringOrRegex> | Record<string, any>;

                          type Problem

                          type Problem = {
                          ruleName: string;
                          result: PostcssResult;
                          message: RuleMessage;
                          messageArgs?: Parameters<RuleMessageFunc> | undefined;
                          node: PostCSS.Node;
                          /**
                          * The inclusive start index of the problem, relative to the node's
                          * source text.
                          */
                          index?: number;
                          /**
                          * The exclusive end index of the problem, relative to the node's
                          * source text.
                          */
                          endIndex?: number;
                          /**
                          * The inclusive start position of the problem, relative to the
                          * node's source text. If provided, this will be used instead of
                          * `index`.
                          */
                          start?: Position;
                          /**
                          * The exclusive end position of the problem, relative to the
                          * node's source text. If provided, this will be used instead of
                          * `endIndex`.
                          */
                          end?: Position;
                          word?: string;
                          /** @deprecated */
                          line?: number;
                          /**
                          * Optional severity override for the problem.
                          */
                          severity?: RuleSeverity;
                          fix?: FixCallback | FixObject;
                          };
                          • A lint problem.

                          type Processor

                          type Processor = () => {
                          name: string;
                          postprocess: (result: LintResult, root?: PostCSS.Root) => void;
                          };
                          • WARNING: This is an experimental feature. The API may change in the future.

                          type PublicApi

                          type PublicApi = PostCSS.PluginCreator<PostcssPluginOptions> & {
                          /**
                          * Runs Stylelint with the given options and returns a Promise that
                          * resolves to the results.
                          *
                          * @param options - A lint options object
                          * @returns A lint result
                          */
                          lint: (options: LinterOptions) => Promise<LinterResult>;
                          /**
                          * Available rules.
                          */
                          rules: { readonly [name in keyof CoreRules]: Promise<CoreRules[name]> };
                          /**
                          * Result report formatters by name.
                          */
                          formatters: Formatters;
                          /**
                          * Creates a Stylelint plugin.
                          */
                          createPlugin: (ruleName: string, rule: Rule) => Plugin;
                          /**
                          * The Stylelint "internal API" is passed among functions
                          * so that methods on a Stylelint instance can invoke
                          * each other while sharing options and caches.
                          *
                          * @internal
                          */
                          _createLinter: (options: LinterOptions) => InternalApi;
                          /**
                          * Resolves the effective configuration for a given file. Resolves to
                          * `undefined` if no config is found.
                          *
                          * @param filePath - The path to the file to get the config for.
                          * @param options - The options to use when creating the Stylelint instance.
                          * @returns A resolved config or `undefined`.
                          */
                          resolveConfig: (
                          filePath: string,
                          options?: Pick<
                          LinterOptions,
                          'cwd' | 'config' | 'configBasedir' | 'configFile'
                          >
                          ) => Promise<Config | undefined>;
                          /**
                          * Utility functions.
                          */
                          utils: Utils;
                          /**
                          * Reference objects.
                          */
                          reference: {
                          longhandSubPropertiesOfShorthandProperties: LonghandSubPropertiesOfShorthandProperties;
                          };
                          };
                          • The Stylelint public API.

                          type Rule

                          type Rule<P = any, S = any, M = RuleMessages> = RuleBase<P, S> & {
                          ruleName: string;
                          messages: M;
                          primaryOptionArray?: boolean;
                          meta?: RuleMeta;
                          };
                          • A rule.

                          type RuleContext

                          type RuleContext = {
                          configurationComment?: string | undefined;
                          fix?: boolean | undefined;
                          newline?: string | undefined;
                          /** @internal */
                          lexer?: unknown | undefined;
                          };
                          • A rule context.

                          type Secondary

                          type Secondary = Record<string, any>;

                            type Severity

                            type Severity = 'warning' | 'error';
                            • Rule severity.

                            type StringOrRegex

                            type StringOrRegex = string | RegExp;

                              type StylelintWarningType

                              type StylelintWarningType = 'deprecation' | 'invalidOption' | 'parseError';

                                type Utils

                                type Utils = {
                                /**
                                * Report a problem.
                                *
                                * This function accounts for `disabledRanges` attached to the result.
                                * That is, if the reported problem is within a disabledRange,
                                * it is ignored. Otherwise, it is attached to the result as a
                                * postcss warning.
                                *
                                * It also accounts for the rule's severity.
                                *
                                * You *must* pass *either* a node or a line number.
                                *
                                * @param problem - A problem
                                */
                                report: (problem: Problem) => void;
                                /**
                                * Given an object of problem messages, return another
                                * that provides the same messages postfixed with the rule
                                * that has been violated.
                                *
                                * @param ruleName - A rule name
                                * @param messages - An object whose keys are message identifiers
                                * and values are either message strings or functions that return message strings
                                * @returns New message object, whose messages will be marked with the rule name
                                */
                                ruleMessages: <T extends RuleMessages, R extends { [K in keyof T]: T[K] }>(
                                ruleName: string,
                                messages: T
                                ) => R;
                                /**
                                * Validate a rule's options.
                                *
                                * See existing rules for examples.
                                *
                                * @param result - PostCSS result
                                * @param ruleName - A rule name
                                * @param optionDescriptions - Each optionDescription can have the following properties:
                                * - `actual` (required): the actual passed option value or object.
                                * - `possible` (required): a schema representation of what values are
                                * valid for those options. `possible` should be an object if the
                                * options are an object, with corresponding keys; if the options are not an
                                * object, `possible` isn't, either. All `possible` value representations
                                * should be **arrays of either values or functions**. Values are === checked
                                * against `actual`. Functions are fed `actual` as an argument and their
                                * return value is interpreted: truthy = valid, falsy = invalid.
                                * - `optional` (optional): If this is `true`, `actual` can be undefined.
                                * @returns Whether or not the options are valid (`true` = valid)
                                */
                                validateOptions: (
                                result: PostcssResult,
                                ruleName: string,
                                ...optionDescriptions: RuleOptions[]
                                ) => boolean;
                                /**
                                * Useful for third-party code (e.g. plugins) to run a PostCSS Root
                                * against a specific rule and do something with the warnings.
                                */
                                checkAgainstRule: <T, O extends Object>(
                                options: {
                                ruleName: string;
                                ruleSettings: ConfigRuleSettings<T, O>;
                                root: PostCSS.Root;
                                result?: PostcssResult;
                                context?: RuleContext;
                                },
                                callback: (warning: PostCSS.Warning) => void
                                ) => Promise<void>;
                                };
                                • Utility functions.

                                type Warning

                                type Warning = {
                                /**
                                * The line of the inclusive start position of the warning.
                                */
                                line: number;
                                /**
                                * The column of the inclusive start position of the warning.
                                */
                                column: number;
                                /**
                                * The line of the exclusive end position of the warning.
                                */
                                endLine?: number;
                                /**
                                * The column of the exclusive end position of the warning.
                                */
                                endColumn?: number;
                                /**
                                * The `EditInfo` object of autofix. This property is undefined if this message is not fixable.
                                */
                                fix?: EditInfo;
                                rule: string;
                                severity: Severity;
                                text: string;
                                url?: string;
                                stylelintType?: StylelintWarningType;
                                };
                                • A lint warning.

                                Package Files (1)

                                Dependencies (38)

                                Dev Dependencies (45)

                                Peer Dependencies (0)

                                No peer dependencies.

                                Badge

                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/stylelint.

                                • Markdown
                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/stylelint)
                                • HTML
                                  <a href="https://www.jsdocs.io/package/stylelint"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>