简体   繁体   English

覆盖 eslint 规则

[英]Overriding eslint rule

I can't seem to override the behavior of "no-use-before-define" .我似乎无法覆盖"no-use-before-define"的行为。 I don't want to be warned when a function is used before defined.在定义之前使用 function 时,我不想被警告。 I've tried disabling & re-enabling the ESLint service in VS Code but with no success.我尝试在 VS Code 中禁用和重新启用 ESLint 服务,但没有成功。

警告示例

VS Code Extensions: ESLint , Prettier VS 代码扩展: ESLint , Prettier

.eslintrc .eslintrc

{
  "env": {
    "browser": true
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "airbnb",
    "plugin:@typescript-eslint/recommended",
    "prettier",
    "prettier/@typescript-eslint",
    "prettier/react",
    "prettier/standard",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    }
  },
  "rules": {
    "no-use-before-define": ["error", { "functions": false, "classes": true }]
  }
}

.prettierrc.js .prettierrc.js

module.exports = {
  semi:  true,
  trailingComma:  'all',
  singleQuote:  true,
  printWidth:  120,
  tabWidth:  2,
  endOfLine: 'auto',
}

I was able to use your configs on a small.tsx file after installing several node modules.安装几个节点模块后,我能够在 small.tsx 文件上使用您的配置。 It seems like the solution is just: rather than似乎解决方案只是:而不是

"no-use-before-define": ["error", { "functions": false, "classes": true }]

it seems you need to use看来你需要使用

"@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": true }]

because the error is coming from @typescript-eslint .因为错误来自@typescript-eslint

If all is lost then you can specify rule for a single line using the below command.如果一切都丢失了,那么您可以使用以下命令为单行指定规则。

/*eslint-disable */

//It will disable all the warnings between comments
alert('eslint disabled');

//To enable just add the below line of code.
/*eslint-enable */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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