[英]Vue 2 - ESLint + Standard + Prettier
How do I create a Vue 2 project that uses ESLint + StandardJS + Prettier?如何创建一个使用 ESLint + StandardJS + Prettier 的 Vue 2 项目?
StandardJS's rules should naturally take precedence over Prettier's. StandardJS 的规则自然应该优先于 Prettier 的规则。
vue create only provides the following options: vue create 只提供以下选项:
I tried 2 things:我尝试了两件事:
I'm of course looking to set this up at the project config level and not at the IDE level.我当然希望在项目配置级别而不是在 IDE 级别进行设置。
Can you try this repo I've just created?你能试试我刚刚创建的这个 repo 吗? Looks like it's working great from what I've tested.
从我的测试来看,它看起来效果很好。
https://github.com/kissu/so-eslint-standard-prettier-config https://github.com/kissu/so-eslint-standard-prettier-config
standard
one into the Prettier
one, the changes can be seen in this commitstandard
一个的配置转储到Prettier
一个中,更改可以在此提交中看到@vue/eslint-config-standard
is throwing an error ( Environment key "es2021" is unknown
) because it requires ESlint 7 to work, as shown in this changelog @vue/eslint-config-standard
抛出错误( Environment key "es2021" is unknown
)因为它需要 ESlint 7 才能工作,如本变更日志所示7.29.0
, fixed the issue7.29.0
,修复了问题npx eslint --version
npx eslint --version
I've tried to remove @vue/prettier
from我试图从
@vue/prettier
删除
extends: ['plugin:vue/essential', 'eslint:recommended', '@vue/standard', '@vue/prettier']
and see if it's successfully removes any ;
并查看它是否成功删除了任何内容
;
and it does!确实如此!
The errors are indeed coming from ESlint (if we do remove @vue/prettier
), and they're fixed by ESlint only upon save (after an ESlint server + VScode restart)!错误确实来自 ESlint(如果我们确实删除了
@vue/prettier
prettier ),并且它们仅在保存时由 ESlint 修复(在 ESlint 服务器 + VScode 重新启动后)!
Putting Prettier
back works fine of course.把
Prettier
放回去当然很好。
Luckly, I had a new PC, hence had the opportunity to try a whole fresh config with VScode.幸运的是,我有一台新 PC,因此有机会使用 VScode 尝试全新的配置。 I had to install ESlint only and have those settings into my
settings.json
我只需要安装ESlint并将这些设置放入我的
settings.json
{
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.fixAll": true,
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
}
}
The formatting works perfectly and nothing more is required.格式化工作完美,不需要更多。
I have eslint 7.8.1 with Vue Prettier on and i don't have any problem, maybe the version of eslint that you have is not compatible with Prettier or maybe your eslint have some errors?我有 eslint 7.8.1 和 Vue Prettier,我没有任何问题,也许你的 eslint 版本与 Prettier 不兼容,或者你的 eslint 有一些错误?
In each way i will put my eslint configuration and maybe it will help you!在每种方式中,我都会放置我的 eslint 配置,也许它会帮助你!
module.exports = {
env: {
'browser': true,
'es6': true,
'node': true
},
parserOptions: {
'parser': 'babel-eslint'
},
extends: [
'@vue/standard',
'plugin:vue/recommended'
],
rules: {
"vue/html-indent": ["error", 4, {
"attribute": 1,
"closeBracket": 0,
"switchCase": 0,
"ignores": []
}],
"vue/max-attributes-per-line": [2, {
"singleline": 10,
"multiline": {
"max": 1,
"allowFirstLine": false
}
}],
'indent': ['error', 4],
'vue/component-name-in-template-casing': ['error', 'kebab-case'],
'vue/script-indent': [
'error',
4,
{ 'baseIndent': 1 }
],
'space-before-function-paren': ['error', 'never'],
'semi': [2, "never"],
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off'
},
overrides: [
{
'files': ['*.vue'],
'rules': {
'indent': 'off'
}
}
]
}
Also maybe you have forgot some of the devDependecies on package.json, those are mine也可能你忘记了 package.json 上的一些 devDependencies,那些是我的
"eslint": "^7.8.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2"
Hope that those will help you !希望那些会帮助你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.