Skip to main content

忽略代码

¥Ignoring code

你可以忽略:

¥You can ignore:

  • 文件的一部分

    ¥parts of a file

  • 完全归档

    ¥files entirely

文件的各个部分

¥Parts of a file

你可以使用 CSS 中的配置注释暂时关闭规则。

¥You can temporarily turn off rules using configuration comments in your CSS.

例如,你可以关闭所有规则:

¥For example, you can either turn all the rules off:

/* stylelint-disable */
a {}
/* stylelint-enable */

或者你可以关闭个别规则:

¥Or you can turn off individual rules:

/* stylelint-disable selector-max-id, declaration-no-important */
#id {
color: pink !important;
}
/* stylelint-enable selector-max-id, declaration-no-important */

你可以使用 /* stylelint-disable-line */ 注释关闭各个行的规则,之后你不需要显式地重新启用它们:

¥You can turn off rules for individual lines with a /* stylelint-disable-line */ comment, after which you do not need to explicitly re-enable them:

#id { /* stylelint-disable-line */
color: pink !important; /* stylelint-disable-line declaration-no-important */
}

你还可以仅使用 /* stylelint-disable-next-line */ 注释关闭下一行的规则,之后无需显式重新启用它们:

¥You can also turn off rules for the next line only with a /* stylelint-disable-next-line */ comment, after which you do not need to explicitly re-enable them:

#id {
/* stylelint-disable-next-line declaration-no-important */
color: pink !important;
}

Stylelint 支持复杂、重叠的禁用和启用模式:

¥Stylelint supports complex, overlapping disabling & enabling patterns:

/* stylelint-disable */
/* stylelint-enable foo */
/* stylelint-disable foo */
/* stylelint-enable */
/* stylelint-disable foo, bar */
/* stylelint-disable baz */
/* stylelint-enable baz, bar */
/* stylelint-enable foo */

[!WARNING] 非标准语法注释中的配置命令(例如 // stylelint-disable)仅受最低限度的支持。它们仅在选择器或值列表之外找到时才有效。

¥[!WARNING] Configuration commands in non-standard syntax comments (e.g. // stylelint-disable) are only minimally supported.\ They will only work when found outside of selectors or value lists.

你还可以在注释末尾的两个连字符之后添加描述:

¥You may also include a description at the end of the comment, after two hyphens:

/* stylelint-disable -- Reason for disabling Stylelint. */
/* stylelint-disable foo -- Reason for disabling the foo rule. */
/* stylelint-disable foo, bar -- Reason for disabling the foo and bar rules. */

[!WARNING] 连字符两侧都必须有空格。

¥[!WARNING] There must be a space on both sides of the hyphens.

完全归档

¥Files entirely

你可以使用 .stylelintignore 文件来忽略特定文件。例如:

¥You can use a .stylelintignore file to ignore specific files. For example:

vendor/**/*.css

.stylelintignore 文件中的模式必须与 .gitignore 语法 匹配。(node-ignore 在幕后解析你的模式。).stylelintignore 中的模式总是相对于 process.cwd() 进行分析。

¥The patterns in your .stylelintignore file must match .gitignore syntax. (Behind the scenes, node-ignore parses your patterns.) Your patterns in .stylelintignore are always analyzed relative to process.cwd().

Stylelint 在 process.cwd() 中查找 .stylelintignore 文件。你还可以使用 --ignore-path(在 CLI 中)和 ignorePath(在 JS 中)选项指定忽略模式文件的路径(绝对路径或相对于 process.cwd())。

¥Stylelint looks for a .stylelintignore file in process.cwd(). You can also specify a path to your ignore patterns file (absolute or relative to process.cwd()) using the --ignore-path (in the CLI) and ignorePath (in JS) options.

或者,你可以在配置对象中添加 ignoreFiles 属性

¥Alternatively, you can add an ignoreFiles property within your configuration object.