Eslint - 配置的规则位置

Eslint - configured rules location

我正在尝试查找开箱即用配置的 Nx 工作区的默认 eslint 规则所在的位置。

我看到我项目根目录下的 eslintrc 文件中使用了一些插件:

{
  "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"],
      "rules": {}
    },
    {
      "files": ["*.js", "*.jsx"],
      "extends": ["plugin:@nrwl/nx/javascript"],
      "rules": {}
    }
  ]
}

有人可以告诉我在哪里可以看到已启用规则的完整列表吗?

规则来自 npm 包 @nrwl/eslint-plugin-nx。这是 plugins 列表中包含的包的名称,不带“eslint-plugin-”,ESLint 在解析插件位置时自动将其添加到前面。

跟随 link 到 monorepo https://github.com/nrwl/nx, and digging into the "packages" folder we discover the source of eslint-plugin-nx. Now, looking into package.json we see that the main module points to "./src/index.js", which is autogenerated by Typescript from "./src/index.ts"。此 .ts 文件从子文件夹“config”和“rules”中的模块导入定义,并将它们映射到导出。所以你的 .eslinrc 文件中包含的位置的来源是这样的:

ESLint 通过合并 extends 部分 (.js, .ts) and then applying the rules definitions (.js, .ts) of the configurations, and finally the rule @nrwl/nx/enforce-module-boundaries as defined in your .eslintrc file (Note also the overrides for .tsx) 中的规则定义来工作。