简体   繁体   English

如何修复由 sass / scss 引起的 css stylelint 错误?

[英]How can i fix the css stylelint errors caused by sass / scss?

I am using Sass(scss) as the css pre-processor for my project.我使用 Sass(scss) 作为我项目的 css 预处理器。 But when i run stylelint for the .css files compiled by sass, it returns very many errors which you cant fix directly in the .css files because these files are compiled by sass.但是当我为 sass 编译的.css文件运行stylelint时,它会返回很多错误,您无法直接在.css文件中修复这些错误,因为这些文件是由 sass 编译的。 Anything you change will be lost after sass recompiles the css files. sass 重新编译 css 文件后,您更改的任何内容都将丢失。

I have used various sass linting options like sass-lint and sass-lint-auto-fix but these options, though helpful, have not fixed the problems in the .css files.我使用了各种 sass sass-lint选项,如sass-lintsass-lint-auto-fix但这些选项虽然有用,但并没有解决.css文件中的问题。

stylelint also keeps flagging the various sass @-rules like @mixin and @include as unexpected and unknown at-rules. stylelint还不断地将各种 sass @-rules(如@mixin@include标记为意外和未知的 at 规则。

Any suggestions or thoughts are welcome.欢迎任何建议或想法。 Thanks.谢谢。

But when I run stylelint for the .css files compiled by sass, it returns very many errors which you cant fix directly in the .css但是当我为 sass 编译的.css文件运行 stylelint 时,它会返回很多错误,您无法直接在.css修复这些错误

The linter supports CSS-like syntaxes like SCSS, Sass, Less and SugarSS, as well as extracting embedded styles from HTML, markdown and CSS-in-JS object & template literals. linter 支持类似 CSS 的语法,如 SCSS、Sass、Less 和 SugarSS,以及从 HTML、markdown 和 CSS-in-JS 对象和模板文字中提取嵌入样式。

You should run stylelint on your SCSS source code files, not your compiled CSS files:你应该在你的 SCSS 源代码文件上运行 stylelint,而不是你编译的 CSS 文件:

stylelint "**/*.scss"

stylelint also keeps flagging the various sass @-rules like @mixin and @include as unexpected and unknown at-rules. stylelint 还不断地将各种 sass @-rules(如 @mixin 和 @include)标记为意外和未知的 at 规则。

The rules built into stylelint are geared towards standard CSS. stylelint 中内置的规则面向标准 CSS。 The @mixin and @includes at-rules are non-standard as they are part of SCSS and not CSS, so they are flagged as unknown. @mixin@includes at 规则是非标准的,因为它们是 SCSS 的一部分而不是 CSS,因此它们被标记为未知。 However, the stylelint-scss plugin pack contains rules specific to SCSS and SCSS-like syntax.但是, stylelint-scss 插件包包含特定于 SCSS 和 SCSS 类语法的规则。 You can use it by extending thestylelint-config-recommended-scss sharable config in your .stylelintrc.json configuration file :您可以通过扩展.stylelintrc.json配置文件中stylelint-config-recommended-scss可共享配置来使用它:

{
  "extends": ["stylelint-config-recommended-scss"],
  "rules": {}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM