ESLint plugin for Nx monorepos with boundary enforcement and dependency management rules.
npx @tessl/cli install tessl/npm-nx--eslint-plugin@21.4.0The @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.
npm install @nx/eslint-pluginimport plugin from "@nx/eslint-plugin";
// Access configs: plugin.configs
// Access rules: plugin.rulesFor 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;// 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"]
}
]
}
]
}
}
];The plugin is organized around several key components:
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[];
}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[];
}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;
}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[];
}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
}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 };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;
}