10

stylelint *.css --fix not working as expect. Error reporting works well but a file is not fixed.

package.json

{
  "devDependencies": {
    "stylelint": "^11.1.1",
    "stylelint-config-recess-order": "^2.0.3"
  }
}

.stylelintrc.json

{
  "extends": "stylelint-config-recess-order"
}

style.css (ugly-order properties)

.test {
  height: 100%;
  margin: auto;
  width: 100%;
}

command

$ npx stylelint style.css --fix

output

style.css
 4:3  ✖  Expected "width" to come before "margin"   order/properties-order

Error reporting is fine.
I expect auto-fixing works for a file.

takanopontaro
  • 217
  • 1
  • 2
  • 12

5 Answers5

8

auto-correct options for Stylelint. It fixes all issues for me.

To check the errors first:

npx stylelint "**/*.{css,scss}"

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

npx stylelint "**/*.{css,scss}" --fix

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]
Mahbub Alam
  • 251
  • 3
  • 2
4

Resolved. I removed node_modules and package-lock.json. After that I ran npm i. I'm not sure about the cause but works well now.

takanopontaro
  • 217
  • 1
  • 2
  • 12
2

Try npx stylelint --fix style.css (note the --fix is before the CSS files path).

edouardbriere
  • 1,170
  • 8
  • 12
1

I noticed that this was happening for untracked files. In my case they were .scss files. What I did was,

  1. Added an exception of the file to .stylelintignore
  2. Commited the file to the repo
  3. Removed the exception of the file from .stylelintignore
  4. Had the errors reported to my terminal and run npx stylelint src/scss/_file.scss --fix
  5. All the fixable errors were fixed
apsuhos
  • 13
  • 3
0

In my case, I used old version of prettier. Upgrading it to latest fixed my problem

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 16 '23 at 06:21