Home > Software design >  Eslint - configured rules location
Eslint - configured rules location

Time:12-08

I am trying to locate where the default eslint rules are for an out of the box configured Nx workspace.

I see some plugins being used in the eslintrc file at the root of my project:

{
  "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": {}
    }
  ]
}

Can someone tell me where I should be able to see the full list of rules enabled please?

CodePudding user response:

The rules come from the npm package @nrwl/eslint-plugin-nx. This is the name of the package included in the list of plugins without "eslint-plugin-", which is prepended automatically by ESLint when resolving the plugin location.

Following the link to the 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". This .ts file imports definitions from modules in the subfolders "config" and "rules" and maps them to exports. So the sources for the locations contained in your .eslinrc file are like this:

ESLint works by merging the rule definitions in the extends sections (.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).

  • Related