The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.
npx @tessl/cli install tessl/npm-nx--eslint@21.5.0@nx/eslint is an ESLint integration package for Nx workspaces that provides executors, generators, and utilities for linting JavaScript and TypeScript projects. It offers comprehensive linting capabilities with support for both legacy .eslintrc and modern flat config formats, along with automated setup and configuration management for monorepo environments.
npm install @nx/eslintimport { lintProjectGenerator, lintInitGenerator, Linter, LinterType } from '@nx/eslint';
import { hasRulesRequiringTypeChecking } from '@nx/eslint';For plugin functionality:
import { createNodes, createNodesV2, EslintPluginOptions } from '@nx/eslint/plugin';import { Tree } from '@nx/devkit';
import { lintProjectGenerator } from '@nx/eslint';
// Add linting to a project
await lintProjectGenerator(tree, {
project: 'my-app',
linter: 'eslint',
eslintFilePatterns: ['src/**/*.ts'],
skipFormat: false
});import { lintInitGenerator } from '@nx/eslint';
// Initialize ESLint in the workspace
await lintInitGenerator(tree, {
skipPackageJson: false,
addPlugin: true
});import { hasRulesRequiringTypeChecking } from '@nx/eslint';
import type { Linter } from 'eslint';
const eslintConfig: Linter.Config = {
rules: {
'@typescript-eslint/no-unused-vars': 'error'
}
};
const requiresTypeInfo = hasRulesRequiringTypeChecking(eslintConfig);
// Returns: boolean indicating if config uses type-aware rules@nx/eslint is built around several key components:
Core generators for setting up and configuring ESLint in Nx projects and workspaces.
function lintProjectGenerator(tree: Tree, options: LintProjectOptions): GeneratorCallback;
function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
interface LintProjectOptions {
project: string;
linter?: Linter | LinterType;
eslintFilePatterns?: string[];
tsConfigPaths?: string[];
skipFormat: boolean;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
unitTestRunner?: string;
rootProject?: boolean;
keepExistingVersions?: boolean;
addPlugin?: boolean;
eslintConfigFormat?: 'mjs' | 'cjs';
}
interface LinterInitOptions {
skipPackageJson?: boolean;
keepExistingVersions?: boolean;
updatePackageScripts?: boolean;
}Plugin functionality for automatic ESLint project inference and target creation within Nx workspaces.
const createNodesV2: CreateNodesV2<EslintPluginOptions>;
const createNodes: CreateNodes<EslintPluginOptions>;
interface EslintPluginOptions {
targetName?: string;
extensions?: string[];
}Executor for running ESLint operations on projects with comprehensive configuration options.
function run(options: Schema, context: ExecutorContext): Promise<{ success: boolean }>;
interface Schema {
eslintConfig?: string;
lintFilePatterns: string[];
format: 'stylish' | 'compact' | 'codeframe' | 'unix' | 'visualstudio' | 'table' | 'checkstyle' | 'html' | 'jslint-xml' | 'json' | 'json-with-metadata' | 'junit' | 'tap';
force: boolean;
silent: boolean;
fix: boolean;
cache: boolean;
cacheLocation?: string;
outputFile?: string;
maxWarnings: number;
quiet: boolean;
ignorePath?: string;
noEslintrc: boolean;
hasTypeAwareRules?: boolean;
cacheStrategy: 'metadata' | 'content';
rulesdir: string[];
resolvePluginsRelativeTo?: string;
reportUnusedDisableDirectives?: 'off' | 'warn' | 'error';
printConfig?: string;
errorOnUnmatchedPattern?: boolean;
}Utilities for analyzing and managing ESLint configurations, including type-aware rule detection.
function hasRulesRequiringTypeChecking(eslintConfig: Linter.Config): boolean;type LinterType = 'eslint' | 'none';
enum Linter {
EsLint = 'eslint',
None = 'none'
}
interface GeneratorCallback {
(): void | Promise<void>;
}
interface Tree {
// Nx DevKit Tree interface for file system operations
}
interface ExecutorContext {
root: string;
projectName: string;
projectsConfigurations: {
projects: Record<string, any>;
};
}