0%

ESLint 配置

ESLint 是什么?

ESLint 检查和修复 JavaScript 代码问题。

安装

1
npm install eslint --save-dev

初始化

1
npx eslint --init

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// .eslintrc.js
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'eslint:recommended',
'@vue/eslint-config-prettier'
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
rules: {
'no-unused-vars': 'error',
'no-console': 'warn'
}
};

规则

  • error: 错误
  • warn: 警告
  • off: 关闭

自动修复

1
npx eslint . --fix

总结

ESLint 保持代码质量。团队统一配置。