I have a Vue project, which is having some inconsistencies with its linting.
I'm using the latest version of VS Code.
For instance, this is a linting error I receive:
After saving the file, VS Code auto fixes so that the code looks is linted like this
However, when I try to run npm run serve
I get an error, asking to change it back.
error: Replace `(h)·=>·h(App),` with `h·=>·h(App)` (prettier/prettier) at src/main.js:91:11:
89 | router,
90 | store,
> 91 | render: (h) => h(App),
| ^
92 | }).$mount("#app");
93 |
my.eslintrc.json file is
{
"env": {
"browser": true,
"es6": true,
"jest/globals": true
},
"extends": [
"plugin:vue/essential",
"airbnb-base",
"plugin:prettier/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"parser": "babel-eslint"
// "ecmaVersion": 2018,
// "sourceType": "module"
},
"plugins": [
"vue",
"jest"
],
"rules": {},
"overrides": [
{
"files": [
"*.js",
"*.vue"
],
"rules": {
"sort-imports": "off",
"spaced-comment": "off",
"import/prefer-default-export": "off",
"import/no-unresolved": "off",
"import/extensions": "off",
"func-names": "off",
"object-shorthand": "off",
"eqeqeq": "warn",
"prefer-const": "off",
"camelcase": "off",
"no-plusplus": "off",
"no-else-return": "off",
"consistent-return": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
"prefer-destructuring": "off",
"no-return-assign": "off",
"guard-for-in": "off",
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
]
}
and my VSCode settings.json file is
{
"eslint.codeAction.showDocumentation": {
"enable": true
},
"explorer.confirmDelete": false,
"remote.extensionKind": {
"pub.name": ["ui"]
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "vue", "html"],
"editor.formatOnPaste": true,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.alwaysShowStatus": true,
"eslint.run": "onSave",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"vetur.format.defaultFormatter.html": "prettier",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"vetur.format.defaultFormatter.stylus": "none",
"editor.formatOnType": true,
"workbench.colorTheme": "Community Material Theme Darker",
"window.zoomLevel": 1
}
I'm guessing there must be a project vs vs code inconsistency, but I can find it.
Using npm run serve
auto fixes the file, however, if I save the offending file again, suddenly it pops up with linting errors all over again (which then cause the Vue app to crash in dev).
I've tried npm cache clear --force
and changing permissions on node modules, and reinstalling them, but no luck.
I think I need to tell my local rules to override prettier, but am unsure how to do so
You need to use eslint-config-prettier
to turn off eslint rules that conflict with prettier. Make sure to also include the prettier/vue
rules
https://github.com/prettier/eslint-config-prettier
"extends": [
"plugin:vue/essential",
"airbnb-base",
"plugin:prettier/recommended",
“prettier”,
“prettier/vue”
],
You can make eslint accept all the prettier formattings by installing eslint configuration for prettier
npm install eslint-config-prettier
And include it in the extends
option in the file .eslintrc.js
extends: [
...,
"prettier",
],
Now it won't complain on the prettier format preferences
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.