规则确定了代码检查工具寻找和报告的内容。默认情况下,所有规则都处于关闭状态,并且没有任何规则的默认值。规则遵循一致的命名约定,并且设计为彼此协同工作,您可以在“关于规则”部分中阅读更多相关信息。
内置规则适用于标准 CSS 语法,除了 indentation
规则之外,所有规则都将忽略包含非标准语法的结构,例如变量插值和混合。
除了这些规则之外,还有插件,它们是社区构建的规则,支持方法论、工具集、非标准 CSS 功能或非常具体的用例。不要忘记查看插件列表以获取更多检查方法。
以下是 stylelint 中的所有内置规则,首先按类别,然后按事物分组。
color-no-invalid-hex
:禁止使用无效的十六进制颜色。
font-family-no-duplicate-names
:禁止使用重复的字体族名称。font-family-no-missing-generic-family-keyword
:禁止在字体族名称列表中缺少通用字体族关键字。
function-calc-no-invalid
:禁止在calc
函数中使用无效表达式。function-calc-no-unspaced-operator
:禁止在calc
函数中使用没有间隔的运算符。function-linear-gradient-no-nonstandard-direction
:Disallow direction values inlinear-gradient()
calls that are not valid according to the standard syntax.
string-no-newline
:Disallow (unescaped) newlines in strings.
unit-no-unknown
:Disallow unknown units.
property-no-unknown
:Disallow unknown properties.
keyframe-declaration-no-important
:Disallow!important
within keyframe declarations.
declaration-block-no-duplicate-properties
:Disallow duplicate properties within declaration blocks.declaration-block-no-shorthand-property-overrides
:Disallow shorthand properties that override related longhand properties within declaration blocks.
block-no-empty
:Disallow empty blocks.
selector-pseudo-class-no-unknown
:Disallow unknown pseudo-class selectors.selector-pseudo-element-no-unknown
:Disallow unknown pseudo-element selectors.selector-type-no-unknown
:Disallow unknown type selectors.
media-feature-name-no-unknown
:Disallow unknown media feature names.
at-rule-no-unknown
:Disallow unknown at-rules.
comment-no-empty
:禁止空注释。
no-descending-specificity
:禁止在具有较高特异性的选择器后出现被其覆盖的较低特异性的选择器。no-duplicate-at-import-rules
:禁止在样式表中使用重复的@import
规则。no-duplicate-selectors
:禁止样式表中的重复选择器。no-empty-source
:禁止空源码。no-extra-semicolons
:禁止额外的分号(可自动修复)。no-invalid-double-slash-comments
:禁止 CSS 不支持的双斜杠注释(//...
)。
color-named
:Require (where possible) or disallow named colors.color-no-hex
:Disallow hex colors.
function-blacklist
:Specify a blacklist of disallowed functions.function-url-no-scheme-relative
:Disallow scheme-relative urls.function-url-scheme-blacklist
:Specify a blacklist of disallowed url schemes.function-url-scheme-whitelist
:Specify a whitelist of allowed url schemes.function-whitelist
:Specify a whitelist of allowed functions.
keyframes-name-pattern
:Specify a pattern for keyframe names.
number-max-precision
:Limit the number of decimal places allowed in numbers.
time-min-milliseconds
:Specify the minimum number of milliseconds for time values.
unit-blacklist
:Specify a blacklist of disallowed units.unit-whitelist
:Specify a whitelist of allowed units.
shorthand-property-no-redundant-values
:Disallow redundant values in shorthand properties (Autofixable).
value-no-vendor-prefix
:Disallow vendor prefixes for values.
custom-property-pattern
:Specify a pattern for custom properties.
property-blacklist
:Specify a blacklist of disallowed properties.property-no-vendor-prefix
:Disallow vendor prefixes for properties.property-whitelist
:Specify a whitelist of allowed properties.
declaration-block-no-redundant-longhand-properties
:Disallow longhand properties that can be combined into one shorthand property.declaration-no-important
:Disallow!important
within declarations.declaration-property-unit-blacklist
:Specify a blacklist of disallowed property and unit pairs within declarations.declaration-property-unit-whitelist
:Specify a whitelist of allowed property and unit pairs within declarations.declaration-property-value-blacklist
:Specify a blacklist of disallowed property and value pairs within declarations.declaration-property-value-whitelist
:Specify a whitelist of allowed property and value pairs within declarations.
declaration-block-single-line-max-declarations
:Limit the number of declarations within single line declaration blocks.
selector-attribute-operator-blacklist
:Specify a blacklist of disallowed attribute operators.selector-attribute-operator-whitelist
:Specify a whitelist of allowed attribute operators.selector-class-pattern
:Specify a pattern for class selectors.selector-combinator-blacklist
:Specify a blacklist of disallowed combinators.selector-combinator-whitelist
:Specify a whitelist of allowed combinators.selector-id-pattern
:Specify a pattern for ID selectors.selector-max-attribute
:Limit the number of attribute selectors in a selector.selector-max-class
:Limit the number of classes in a selector.selector-max-combinators
:Limit the number of combinators in a selector.selector-max-compound-selectors
:Limit the number of compound selectors in a selector.selector-max-empty-lines
:Limit the number of adjacent empty lines within selectors.selector-max-id
:Limit the number of ID selectors in a selector.selector-max-pseudo-class
:Limit the number of pseudo-classes in a selector.selector-max-specificity
:Limit the specificity of selectors.selector-max-type
:Limit the number of type in a selector.selector-max-universal
:Limit the number of universal selectors in a selector.selector-nested-pattern
:Specify a pattern for the selectors of rules nested within rules.selector-no-qualifying-type
:Disallow qualifying a selector by type.selector-no-vendor-prefix
:Disallow vendor prefixes for selectors.selector-pseudo-class-blacklist
:Specify a blacklist of disallowed pseudo-class selectors.selector-pseudo-class-whitelist
:Specify a whitelist of allowed pseudo-class selectors.selector-pseudo-element-blacklist
:Specify a blacklist of disallowed pseudo-element selectors.selector-pseudo-element-whitelist
:Specify a whitelist of allowed pseudo-element selectors.
media-feature-name-blacklist
:Specify a blacklist of disallowed media feature names.media-feature-name-no-vendor-prefix
:Disallow vendor prefixes for media feature names.media-feature-name-value-whitelist
:Specify a whitelist of allowed media feature name and value pairs.media-feature-name-whitelist
:Specify a whitelist of allowed media feature names.
custom-media-pattern
:Specify a pattern for custom media query names.
at-rule-blacklist
:Specify a blacklist of disallowed at-rules.at-rule-no-vendor-prefix
:Disallow vendor prefixes for at-rules.at-rule-whitelist
:Specify a whitelist of allowed at-rules.
comment-word-blacklist
:指定在注释中禁用的单词的黑名单。
max-nesting-depth
:限制允许的嵌套深度。no-unknown-animations
:禁止未知的动画。
color-hex-case
:Specify lowercase or uppercase for hex colors (Autofixable).color-hex-length
:Specify short or long notation for hex colors (Autofixable).
font-family-name-quotes
:Specify whether or not quotation marks should be used around font family names.
font-weight-notation
:Require numeric or named (where possible)font-weight
values.
function-comma-newline-after
:要求在函数的逗号之后必须有换行符或不能有空白符(可自动修复)。function-comma-newline-before
:要求在函数的逗号之前必须有换行符或不能有空白符(可自动修复)。function-comma-space-after
:Require a single space or disallow whitespace after the commas of functions (Autofixable).function-comma-space-before
:Require a single space or disallow whitespace before the commas of functions (Autofixable).function-max-empty-lines
:Limit the number of adjacent empty lines within functions (Autofixable).function-name-case
:Specify lowercase or uppercase for function names (Autofixable).function-parentheses-newline-inside
:要求在函数的括号内侧必须有换行符或不能有空白符(可自动修复)。function-parentheses-space-inside
:Require a single space or disallow whitespace on the inside of the parentheses of functions (Autofixable).function-url-quotes
:Require or disallow quotes for urls.function-whitespace-after
:Require or disallow whitespace after functions (Autofixable).
number-leading-zero
:Require or disallow a leading zero for fractional numbers less than 1 (Autofixable).number-no-trailing-zeros
:Disallow trailing zeros in numbers (Autofixable).
string-quotes
:Specify single or double quotes around strings (Autofixable).
length-zero-no-unit
:Disallow units for zero lengths (Autofixable).
unit-case
:Specify lowercase or uppercase for units (Autofixable).
value-keyword-case
:Specify lowercase or uppercase for keywords values (Autofixable).
value-list-comma-newline-after
:要求在值列表的逗号之后必须有换行符或不能有空白符(可自动修复)。value-list-comma-newline-before
:要求在值列表的逗号之前必须有换行符或不能有空白符。value-list-comma-space-after
:Require a single space or disallow whitespace after the commas of value lists (Autofixable).value-list-comma-space-before
:Require a single space or disallow whitespace before the commas of value lists (Autofixable).value-list-max-empty-lines
:Limit the number of adjacent empty lines within value lists (Autofixable).
custom-property-empty-line-before
:要求或禁止在自定义属性之前的空行(可自动修复)。
property-case
:Specify lowercase or uppercase for properties (Autofixable).
declaration-bang-space-after
:Require a single space or disallow whitespace after the bang of declarations (Autofixable).declaration-bang-space-before
:Require a single space or disallow whitespace before the bang of declarations (Autofixable).declaration-colon-newline-after
:要求在声明块的冒号之后必须有换行符或不能有空白符(可自动修复)。declaration-colon-space-after
:Require a single space or disallow whitespace after the colon of declarations (Autofixable).declaration-colon-space-before
:Require a single space or disallow whitespace before the colon of declarations (Autofixable).declaration-empty-line-before
:要求或禁止在声明之前的空行(可自动修复)。
declaration-block-semicolon-newline-after
:要求在声明块的分号之后必须有换行符或不能有空白符(可自动修复)。declaration-block-semicolon-newline-before
:要求在声明块的分号之前必须有换行符或不能有空白符。declaration-block-semicolon-space-after
:Require a single space or disallow whitespace after the semicolons of declaration blocks (Autofixable).declaration-block-semicolon-space-before
:Require a single space or disallow whitespace before the semicolons of declaration blocks (Autofixable).declaration-block-trailing-semicolon
:Require or disallow a trailing semicolon within declaration blocks (Autofixable).
block-closing-brace-empty-line-before
:要求或禁止在块的闭大括号之前空行(可自动修复)。block-closing-brace-newline-after
:要求在块的闭大括号之后必须有换行符或不能有空白符(可自动修复)。block-closing-brace-newline-before
:要求在块的闭大括号之前必须有换行符或不能有空白符(可自动修复)。block-closing-brace-space-after
:Require a single space or disallow whitespace after the closing brace of blocks.block-closing-brace-space-before
:Require a single space or disallow whitespace before the closing brace of blocks (Autofixable).block-opening-brace-newline-after
:要求在块的开大括号之后必须有换行符(可自动修复)。block-opening-brace-newline-before
:要求在块的开大括号之前必须有换行符或不能有空白符(可自动修复)。block-opening-brace-space-after
:Require a single space or disallow whitespace after the opening brace of blocks (Autofixable).block-opening-brace-space-before
:Require a single space or disallow whitespace before the opening brace of blocks (Autofixable).
selector-attribute-brackets-space-inside
:Require a single space or disallow whitespace on the inside of the brackets within attribute selectors (Autofixable).selector-attribute-operator-space-after
:Require a single space or disallow whitespace after operators within attribute selectors (Autofixable).selector-attribute-operator-space-before
:Require a single space or disallow whitespace before operators within attribute selectors (Autofixable).selector-attribute-quotes
:Require or disallow quotes for attribute values.selector-combinator-space-after
:Require a single space or disallow whitespace after the combinators of selectors (Autofixable).selector-combinator-space-before
:Require a single space or disallow whitespace before the combinators of selectors (Autofixable).selector-descendant-combinator-no-non-space
:Disallow non-space characters for descendant combinators of selectors (Autofixable).selector-pseudo-class-case
:Specify lowercase or uppercase for pseudo-class selectors (Autofixable).selector-pseudo-class-parentheses-space-inside
:Require a single space or disallow whitespace on the inside of the parentheses within pseudo-class selectors (Autofixable).selector-pseudo-element-case
:Specify lowercase or uppercase for pseudo-element selectors.selector-pseudo-element-colon-notation
:Specify single or double colon notation for applicable pseudo-elements (Autofixable).selector-type-case
:Specify lowercase or uppercase for type selector (Autofixable).
selector-list-comma-newline-after
:要求在选择器列表的逗号之后必须有换行符或不能有空白符(可自动修复)。selector-list-comma-newline-before
:要求在选择器列表的逗号之前必须有换行符或不能有空白符(可自动修复)。selector-list-comma-space-after
:Require a single space or disallow whitespace after the commas of selector lists (Autofixable).selector-list-comma-space-before
:Require a single space or disallow whitespace before the commas of selector lists (Autofixable).
rule-empty-line-before
:要求或禁止在规则之前的空行(可自动修复)。
media-feature-colon-space-after
:Require a single space or disallow whitespace after the colon in media features (Autofixable).media-feature-colon-space-before
:Require a single space or disallow whitespace before the colon in media features (Autofixable).media-feature-name-case
:Specify lowercase or uppercase for media feature names (Autofixable).media-feature-parentheses-space-inside
:Require a single space or disallow whitespace on the inside of the parentheses within media features (Autofixable).media-feature-range-operator-space-after
:Require a single space or disallow whitespace after the range operator in media features (Autofixable).media-feature-range-operator-space-before
:Require a single space or disallow whitespace before the range operator in media features (Autofixable).
media-query-list-comma-newline-after
:要求在媒体查询列表的逗号之后必须有换行符或不能有空白符(可自动修复)。media-query-list-comma-newline-before
:要求在媒体查询列表的逗号之前必须有换行符或不能有空白符。media-query-list-comma-space-after
:Require a single space or disallow whitespace after the commas of media query lists (Autofixable).media-query-list-comma-space-before
:Require a single space or disallow whitespace before the commas of media query lists (Autofixable).
at-rule-empty-line-before
:要求或禁止在 @规则之前的空行(可自动修复)。at-rule-name-case
:Specify lowercase or uppercase for at-rules names (Autofixable).at-rule-name-newline-after
:Require a newline after at-rule names.at-rule-name-space-after
:Require a single space after at-rule names (Autofixable).at-rule-semicolon-newline-after
:要求在 @规则的分号之后必须有换行符(可自动修复)。at-rule-semicolon-space-before
:Require a single space or disallow whitespace before the semicolons of at rules.
comment-empty-line-before
:要求或禁止在注释之前的空行(可自动修复)。comment-whitespace-inside
:要求或禁止注释标记内侧的空白符(可自动修复)。
indentation
:指定缩进(可自动修复)。linebreaks
:指定 unix 或 windows 换行符(可自动修复)。max-empty-lines
:限制相邻空行的数量。max-line-length
:限制行的长度。no-eol-whitespace
:禁止行尾空白符(可自动修复)。no-missing-end-of-source-newline
:禁止缺少源码结尾换行符(可自动修复)。no-empty-first-line
:禁止空第一行(可自动修复)。