迁移到 14.0.0
¥Migrating to 14.0.0
此版本包含重大更改。我们知道这些可能会造成破坏,但它们需要使我们的依赖保持最新并且 Stylelint 不存在安全问题。
¥This release contains breaking changes. We know these can be disruptive, but they were needed to keep our dependencies up to date and Stylelint free of security issues.
用户
¥Users
有五项变化可能会影响你:
¥There are five changes that may affect you:
-
删除了
syntax
选项和自动推断语法¥the
syntax
option and automatic inferral of syntax were removed -
Node.js 10 支持已取消
¥Node.js 10 support was dropped
-
13.7.0 中弃用的规则已被删除
¥the rules deprecated in 13.7.0 were removed
-
configOverrides
选项已删除¥the
configOverrides
option was removed -
function-calc-no-invalid
规则已删除¥the
function-calc-no-invalid
rule was removed
如果你需要更新配置文件,你可能还需要删除 .stylelintcache
文件。
¥If you need to update your config file, you may need to delete your .stylelintcache
file too.
syntax
选项和语法自动推断
¥syntax
option and automatic inferral of syntax
Stylelint 不再包含以下语法:
¥Stylelint no longer includes the syntaxes that:
-
解析类似 CSS 的语言,如 SCSS、Sass、Less 和 SugarSS
¥parse CSS-like languages like SCSS, Sass, Less and SugarSS
-
从 HTML、Markdown 和 CSS-in-JS 对象和模板文本中提取样式
¥extract styles from HTML, Markdown and CSS-in-JS object & template literals
如果你使用 Stylelint 来检查 CSS 文件以外的任何内容,则需要安装和配置这些语法。我们推荐 extending 共享配置,其中包括适合你的 PostCSS 语法。例如,如果你使用 Stylelint 来检查 SCSS,则可以扩展 stylelint-config-standard-scss 共享配置。
¥If you use Stylelint to lint anything other than CSS files, you will need to install and configure these syntaxes. We recommend extending a shared config that includes the appropriate PostCSS syntax for you. For example, if you use Stylelint to lint SCSS, you can extend the stylelint-config-standard-scss shared config.
首先,将共享配置安装为依赖:
¥First, install the shared config as a dependency:
npm install --save-dev stylelint-config-standard-scss
然后,更新你的 配置对象 以使用它:
¥Then, update your configuration object to use it:
{
"extends": ["stylelint-config-standard-scss"],
"rules": {
// ..
}
}
此共享配置扩展了 Stylelint 以与 SCSS 兼容。它为 SCSS 配置 内置规则,并包括 postcss-scss 语法 和 stylelint-scss 插件(特定于 SCSS 的规则集合)。
¥This shared config extends Stylelint to be compatible with SCSS. It configures the built-in rules for SCSS, and includes the postcss-scss syntax and stylelint-scss plugin (a collection of rules specific to SCSS).
每种语言还提供其他共享配置:
¥There are other shared configs provided for each language:
-
stylelint-config-recommended-vue...Vue 的共享配置。
¥stylelint-config-recommended-vue ... Shared config for Vue.
-
stylelint-config-html...支持解析 HTML、XML、Vue、Svelte 和 PHP 的共享配置。
¥stylelint-config-html ... Shared config that enables parsing for HTML, XML, Vue, Svelte, and PHP.
如果共享配置不适用于你的首选语言或库,那么你 可以自行安装适当的 PostCSS 语法 并使用 customSyntax
选项,该配置现在在配置对象中可用。
¥If a shared config isn't available for your preferred language or library, then you can install the appropriate PostCSS syntax yourself and use the customSyntax
option, which is now available in the configuration object.
例如,检查 SugarSS。
¥For example, to lint SugarSS.
首先,安装 无糖语法 作为依赖:
¥First, install the sugarss syntax as a dependency:
npm install --save-dev sugarss
然后,更新你的配置对象以使用它:
¥Then, update your configuration object to use it:
{
"customSyntax": "sugarss",
"rules": {
// ..
}
}
对于其他语言和嵌入样式,我们建议使用以下 PostCSS 语法:
¥For other languages and embedded styles, we suggest the following PostCSS syntaxes:
-
少语言(
.less
)使用 postcss-less¥Less language (
.less
) use postcss-less -
Sass 语言(
.sass
)使用 postcss-sass¥Sass language (
.sass
) use postcss-sass -
CSS-in-JS 嵌入(
.js