Skip to content

Linting

Michael Rudloff edited this page Sep 23, 2021 · 1 revision

Prettier

  • Install Prettier extension
  • Press CTRL + , to open VSC settings and search for Prettier
    • Set format on save: true
    • Check off Prettier: require config
  • Type into the terminal npm install -D prettier
  • Create a new file .prettierrc and put an empty object into it {}
  • In package.json, create a script called "format": prettier --write "src

ESLint

  • Install ESLint extension

  • npm install -D eslint eslint-config-prettier

  • Create a .eslintrc.json file

    Put the following code into this file
    {
        "extends": ["eslint:recommended", "prettier"],
        "parserOptions": {
          "ecmaVersion": 2021
        },
        "env": {
          "es6": true,
          "browser": true,
          "node": true,
          "commonjs": true
        },
        "settings": {}
    }
    

In scripts in package.json

"scripts": {
    "format": "prettier --write \"**/*.{js,jsx}\"",
    "lint": "eslint \"**/*.{js,jsx}\" --quiet",
    "lint:fix": "eslint \"**/*.{js,jsx}\" --fix"
  },  

Now to run format or lint your code, simply run npm run { command } - for example, npm run format, npm run lint, npm run lint:fix

Clone this wiki locally