Skip to content

参考

基于 Stylelint v17.13.0 编写

速查

  • 用法:stylelint [输入 glob]... [选项](glob 必须用引号)
  • 配置:-c, --config <file>;查看生效配置:--print-config <file>
  • 修复:--fix(次选项 disableFix 可对单条规则关闭修复)
  • 输出:-f, --formatter <string|json|github|compact|unix|tap|verbose>
  • 阈值:--max-warnings <n>(CI 常用 0
  • 忽略:--ignore-path <file>--ignore-pattern <p>--allow-empty-input
  • 缓存:--cache--cache-location <path>--cache-strategy <metadata|content>
  • 退出码:1 致命 · 2 有问题 · 64 用法错误 · 78 配置无效

常用 CLI 参数

参数作用
stylelint "<glob>"指定要检查的文件(glob 用引号包裹)
-c, --config <file>指定配置文件
--print-config <file>打印某文件最终生效的配置
--fix自动修复可修复的违规
-f, --formatter <name>输出格式:string/json/github/compact/unix/tap/verbose
-q, --quiet只报错误,忽略警告
--quiet-deprecation-warnings抑制弃用告警
--max-warnings <n> (--mw)超过 n 个警告则失败(CI 常用 0
--custom-syntax <path>指定自定义语法(如 postcss-scss
-i, --ignore-path <file>指定忽略文件(可重复)
--ignore-pattern <p> (--ip)追加忽略模式
--allow-empty-input (--aei)glob 无匹配时不报错
--cache缓存结果,仅查变更文件
--cache-location <path>缓存文件路径(默认 ./.stylelintcache
--cache-strategy <type>缓存策略:metadata / content
--report-needless-disables (--rd)报告多余的 disable 注释
--stdin从标准输入读取(即使为空)
-o, --output-file <path>将报告写入文件
--color / --no-color强制开/关彩色输出
-v, --version显示版本

完整列表见官方 CLI reference

配置字段速查

字段作用
extends继承共享配置(数组,后者覆盖前者)
plugins加载第三方插件规则
rules精确控制单条规则与严重级、选项
customSyntax指定 PostCSS 自定义语法
overridesfiles glob 分文件覆盖配置
defaultSeverity未声明 severity 时的默认级别
ignoreFilesglob 忽略文件
cache缓存结果只查变更文件
allowEmptyInputglob 无匹配时不报错
reportNeedlessDisables报告多余的 disable
reportInvalidScopeDisables报告禁用了不存在规则的 disable
reportDescriptionlessDisables报告缺理由的 disable

规则值与次选项

形态含义
null关闭规则
true用默认设置开启
["主选项", { 次选项 }]带选项开启

次选项:severitywarning/error,默认 error)、messageurldisableFixreportDisables、各规则特有的 ignore*

内置 formatter

formatter默认场景
stringCLI 默认
jsonNode API 默认
githubGitHub Actions
compact紧凑
unixUnix 风格
tapTAP
verbose详细统计

退出码

退出码含义
1致命错误
2发现 lint 问题
64CLI 用法错误
78配置文件无效

相关链接