Skip to main content




¥Options shared by the:

你可以在 配置对象 中使用其中一些选项。

¥You can use some of these options in the configuration object.


CLI 标志:--allow-empty-input, --aei

¥CLI flag: --allow-empty-input, --aei

当 glob 模式不匹配任何文件时,Stylelint 不会抛出错误。

¥Stylelint does not throw an error when glob pattern matches no files.


CLI 标志:--config, -c

¥CLI flag: --config, -c

包含 配置对象.json、YAML 或 JS 文件的路径。

¥Path to a JSON, YAML, or JS file that contains your configuration object.

如果你不希望 Stylelint 搜索配置文件,请使用此选项。

¥Use this option if you don't want Stylelint to search for a configuration file.

该路径应该是绝对路径或相对于进程运行的目录 (process.cwd())。

¥The path should be either absolute or relative to the directory that your process is running from (process.cwd()).


CLI 标志:--config-basedir

¥CLI flag: --config-basedir

定义 "extends"、"插件" 和 "customSyntax" 的相对路径相对于的目录的绝对路径。仅当这些值是相对路径时才需要。

¥Absolute path to the directory that relative paths defining "extends", "plugins", and "customSyntax" are relative to. Only necessary if these values are relative paths.


CLI 标志:--fix

¥CLI flag: --fix


¥Automatically fix, where possible, problems reported by rules.

对于具有标准语法的 CSS,Stylelint 使用 postcss-safe-parser 来修复语法错误。

¥For CSS with standard syntax, Stylelint uses postcss-safe-parser to fix syntax errors.

使用 Node.js API 时,自动修复的代码可用作返回对象中 code 属性的值。

¥When using the Node.js API, the autofixed code is available as the value of the code property in the returned object.


¥If a source contains a:

  • 范围禁用注释,例如 /* stylelint-disable color-named */,范围规则报告的任何问题都不会在源中的任何位置自动修复

    ¥scoped disable comment, e.g. /* stylelint-disable color-named */, any problems reported by the scoped rules will not be automatically fixed anywhere in the source

  • 无范围禁用注释,即 /* stylelint-disable */,整个源代码不会被自动修复

    ¥unscoped disable comment, i.e. /* stylelint-disable */, the entirety of source will not be automatically fixed

问题#2643 中跟踪此限制。

¥This limitation in being tracked in issue #2643.


CLI 标志:--custom-syntax

¥CLI flag: --custom-syntax


¥Specify a custom syntax to use on your code.

