question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

stylelint can't automatically format on save

See original GitHub issue

What steps are needed to reproduce the bug?

When I was using stylelint 13, it was working fine, but for some reason after I upgraded to version 14, the fix on save function didn’t work, but stylelint has correctly marked the error.

What Stylelint configuration is needed to reproduce the bug?

  // stylelint.config.cjs

  extends: [
    'stylelint-config-standard-scss',
    'stylelint-config-recommended-vue',
  ],
  customSyntax: 'postcss-html',
  overrides: [
    {
      files: ['**/*.{scss,css,sass}'],
      customSyntax: 'postcss-scss',
    },
  ],
  plugins: [
    'stylelint-scss',
    'stylelint-order',
  ],
  // package.json

  "devDependencies": {
    "@babel/core": "^7.19.6",
    "@babel/eslint-parser": "^7.19.1",
    "@types/node": "^18.11.8",
    "@vitejs/plugin-vue": "^3.2.0",
    "eslint": "^8.26.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-sort": "^2.4.0",
    "eslint-plugin-vue": "^9.7.0",
    "postcss": "^8.4.18",
    "postcss-html": "^1.5.0",
    "postcss-scss": "^4.0.5",
    "prettier": "^2.6.0",
    "prettier-plugin-tailwindcss": "^0.1.11",
    "sass": "^1.55.0",
    "stylelint": "^14.14.0",
    "stylelint-config-recommended-vue": "^1.4.0",
    "stylelint-config-standard-scss": "^6.0.0",
    "stylelint-order": "^5.0.0",
    "stylelint-scss": "^4.3.0",
    "typescript": "^4.6.4",
    "vite": "^3.2.0",
    "vite-plugin-pages": "^0.27.1",
    "vue-tsc": "^1.0.9"
  }
  // setting.json
  
  {
  "files.associations": {
    "*.vue": "vue"
  },
  "editor.formatOnSave": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.tslint": true,
    "source.fixAll.stylelint": true,
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "editor.cursorSmoothCaretAnimation": true,
  "files.eol": "\n",
  "editor.detectIndentation": false,
  "editor.tabSize": 2,
  "editor.quickSuggestions": {
    "strings": true
  },
  "css.validate": false,
  "less.validate": false,
  "scss.validate": false,
  "files.autoSaveDelay": 500,
  "prettier.singleQuote": true,
  "emmet.triggerExpansionOnTab": true,
  "editor.snippetSuggestions": "top",
  "terminal.integrated.defaultProfile.windows": "Git Bash",
  "stylelint.snippet": [
    "css",
    "less",
    "postcss",
    "scss"
  ],
  "stylelint.validate": [
    "css",
    "less",
    "postcss",
    "scss",
    "html",
    "javascript",
    "vue-html",
    "vue-postcss",
    "sass",
    "markdown",
    "vue",
  ],
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
   "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "bracketPairColorizer.depreciation-notice": false,
  "i18n-ally.localesPaths": [
    "src/locales/lang",
    "lang",
    "src/locales",
    "src/lang",
  ],
  "i18n-ally.enabledParsers": ["js", "json"],
  "i18n-ally.displayLanguage": "zh_cn",
  "html.autoClosingTags": false,
}

How did you run Stylelint?

Just save code

Which version of Stylelint are you using?

14.14.0

What did you expect to happen?

I expect it would format the code automatically

What actually happened?

It didn’t format the code automatically

Does the bug relate to non-standard syntax?

No response

Proposal to fix the bug

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
W-Acecommented, Nov 2, 2022

Oh. I made a typo, my setting is the same as yours.

OK, I get it, I’ll find out what the problem is,

Sorry and Thanks for your help.

Masafumi Koba @.***>於 2022年11月2日 週三,13:44寫道:

If VS Code only causes the issue instead of CLI, there may be a cause in the VS Code extension. It may not be related to this repository.

Also, according to the vscode-stylelint doc https://github.com/stylelint/vscode-stylelint#editorcodeactionsonsave, the following settings seem to be correct instead of your settings:

{ “editor.codeActionsOnSave”: { “source.fixAll.stylelint”: true } }

— Reply to this email directly, view it on GitHub https://github.com/stylelint/stylelint/issues/6441#issuecomment-1299606208, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALH4GQDLF7ACJDB7PFSXZW3WGH5UBANCNFSM6AAAAAART2D4X4 . You are receiving this because you were mentioned.Message ID: @.***>

1reaction
W-Acecommented, Nov 2, 2022

@ybiquitous Thanks for your help, please refer to the following answers:

Thank you very much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support autofix on autoSave · Issue #35 · stylelint/vscode ...
When creating an error in an scss or css file that can be auto fixed by vscode-stylelint (such as omitting a space in...
Read more >
Stylelint VScode doesn't work - Stack Overflow
If you're getting started with stylelint for the first time, there are two key steps to enable it in Visual Studio Code:.
Read more >
Options - Stylelint
Automatically fix, where possible, problems reported by rules. For CSS with standard syntax, Stylelint uses postcss-safe-parser to fix syntax errors. When using ...
Read more >
How to Fix ESLint & StyleLint Errors Upon Save in VS Code
Complete the following steps to make Visual Studio Code fix any lint errors when a file is saved: Open the following file path:...
Read more >
vscode-stylelint - Visual Studio Marketplace
Extension for Visual Studio Code - Official Stylelint extension for Visual ... all auto-fixable Stylelint errors will be fixed on save.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found