简体   繁体   中英

How to disable eslint check on development mode in reactjs

I have configured eslint successfully to run for every commit (pre-commit hook) in reactjs project. It runs properly after sending git commit command to terminal.

here's my package.json

  "scripts": {
    ......
    "lint": "eslint src --ext .tsx .",
    "lint:fix": "eslint src --ext .tsx --fix",
    "precommit": "lint-staged",
    "prepare": "husky install",
    "format": "prettier --write \"src/**/*.tsx\"",
    ......
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.(ts|tsx)": [
      "prettier --write .",
      "eslint src --ext .tsx --fix .",
      "git add ."
    ]
  },

But I don't want eslint to check for rules when in development mode (by running npm run start ).

For example, I set no-console rule to error to prevent user to commit the code using console.log in it, but when I try to use console.log in development mode to show the log in console, it throw an error by lint check

How can I config it?

Thanks all

I myself found the solution from here Edit .env:

DISABLE_ESLINT_PLUGIN=true

Or in package.json:

{
  "scripts": {
    "start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
    "build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",
    "test": "DISABLE_ESLINT_PLUGIN=true react-scripts test"
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM