简体   繁体   English

在 Vue 项目中使用 VScode 正确设置 Eslint Airbnb

[英]Correctly setup Eslint Airbnb with VScode in Vue project

This is my Vuejs code without linting.这是我的 Vuejs 代码,没有 linting。

在此处输入图片说明

After I run我跑后

npm run lint --fix npm 运行 lint --fix

Code is like this代码是这样的

在此处输入图片说明

But again I do some change and press Control + C. It's get formatted to the old code and gives me back same linting errors.但是我再次做了一些更改并按 Control + C。它被格式化为旧代码并返回相同的 linting 错误。

I think my code is auto formatted when I hit the Control + C.我认为当我点击 Control + C 时我的代码是自动格式化的。

This is my Vue projects eslint.rc file这是我的 Vue 项目 eslint.rc 文件

 module.exports = { root: true, env: { node: true, }, extends: [ 'plugin:vue/essential', '@vue/airbnb', ], rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', }, parserOptions: { parser: 'babel-eslint', }, };

I didn't installed pretier plugin on VScode.我没有在 VScode 上安装 pretier 插件。 But I installed Vueter plugin and Eslint pluggin.但是我安装了 Vueter 插件和 Eslint 插件。

My goal is to format my Vuejs code with Eslint Airbnb rules.我的目标是使用 Eslint Airbnb 规则格式化我的 Vuejs 代码。 When I save the code.当我保存代码时。 Right now it mess the code.现在它弄乱了代码。 How do I fix this?我该如何解决?

For me adding对我来说添加

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
}

to my VS Code settings ( Preferences: Open Settings (JSON) ) helped.对我的 VS Code 设置( Preferences: Open Settings (JSON) )有帮助。 Also: don't forget to reload/restart VS Code.另外:不要忘记重新加载/重新启动 VS Code。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM