你们好,我是金金金。
![](https://file.jishuzhan.net/article/1755051587799093249/786f963e2c54aa9783f261ed747624e8.webp)
场景
每个人写的代码都有自己所属的风格,所以项目中统一代码风格特别重要,新开的项目中如何快速配置
ESLint
呢?
安装
- npm install --save-dev eslint ----安装eslint
- npm install --save-dev eslint-plugin-vue ------检测.vue文件里的js
- npm install --save-dev @typescript-eslint/eslint-plugin ------ ts
- npm install --save-dev @typescript-eslint/parser ------ ts
初始化配置
npx eslint --init
![](https://file.jishuzhan.net/article/1755051587799093249/b8748b8d657e84a1f85b51e73369d3a6.webp)
- 随后会出现一些配置项让你选择,根据项目需求对应选择就好,完成后会在当前项目的根目录下自动生成
.eslintrc.js
文件,随后你在里面配置对应的规则即可
以下是我配置的一些简单规则
![](https://file.jishuzhan.net/article/1755051587799093249/f72cc43321a1f01a93af7b2dccffcc38.webp)
vscode怎么开启eslint检测?
- 下载ESLint插件
![](https://file.jishuzhan.net/article/1755051587799093249/eb6aa06c131e4ded4571dac16cc384dc.webp)
这里有个大坑,我刚开始安装的最新版本的,配置好了 始终没效果,检查了许久,在群里面问了大佬才知道新版本有这个坑,退回上一个版本就好了,我安装的是2.4.2版本的
![](https://file.jishuzhan.net/article/1755051587799093249/6b74b3c67f8632aadf73cfc7c1f52cfc.webp)
- 测试如下,就是成功了。配置生效
![](https://file.jishuzhan.net/article/1755051587799093249/6be469b0c02091d163ddc0f887241f3e.webp)
- 这里再推荐一个插件,显示错误信息在当前代码后,更直观
![](https://file.jishuzhan.net/article/1755051587799093249/3e48997fe442a19671045926fc6796b9.webp)
WebStorm怎么开启ESLint检测?
![](https://file.jishuzhan.net/article/1755051587799093249/beaac19033645b78d87842ebf34a5afd.webp)
![](https://file.jishuzhan.net/article/1755051587799093249/9e372af24ee0cfa84725d73cfd7a657a.webp)
HBuilde怎么开启ESLint检测?
- 插件安装,eslint-js、eslint-plugin-vue、stylelint、htmlhint
![](https://file.jishuzhan.net/article/1755051587799093249/4f271921c63285dc62520b94379e93e9.webp)
![](https://file.jishuzhan.net/article/1755051587799093249/25f6d92e530c3fdb61a6d8afd0f7fcf6.webp)
![](https://file.jishuzhan.net/article/1755051587799093249/f4b4cf4fef56e46d573c4c3b8fb6cfbe.webp)
- 配置
![](https://file.jishuzhan.net/article/1755051587799093249/078f94f6f2af1a4cd6d179ed9eabc2a5.webp)
![](https://file.jishuzhan.net/article/1755051587799093249/c23b5b44a7d966cef93644cc77a924c0.webp)
- 测试
![](https://file.jishuzhan.net/article/1755051587799093249/065b3ad6f7a055c6bdbe10610b9c0521.webp)
- 编写有误还请大佬指正,万分感谢。