如何设置 stylelint 自动修复错误?

tak*_*aro 6 stylelint

stylelint *.css --fix没有按预期工作。错误报告运行良好,但文件未修复。

包.json

{
  "devDependencies": {
    "stylelint": "^11.1.1",
    "stylelint-config-recess-order": "^2.0.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

.stylelintrc.json

{
  "extends": "stylelint-config-recess-order"
}
Run Code Online (Sandbox Code Playgroud)

style.css(丑陋的顺序属性)

{
  "devDependencies": {
    "stylelint": "^11.1.1",
    "stylelint-config-recess-order": "^2.0.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

命令

{
  "extends": "stylelint-config-recess-order"
}
Run Code Online (Sandbox Code Playgroud)

输出

.test {
  height: 100%;
  margin: auto;
  width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

错误报告很好。
我希望自动修复适用于文件。

小智 10

Stylelint 的自动更正选项。它为我解决了所有问题。

To check the errors first:

npx stylelint "**/*.{css,scss}"
Run Code Online (Sandbox Code Playgroud)

To fix the issues for all files (auto-correct options)

npx stylelint "**/*.{css,scss}" --fix
Run Code Online (Sandbox Code Playgroud)

If you want to change it for a specific file.

/npx stylelint src/index.css --fix 

[your file name and path may need to be modified according to your one]
Run Code Online (Sandbox Code Playgroud)


tak*_*aro 4

解决。我删除了node_modulespackage-lock.json。之后我就跑了npm i。我不确定原因,但现在运行良好。