Solve stylelint error: Expected double quotes

Table of contents

background

deal with


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

  1. Open the .stylelintrcor .stylelintrc.jsonconfiguration file.

  2. Rules related to string quoting are found in the configuration file, usually "string-quotes".

  3. 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 to url()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 containing url()specific configuration for:

  • "ignore": ["url"]: Indicates that  url() 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.

Guess you like

Origin blog.csdn.net/qq_62799214/article/details/132837488