如何将tyescript-eslint规则添加到eslint [英] How to add typescript-eslint rules to eslint

查看:26
本文介绍了如何将tyescript-eslint规则添加到eslint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NX构建ANGLE应用程序,并已将其配置为使用ESLint。我们能够配置像no-console这样的内置规则,但@typescript-eslint/no-inferrable-types不接受我们的覆盖。我们甚至尝试将规则移动到overrides部分的变量条目中,但都不起作用。

在哪里指定typescript-eslint规则?

我们的根级别.eslintrc.json

{
  "root": true,
  "ignorePatterns": ["**/*"],
  "plugins": ["@nrwl/nx"],
  "overrides": [
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "rules": {
        "@nrwl/nx/enforce-module-boundaries": [
          "error",
          {
            "enforceBuildableLibDependency": true,
            "allow": [],
            "depConstraints": [
              { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
            ]
          }
        ]
      }
    },
    {
      "files": ["*.ts", "*.tsx"],
      "extends": ["plugin:@nrwl/nx/typescript"],
      "parserOptions": { "project": "./tsconfig.*?.json" },
      "rules": {}
    },
    {
      "files": ["*.js", "*.jsx"],
      "extends": ["plugin:@nrwl/nx/javascript"],
      "rules": {}
    }
  ],
  "rules": {
    "no-console":"warn",
    "@typescript-eslint/no-inferrable-types": "off"
  }
}

推荐答案

根据我对NX LINTING工作原理的理解,我认为您可以将该规则添加到覆盖部分。

在下面的JSON中,您可以看到no-console已添加到具有与*.ts和*.tsx匹配的文件的覆盖数组元素的&Quot;Rules&Quot;。

{
  "root": true,
  "ignorePatterns": ["**/*"],
  "plugins": ["@nrwl/nx"],
  "overrides": [
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "rules": {
        "@nrwl/nx/enforce-module-boundaries": [
          "error",
          {
            "enforceBuildableLibDependency": true,
            "allow": [],
            "depConstraints": [
              { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
            ]
          }
        ]
      }
    },
    {
      "files": ["*.ts", "*.tsx"],
      "extends": ["plugin:@nrwl/nx/typescript"],
      "parserOptions": { "project": "./tsconfig.*?.json" },
      "rules": {
        "no-console":"warn"
      }
    },
    {
      "files": ["*.js", "*.jsx"],
      "extends": ["plugin:@nrwl/nx/javascript"],
      "rules": {}
    }
  ],
  "rules": {
    "@typescript-eslint/no-inferrable-types": "off"
  }
}

重要的是将规则放入哪个覆盖数组元素。我遇到了类似的问题,您可以在https://stackoverflow.com/a/71230627/990642上的答案中看到我尝试的不同方法的完整说明。

值得注意的是,似乎人们的运气好坏参半,而不是已经在pluginsextends中指定的规则。

这篇关于如何将tyescript-eslint规则添加到eslint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