有许多样式语言,从 CSS 语言扩展(如 SCSS)到完全不同的符号(例如 CSS-in-JS 对象。

¥There are many styling languages, ranging from CSS language extensions like SCSS to entirely different notations, e.g. CSS-in-JS objects.


¥These styling languages can be embedded within other languages too. For example:

  • HTML <style> 标签

    ¥HTML <style> tags

  • Markdown 围栏

    ¥markdown fences

  • JavaScript 模板字面量

    ¥JavaScript template literals

此选项允许 Stylelint 将它们转换为类似于 CSS 的语言,CSS 是一种以下语言:

¥This option allows Stylelint to transform these into something that resembles CSS, which is the language that:

  • 支持所有其他样式语言

    ¥underpins all the other styling languages

  • 最好通过 Stylelint 内置的规则来理解

    ¥is best understood by rules built into Stylelint

此选项应该是一个解析为导出 PostCSS 兼容语法.js 的 JS 模块的字符串。该字符串可以是模块名称(如 my-module)或 JS 文件的路径(如 path/to/my-module.js)。

¥This option should be a string that resolves to a JS module that exports a PostCSS-compatible syntax. The string can be a module name (like my-module) or a path to a JS file (like path/to/my-module.js).

如果要检查两种或多种不同语言,可以将 customSyntaxoverrides 配置属性结合起来。

¥If you want to lint two or more different languages, you can combine customSyntax with the overrides configuration property.

使用 Node.js API,customSyntax 选项也可以接受 语法对象。Stylelint 将 parse 属性视为必需值。此外,Stylelint 支持用 ESM 编写的语法模块。

¥Using the Node.js API, the customSyntax option can also accept a Syntax object. Stylelint treats the parse property as a required value. Also, Stylelint supports syntax modules written in ESM.


Stylelint 无法保证核心规则适用于自定义语法。

¥Stylelint can provide no guarantee that core rules work with custom syntaxes.


CLI 标志:--formatter, -f | --custom-formatter

¥CLI flags: --formatter, -f | --custom-formatter


¥Specify the formatter to format your results.


¥Options are:

  • compact - 生成类似于 ESLint 的紧凑格式化程序的输出

    ¥compact - generates output similar to ESLint's compact formatter

  • github - 通过 GitHub Actions 的工作流程命令 生成消息

    ¥github - generates messages via workflow commands for GitHub Actions

  • json(节点 API 的默认值) - 生成可由其他工具使用的 JSON

    ¥json (default for Node API) - generates JSON that can be consumed by another tool

  • string(CLI 默认) - 生成人类可读的字符串

    ¥string (default for CLI) - generates human-readable strings

  • tap - 生成 测试任何协议 输出

    ¥tap - generates Test Anything Protocol output

  • unix - 像 C 编译器一样生成消息,以便 Emacs 的编译模式等工具可以超链接它们

    ¥unix - generates messages like a C compiler, so that tools like Emacs' Compilation mode can hyperlink them

  • verbose - 扩展 string 以包含已检查文件的列表以及每个规则的计数

    ¥verbose - extends string to include a list of checked files and a tally for each rule

formatter Node.js API 选项还可以接受函数或 Promise 函数,而 --custom-formatter CLI 标志接受导出 JS 文件的路径(文件系统路径或依赖)。两种情况下的函数都必须符合 开发者指南 中描述的签名。

¥The formatter Node.js API option can also accept a function or a Promise function, whereas the --custom-formatter CLI flag accepts a path (either a filesystem path or a dependency) to a JS file exporting one. The function in both cases must fit the signature described in the Developer Guide.


CLI 标志:--cache

¥CLI flag: --cache

存储处理文件的结果,以便 Stylelint 只对更改的文件进行操作。默认情况下,缓存存储在 process.cwd() 中的 ./.stylelintcache 中。

¥Store the results of processed files so that Stylelint only operates on the changed ones. By default, the cache is stored in ./.stylelintcache in process.cwd().

启用此选项可以显着提高 Stylelint 的速度,因为只有更改的文件才会被检查。

¥Enabling this option can dramatically improve Stylelint's speed because only changed files are linted.

如果你运行带有 cache 的 Stylelint,然后运行不带 cache 的 Stylelint,Stylelint 会删除 .stylelintcache,因为我们必须假设第二个命令使 .stylelintcache 无效。

¥If you run Stylelint with cache and then run Stylelint without cache, Stylelint deletes the .stylelintcache because we have to assume that the second command invalidated .stylelintcache.


CLI 标志:--cache-location

¥CLI flag: --cache-location


¥Path to a file or directory for the cache location.

如果指定了目录,Stylelint 会在指定文件夹内创建一个缓存文件。文件名基于 process.cwd() 的哈希值(例如 .cache_hashOfCWD),以便 Stylelint 可以为不同项目的各种缓存重用单个位置。

¥If a directory is specified, Stylelint creates a cache file inside the specified folder. The name of the file is based on the hash of process.cwd() (e.g. .cache_hashOfCWD) so that Stylelint can reuse a single location for a variety of caches from different projects.

如果 cacheLocation 的目录不存在,请确保在 *nix 系统上添加尾随 / 或在 Windows 上添加尾随 \。否则,Stylelint 假定路径是一个文件。

¥*If the directory of cacheLocation does not exist, make sure you add a trailing / on nix systems or \ on Windows. Otherwise, Stylelint assumes the path to be a file.


CLI 标志:--cache-strategy

¥CLI flag: --cache-strategy

用于检测已更改文件的缓存策略。可以是 "metadata" 或 "content"。

¥Strategy for the cache to use for detecting changed files. Can be either "metadata" or "content".

当文件的修改时间发生变化(即使其内容没有变化)时,"content" 策略会很有用。例如,这可能发生在像 "克隆" 这样的 git 操作期间,因为 git 不跟踪文件修改时间。

¥The "content" strategy can be useful in cases where the modification time of your files changes even if their contents have not. For example, this can happen during git operations like "git clone" because git does not track file modification time.


CLI 标志:--max-warnings, --mw

¥CLI flags: --max-warnings, --mw


¥Set a limit to the number of warnings accepted.

当将 defaultSeverity 设置为 "warning" 并期望进程因警告而失败(例如 CI 构建)时,它非常有用。

¥It is useful when setting defaultSeverity to "warning" and expecting the process to fail on warnings (e.g. CI build).


¥If the number of warnings exceeds this value, the:

  • CLI 进程退出并显示代码 2

    ¥CLI process exits with code 2

  • Node.js API 在返回的数据中添加 maxWarningsExceeded 属性

    ¥Node.js API adds a maxWarningsExceeded property to the returned data


CLI 标志:--disable-default-ignores, --di

¥CLI flags: --disable-default-ignores, --di

禁用默认忽略。Stylelint 不会自动忽略 node_modules 的内容。

¥Disable the default ignores. Stylelint will not automatically ignore the contents of node_modules.


CLI 标志:--globby-options, --go

¥CLI flags: --globby-options, --go

选项传递给 globby更多信息

¥Options passed to globby. More info.


CLI 标志:--ignore-path, -i

¥CLI flags: --ignore-path, -i

包含描述要忽略的文件的模式的文件的路径。该路径可以是绝对路径,也可以是相对于 process.cwd() 的路径。你可以重复该选项以提供多个路径。默认情况下,Stylelint 在 process.cwd() 中查找 .stylelintignore

¥Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). You can repeat the option to provide multiple paths. By default, Stylelint looks for .stylelintignore in process.cwd().


