安装

    1. $ npm install eslint --save-dev

    初始化和问题回答

    1. $ npx eslint --init
    2. How would you like to use ESLint? > To check syntax, find problems, and enforce code style
    3. What type of modules does your project use? > JavaScript modules (import/export)
    4. Which framework does your project use? > None of these
    5. Does your project use TypeScript? > NO
    6. Where does your code run? > Browser, Node
    7. How would you like to define a style for your project > Use a popular style guide
    8. Which style guide do you want to follow? > Airbnb: github.com/airbnb/java
    9. What format do you want your config file to be in? > JavaScript
    10. Would you like to install them now with npm? > Yes

    安装规则,比如airbnb

    1. npm install eslint-plugin-import eslint-config-airbnb-base@latest --save-dev

    生成.eslint.js,根据需要修改:

    1. module.exports = {
    2. env: {
    3. browser: true,
    4. es2021: true,
    5. node: true,
    6. jest: true,
    7. },
    8. extends: [
    9. 'airbnb-base',
    10. ],
    11. parserOptions: {
    12. ecmaVersion: 'latest',
    13. sourceType: 'module',
    14. },
    15. rules: {
    16. 'import/prefer-default-export': 0,
    17. semi: 0,
    18. },
    19. }

    增加lint脚本

    1. "lint": "eslint --fix"