or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configurations.mddependency-checks.mdindex.mdmodule-boundaries.mdplugin-validation.mdworkspace-rules.md
tile.json

tessl/npm-nx--eslint-plugin

ESLint plugin for Nx monorepos with boundary enforcement and dependency management rules.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nx/eslint-plugin@21.4.x

To install, run

npx @tessl/cli install tessl/npm-nx--eslint-plugin@21.4.0

index.mddocs/

@nx/eslint-plugin

The @nx/eslint-plugin is a comprehensive ESLint plugin designed specifically for Nx monorepo development. It provides essential rules for enforcing module boundaries, managing dependencies, and validating plugin configurations, along with pre-configured ESLint settings for TypeScript, JavaScript, React, and Angular projects.

Package Information

  • Package Name: @nx/eslint-plugin
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @nx/eslint-plugin

Core Imports

import plugin from "@nx/eslint-plugin";
// Access configs: plugin.configs
// Access rules: plugin.rules

For specialized imports:

// Import specific framework configs
import angularPlugin from "@nx/eslint-plugin/angular";
import reactPlugin from "@nx/eslint-plugin/react";
import typescriptPlugin from "@nx/eslint-plugin/typescript";

// Import rules only
import nxPlugin from "@nx/eslint-plugin/nx";

CommonJS:

const plugin = require("@nx/eslint-plugin");
const { configs, rules } = plugin;

Basic Usage

// ESLint flat config setup
import nxPlugin from "@nx/eslint-plugin";

export default [
  ...nxPlugin.configs["flat/typescript"],
  {
    rules: {
      "@nx/enforce-module-boundaries": [
        "error",
        {
          depConstraints: [
            {
              sourceTag: "scope:shared",
              onlyDependOnLibsWithTags: ["scope:shared"]
            }
          ]
        }
      ]
    }
  }
];

Architecture

The plugin is organized around several key components:

  • Core Rules: Three main ESLint rules that enforce Nx workspace integrity
  • Configuration Presets: Pre-built ESLint configurations for different frameworks and formats
  • Workspace Integration: Dynamic loading of custom rules from workspace tools
  • Utility System: Graph analysis, AST parsing, and project resolution utilities
  • Format Support: Both legacy ESLintRC and modern flat config formats

Capabilities

Module Boundary Enforcement

Core rule that ensures proper module boundaries and dependency graph integrity within Nx workspaces. Prevents circular dependencies, enforces tagging constraints, and validates import patterns.

interface EnforceModuleBoundariesOptions {
  allow: string[];
  buildTargets: string[];
  depConstraints: DepConstraint[];
  enforceBuildableLibDependency: boolean;
  allowCircularSelfDependency: boolean;
  ignoredCircularDependencies: Array<[string, string]>;
  checkDynamicDependenciesExceptions: string[];
  banTransitiveDependencies: boolean;
  checkNestedExternalImports: boolean;
}

interface DepConstraint {
  sourceTag: string;
  onlyDependOnLibsWithTags?: string[];
  notDependOnLibsWithTags?: string[];
  bannedExternalImports?: string[];
}

Module Boundaries

Dependency Management

Validates package.json dependencies against actual usage, detecting missing dependencies, obsolete packages, and version mismatches across the workspace.

interface DependencyChecksOptions {
  buildTargets?: string[];
  checkMissingDependencies?: boolean;
  checkObsoleteDependencies?: boolean;
  checkVersionMismatches?: boolean;
  ignoredDependencies?: string[];
  ignoredFiles?: string[];
  includeTransitiveDependencies?: boolean;
  useLocalPathsForWorkspaceDependencies?: boolean;
  runtimeHelpers?: string[];
}

Dependency Checks

Plugin Configuration Validation

Validates Nx plugin configuration files including generators.json, executors.json, migrations.json, and related TypeScript implementations.

interface NxPluginChecksOptions {
  generatorsJson?: string;
  executorsJson?: string;
  migrationsJson?: string;
  packageJson?: string;
  allowedVersionStrings: string[];
  tsConfig?: string;
}

Plugin Validation

ESLint Configurations

Pre-configured ESLint setups for different frameworks and formats, supporting both legacy ESLintRC and modern flat config approaches.

interface PluginConfigs {
  // Legacy ESLintRC configs
  typescript: ESLintConfig;
  javascript: ESLintConfig;
  react: ESLintConfig;
  "react-base": ESLintConfig;
  "react-typescript": ESLintConfig;
  "react-jsx": ESLintConfig;
  angular: ESLintConfig;
  "angular-template": ESLintConfig;
  
  // Flat configs
  "flat/base": FlatConfig[];
  "flat/typescript": FlatConfig[];
  "flat/javascript": FlatConfig[];
  "flat/react": FlatConfig[];
  "flat/react-base": FlatConfig[];
  "flat/react-typescript": FlatConfig[];
  "flat/react-jsx": FlatConfig[];
  "flat/angular": FlatConfig[];
  "flat/angular-template": FlatConfig[];
}

ESLint Configurations

Workspace Rule Integration

Dynamically loads and integrates custom ESLint rules from the workspace's tools/eslint-rules directory, enabling project-specific linting extensions.

interface WorkspaceRules {
  [key: `workspace-${string}`]: TSESLint.RuleModule<string, unknown[]>;
  [key: `workspace/${string}`]: TSESLint.RuleModule<string, unknown[]>; // backwards compatibility
}

Workspace Rules

Plugin Exports

interface NxESLintPlugin {
  configs: PluginConfigs;
  rules: {
    "enforce-module-boundaries": RuleModule;
    "dependency-checks": RuleModule;
    "nx-plugin-checks": RuleModule;
  } & WorkspaceRules;
}

// Default export
export default NxESLintPlugin;

// Named exports
export { configs, rules };

Type Definitions

interface ESLintConfig {
  parser?: string;
  parserOptions?: ParserOptions;
  plugins?: string[];
  extends?: string[];
  rules?: Record<string, any>;
}

interface FlatConfig {
  files?: string[];
  ignores?: string[];
  plugins?: Record<string, any>;
  languageOptions?: LanguageOptions;
  rules?: Record<string, any>;
}

interface ParserOptions {
  ecmaVersion?: number;
  sourceType?: "module" | "script";
  tsconfigRootDir?: string;
}

interface LanguageOptions {
  parser?: any;
  ecmaVersion?: number;
  sourceType?: "module" | "script";
  parserOptions?: ParserOptions;
}