nx/docs/generated/packages/eslint-plugin-nx/documents/enforce-module-boundaries.md

4.3 KiB

The @nrwl/nx/enforce-module-boundaries ESLint rule enables you to define strict rules for accessing resources between different projects in the repository. Enforcing strict boundaries helps to prevent unplanned cross-dependencies.

Usage

You can use enforce-module-boundaries rule by adding it to your ESLint rules configuration:

{
  // ... more ESLint config here
  "overrides": [
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "rules": {
        "@nrwl/nx/enforce-module-boundaries": [
          "error",
          {
            // ...rule specific configuration
          }
        ]
      }
    }
    // ... more ESLint overrides here
  ]
}

Options

Property Type Default Description
allow Array [] List of imports that should be allowed without any checks
allowCircularSelfDependency boolean false Disable check for self circular dependency when project imports from itself via alias path
banTransitiveDependencies boolean false Ban import of dependencies that were not specified in the root or project's package.json
checkNestedExternalImports boolean false Enable to enforce the check for banned external imports in the nested packages. Check Dependency constraits for more information
enforceBuildableLibDependency boolean false Enable to restrict the buildable libs from importing non-buildable libraries
depConstraints Array [] List of dependency constraints between projects

Dependency constraits

The depConstraints is an array of objects representing the constraints defined between source and target projects. A constraint must include sourceTag or allSourceTags. The constraints are applied with AND logical operation - for given source project the resulting constraints would be all that match its tags.

Property Type Description
sourceTag string Tag that source project must contain to match the constraint
allSourceTags Array List of targs the source project must contain to match the constraint
onlyDependOnLibsWithTags Array The source can depend only on projects that contain at least one of these tags
notDependOnLibsWithTags Array The source can not depend on projects that contain at least one of these tags
allowedExternalImports Array Exclusive list of external (npm) packages that are allowed to be imported
bannedExternalImports Array List of external (npm) packages that are banned from importing

Read more about the proper usage of this rule: