Reputation: 21852
Often times, when I try to run the , Fix all auto-fixable issues command on my Javascript files, the app goes into a never-ending loop of moving the tabs/spaces around, but never really getting satisfied:
My .eslintrc.js
is as follows:
const fs = require('fs');
const prettierOptions = JSON.parse(fs.readFileSync('./.prettierrc', 'utf8'));
module.exports = {
parser: 'babel-eslint',
extends: ['airbnb', 'prettier', 'prettier/react'],
plugins: ['prettier', 'redux-saga', 'react', 'jsx-a11y'],
env: {
browser: true,
node: true,
jest: true,
es6: true,
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'prettier/prettier': ['error', prettierOptions],
'arrow-body-style': [2, 'as-needed'],
'class-methods-use-this': 0,
'comma-dangle': [2, 'always-multiline'],
'import/imports-first': 0,
'import/newline-after-import': 0,
'import/no-dynamic-require': 0,
'import/no-extraneous-dependencies': 0,
'import/no-named-as-default': 0,
'import/no-unresolved': 2,
'import/no-webpack-loader-syntax': 0,
'import/prefer-default-export': 0,
indent: [
2,
2,
{
SwitchCase: 1,
},
],
"jsx-a11y/anchor-is-valid": 0,
'jsx-a11y/aria-props': 2,
'jsx-a11y/heading-has-content': 0,
'jsx-a11y/label-has-for': 2,
'jsx-a11y/mouse-events-have-key-events': 2,
'jsx-a11y/role-has-required-aria-props': 2,
'jsx-a11y/role-supports-aria-props': 2,
'max-len': 0,
'newline-per-chained-call': 0,
'no-confusing-arrow': 0,
'no-console': 1,
'no-use-before-define': 0,
'prefer-template': 2,
'react/jsx-closing-tag-location': 0,
'react/forbid-prop-types': 0,
'react/jsx-first-prop-new-line': [2, 'multiline'],
'react/jsx-filename-extension': 0,
'react/jsx-no-target-blank': 0,
'react/require-default-props': 0,
'react/require-extension': 0,
'react/self-closing-comp': 0,
'react/sort-comp': 0,
'redux-saga/no-yield-in-race': 2,
'redux-saga/yield-effects': 2,
'require-yield': 0,
},
settings: {
'import/resolver': {
webpack: {
config: './internals/webpack/webpack.prod.babel.js',
},
},
},
};
Could anyone help me with resolving this issue?
Upvotes: 18
Views: 37789
Reputation: 11
In my settings.json was rule that broke my eslint formatting
(remove it):
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
With this rule, every time after saving,
VS Code will apply eslint rules,
then applies prettier rules,
and as a result,
the formatter's code will look wrong
(like without formatting).
Upvotes: 0
Reputation: 4568
Simple fix : In VS Code open setting.json
file and put "editor.formatOnSave": true,
. This will autofix on save.
Upvotes: -2
Reputation: 3028
Try adding following configs to vscode settings.json
"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true,
// For TSLint
"source.fixAll.tslint": true,
// For Stylelint
"source.fixAll.stylelint": true
},
Upvotes: 30
Reputation: 615
UPD:
Now you can just choose vscode-eslint
/ prettier
as your default formatter and it should format file in one pass:
ctrl
+ shift
+ p
Format document with...
Configure default foramtter
OLD:
This is old issue in vscode-eslint extention due to limitation of vscode formatting API. One possible solution is to fix code via cli:
eslint --fix
Upvotes: 11
Reputation: 2167
Install extension Toggle Format on Save, And press CMD+SHIFT+P type Toggle Format on Save > Enter.
Hope to help.
Upvotes: 1