The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Executor for running ESLint operations on projects with comprehensive configuration options, supporting both legacy and flat config formats with advanced caching and output capabilities.
import type { ExecutorContext } from '@nx/devkit';
import type { ESLint } from 'eslint';The primary executor function that runs ESLint on specified files with configurable options.
/**
* Runs ESLint on a project with specified configuration
* @param options - ESLint execution options
* @param context - Nx executor context with workspace information
* @returns Promise resolving to execution result
*/
function run(options: Schema, context: ExecutorContext): Promise<{ success: boolean }>;
interface ExecutorContext {
/** Workspace root directory */
root: string;
/** Name of the project being executed */
projectName: string;
/** All project configurations in the workspace */
projectsConfigurations: {
projects: Record<string, ProjectConfiguration>;
};
}
interface ProjectConfiguration {
root: string;
projectType?: string;
targets?: Record<string, any>;
}Complete configuration schema for the lint executor with all available options.
interface Schema {
/** Path to ESLint configuration file */
eslintConfig?: string;
/** File patterns to lint */
lintFilePatterns: string[];
/** Output format for lint results */
format: 'stylish' | 'compact' | 'codeframe' | 'unix' | 'visualstudio' | 'table' | 'checkstyle' | 'html' | 'jslint-xml' | 'json' | 'json-with-metadata' | 'junit' | 'tap';
/** Continue execution even if linting fails */
force: boolean;
/** Suppress most output except errors */
silent: boolean;
/** Automatically fix problems where possible */
fix: boolean;
/** Enable result caching */
cache: boolean;
/** Cache location for storing results */
cacheLocation?: string;
/** Output file for lint results */
outputFile?: string;
/** Maximum number of warnings allowed */
maxWarnings: number;
/** Only show errors, suppress warnings */
quiet: boolean;
/** Path to ignore file */
ignorePath?: string;
/** Disable use of .eslintrc files */
noEslintrc: boolean;
/** Whether configuration uses type-aware rules */
hasTypeAwareRules?: boolean;
/** Cache strategy to use */
cacheStrategy: 'metadata' | 'content';
/** Additional rules directories */
rulesdir: string[];
/** Resolve plugins relative to this path */
resolvePluginsRelativeTo?: string;
/** Report unused disable directives */
reportUnusedDisableDirectives?: 'off' | 'warn' | 'error';
/** Print configuration for a file */
printConfig?: string;
/** Error on unmatched file patterns */
errorOnUnmatchedPattern?: boolean;
}Usage Examples:
import { ExecutorContext } from '@nx/devkit';
// Basic linting
const result = await run({
eslintConfig: null, // Use default config resolution
lintFilePatterns: ['src/**/*.ts'],
format: 'stylish',
force: false,
silent: false,
fix: false,
cache: true,
noEslintrc: false,
outputFile: null,
cacheLocation: null,
maxWarnings: -1,
quiet: false,
ignorePath: null,
hasTypeAwareRules: false,
cacheStrategy: 'metadata',
rulesdir: [],
resolvePluginsRelativeTo: null,
reportUnusedDisableDirectives: null
}, context);
// Linting with fixes and JSON output
const result = await run({
eslintConfig: 'eslint.config.js',
lintFilePatterns: ['src/**/*.{ts,tsx}', 'tests/**/*.ts'],
format: 'json',
force: false,
silent: false,
fix: true,
cache: true,
outputFile: 'lint-results.json',
maxWarnings: 0,
quiet: false,
hasTypeAwareRules: true,
cacheStrategy: 'content',
errorOnUnmatchedPattern: true
}, context);The executor is registered in executors.json:
{
"executors": {
"lint": {
"implementation": "./src/executors/lint/lint.impl",
"schema": "./src/executors/lint/schema.json",
"hasher": "./src/executors/lint/hasher",
"description": "Run ESLint on a project."
}
}
}The executor supports all standard ESLint formatters:
type Formatter =
| 'stylish' // Default human-readable format
| 'compact' // Compact format similar to GCC
| 'codeframe' // Output like a snippet of code
| 'unix' // Unix style format
| 'visualstudio' // Visual Studio format
| 'table' // Table format
| 'checkstyle' // Checkstyle XML format
| 'html' // HTML format
| 'jslint-xml' // JSLint XML format
| 'json' // JSON format
| 'json-with-metadata' // JSON with metadata
| 'junit' // JUnit XML format
| 'tap'; // TAP formatUsage Examples:
// JSON output for CI/CD integration
await run({
// ... other options
format: 'json',
outputFile: 'eslint-results.json'
}, context);
// JUnit XML for test reporting
await run({
// ... other options
format: 'junit',
outputFile: 'eslint-results.xml'
}, context);
// HTML report for viewing in browser
await run({
// ... other options
format: 'html',
outputFile: 'eslint-report.html'
}, context);The executor resolves ESLint configuration in the following order:
eslintConfig optioneslint.config.js, eslint.config.mjs, eslint.config.cjs).eslintrc.*)interface ConfigResolution {
/** Explicit configuration file path */
explicitConfig?: string;
/** Automatically resolved flat config */
flatConfig?: string;
/** Legacy configuration file */
legacyConfig?: string;
/** Final resolved configuration path */
resolvedConfig: string | null;
}The executor respects ESLint environment variables:
ESLINT_USE_FLAT_CONFIG: Force flat config usageESLINT_CONFIG_FILE: Override config file pathtype CacheStrategy = 'content' | 'metadata';
interface CacheOptions {
/** Enable caching */
cache: boolean;
/** Cache location directory */
cacheLocation?: string;
/** Strategy for cache invalidation */
cacheStrategy?: CacheStrategy;
}Cache Strategy Details:
content: Cache based on file content hashes (more accurate, slower)metadata: Cache based on file modification times (faster, less accurate)Cache files are stored in:
cacheLocationnode_modules/.cache/eslint/ (default)Special handling for TypeScript ESLint parser configuration errors:
interface TypeAwareRulesError {
/** Error message indicating missing parserOptions.project */
message: string;
/** Rule name that triggered the error */
ruleName?: string;
/** File being linted when error occurred */
reportedFile?: string;
/** Resolved configuration file path */
configPath?: string;
}Example Error Output:
Error: You have attempted to use the lint rule "@typescript-eslint/no-unused-vars"
which requires the full TypeScript type-checker to be available, but you do not have
"parserOptions.project" configured to point at your project tsconfig.json files in
the relevant TypeScript file "overrides" block of your ESLint config "eslint.config.js"
Occurred while linting src/main.ts
Please see https://nx.dev/recipes/tips-n-tricks/eslint for full guidance on how to resolve this issue.interface ExecutionResult {
/** Whether execution completed successfully */
success: boolean;
}
interface LintResults {
/** Total number of errors found */
errors: number;
/** Total number of warnings found */
warnings: number;
/** Number of fixable errors */
fixableErrors: number;
/** Number of fixable warnings */
fixableWarnings: number;
}Install with Tessl CLI
npx tessl i tessl/npm-nx--eslint