Table of contents
background
problem causes:
stylelint uses double quotes when css expects quotes
Solution:
Modify the check that double quotes must be used when importing images into css in stylelint.
Notice:
I just want to modify the check in stylelint that when using url to import images in css, double quotes must be used instead of using single quotes for all imports.
deal with
Open the
.stylelintrc
or.stylelintrc.json
configuration file.Rules related to string quoting are found in the configuration file, usually
"string-quotes"
.
url()
Modify the value of the rule to an object and add specific configuration for in the object .Example configuration file (
.stylelintrc.json
):{ "rules": { "string-quotes": { "except": ["url"] } } }
In the above configuration, we
"string-quotes"
set the value of the rule to an object and added"except": ["url"]
the configuration to it. This means that in addition tourl()
the internal quotation, double quotation marks are still required elsewhere.Add specific configuration for url() in the object:
{ "rules": { "string-quotes": [ "double", { "ignore": ["url"], "message": "请使用双引号引用其他字符串" } ] } }
In the above configuration, we
"string-quotes"
set the value of the rule to an array. The first element is the default rule setting, which requires double quotes. The second element is an object containingurl()
specific configuration for:
"ignore": ["url"]
: Indicates thaturl()
internal references are ignored."message": "请使用双引号引用其他字符串"
: Optional setting that specifies a custom error message for this rule.Through the above configuration, stylelint will allow the use of single quotes or double quotes in CSS
url()
to introduce images, while double quotes are still required in other places.Save and close configuration file
Through the above configuration, stylelint will allow the use of single quotes or double quotes in CSS
url()
to introduce images, while double quotes are still required in other places.