安装
$ npm install eslint --save-dev
初始化和问题回答
$ npx eslint --init
How would you like to use ESLint? > To check syntax, find problems, and enforce code style
What type of modules does your project use? > JavaScript modules (import/export)
Which framework does your project use? > None of these
Does your project use TypeScript? > NO
Where does your code run? > Browser, Node
How would you like to define a style for your project > Use a popular style guide
Which style guide do you want to follow? > Airbnb: github.com/airbnb/java…
What format do you want your config file to be in? > JavaScript
Would you like to install them now with npm? > Yes
安装规则,比如airbnb
npm install eslint-plugin-import eslint-config-airbnb-base@latest --save-dev
生成.eslint.js,根据需要修改:
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
jest: true,
},
extends: [
'airbnb-base',
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'import/prefer-default-export': 0,
semi: 0,
},
}
增加lint脚本
"lint": "eslint --fix"