【问题标题】:How to disable eslint check on development mode in reactjs如何在reactjs中禁用eslint检查开发模式
【发布时间】:2021-12-17 06:44:08
【问题描述】:

我已成功配置 eslint 以在 reactjs 项目中为每个提交(预提交挂钩)运行。向终端发送 git commit 命令后运行正常。

这是我的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 ."
    ]
  },

但我不希望 eslint 在开发模式下检查规则(通过运行npm run start)。

例如,我将no-console 规则设置为error 以防止用户在其中使用console.log 提交代码,但是当我尝试在开发模式下使用console.log 在控制台中显示登录时,它通过 lint 检查抛出错误

我该如何配置它?

谢谢大家

【问题讨论】:

  • 您能否提供您的 package.json 以查看您如何运行 linting 阶段?
  • @WilliamScalabre 我已经修改了原始帖子以在其中添加package.json
  • 大家好,我还在等你的答复

标签: reactjs eslint pre-commit


【解决方案1】:

我自己从这里找到了解决方案 编辑.env:

DISABLE_ESLINT_PLUGIN=true

或者在 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"
  }
}

【讨论】:

    猜你喜欢
    • 2016-06-06
    • 2021-04-18
    • 2020-04-20
    • 1970-01-01
    • 2014-04-02
    • 2013-06-03
    • 2020-04-05
    • 2021-04-13
    • 2017-06-04
    相关资源
    最近更新 更多