CLI 标志:--ignore-disables, --id

¥CLI flags: --ignore-disables, --id

忽略 stylelint-disable(例如 /* stylelint-disable block-no-empty */)注释。

¥Ignore stylelint-disable (e.g. /* stylelint-disable block-no-empty */) comments.

你可以使用此选项来查看如果没有这些异常,你的 linting 结果会是什么样子。

¥You can use this option to see what your linting results would be like without those exceptions.


CLI 标志:--report-descriptionless-disables, --rdd

¥CLI flags: --report-descriptionless-disables, --rdd

报告 stylelint-disable 条注释,但不加说明。

¥Report stylelint-disable comments without a description.


¥The following patterns are reported:

/* stylelint-disable */
a {}
/* stylelint-disable-next-line block-no-empty */
a {}

但是,不会报告以下模式 (stylelint-disable -- <description>):

¥But, the following patterns (stylelint-disable -- <description>) are not reported:

/* stylelint-disable -- This problem is ignorable. */
a {}
/* stylelint-disable-next-line block-no-empty -- This problem is ignorable. */
a {}


CLI 标志:--report-invalid-scope-disables, --risd

¥CLI flags: --report-invalid-scope-disables, --risd

报告与配置对象中指定的规则不匹配的 stylelint-disable 注释。

¥Report stylelint-disable comments that don't match rules that are specified in the configuration object.


CLI 标志:--report-needless-disables, --rd

¥CLI flags: --report-needless-disables, --rd

报告 stylelint-disable 条注释,这些注释实际上与任何需要禁用的 lint 不匹配。

¥Report stylelint-disable comments that don't actually match any lints that need to be disabled.


CLI 标志:--stdin-filename

¥CLI flag: --stdin-filename


¥A filename to assign the input.

如果使用 codestdin 直接传递源字符串,则可以使用 codeFilename 将该代码与特定文件名关联起来。

¥If using code or stdin to pass a source string directly, you can use codeFilename to associate that code with a particular filename.


CLI 标志:--quiet

¥CLI flag: --quiet

仅注册严重性为 "error" 级的规则的问题(忽略 "warning" 级)。

¥Only register problems for rules with an "error"-level severity (ignore "warning"-level).


CLI 标志:--quiet-deprecation-warnings

¥CLI flag: --quiet-deprecation-warnings


¥Ignore deprecation warnings.