CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nx--eslint

The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

executor.mddocs/

Lint Executor

Executor for running ESLint operations on projects with comprehensive configuration options, supporting both legacy and flat config formats with advanced caching and output capabilities.

Core Imports

import type { ExecutorContext } from '@nx/devkit';
import type { ESLint } from 'eslint';

Capabilities

Main Executor Function

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>;
}

Executor Schema

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);

Executor Registration

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."
    }
  }
}

Output Formats

Available Formatters

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 format

Usage 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);

Configuration Resolution

Config File Resolution

The executor resolves ESLint configuration in the following order:

  1. Explicit eslintConfig option
  2. Flat config files (eslint.config.js, eslint.config.mjs, eslint.config.cjs)
  3. Legacy config files (.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;
}

Environment Variables

The executor respects ESLint environment variables:

  • ESLINT_USE_FLAT_CONFIG: Force flat config usage
  • ESLINT_CONFIG_FILE: Override config file path

Caching

Cache Strategies

type 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 Location

Cache files are stored in:

  1. Specified cacheLocation
  2. node_modules/.cache/eslint/ (default)
  3. Per-project subdirectories when using project-specific caching

Error Handling

Type-Aware Rules Error

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.

Execution Results

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

docs

executor.md

generators.md

index.md

plugin.md

utilities.md

tile.json