Eslint
ESLint 是一个用于识别和报告在 ECMAScript/JavaScript 代码中发现的模式的工具,其目标是使代码更加一致并避免错误。
安装
确保事先运行 npm init,已经有 package.json 文件。
1
| npm init -D @eslint/config@latest
|
使用托管在 npm 上的特定可共享配置
1
| npm init -D @eslint/config@latest -- --config packageName
|
在项目中添加 eslint.config.js文件
运行
1
| npx eslint your-project-dir/yourfile.js
|
配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| import js from "@eslint/js";
export default [ js.configs.recommended,
{ rules: { "no-unused-vars": "warn", "no-undef": "warn" } } ];
|
配置文档
实践问题
要关闭 ESLint 中的vue/multi-word-component-names提示
在eslint.config.js中添加
1 2 3 4 5
| { "rules": { "vue/multi-word-component-names": "off" } }
|