问题描述
我正在使用最新版本的VS Code。
例如,这是我收到的棉绒错误:
但是,当我尝试运行npm run serve
我遇到错误,要求将其改回。
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 |
{
"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"
}
}
]
}
我的VSCode settings.json文件是
{
"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
}
我猜想项目与代码之间肯定存在不一致,但是我可以找到它。
使用npm run serve
自动修复文件,但是,如果我再次保存有问题的文件,则突然突然弹出,并出现掉毛错误(这会导致Vue应用在开发中崩溃)。
我尝试过npm cache clear --force
并更改了节点模块的权限,然后重新安装它们,但是没有运气。
我认为我需要告诉我的本地规则以覆盖更漂亮的内容,但不确定如何做到这一点
解决方法
您需要使用eslint-config-prettier
来关闭与漂亮冲突的陪同规则。确保还包括prettier/vue
规则
https://github.com/prettier/eslint-config-prettier
"extends": [
"plugin:vue/essential","airbnb-base","plugin:prettier/recommended",“prettier”,“prettier/vue”
],