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

generators.mddocs/

Project Generators

Generators for setting up and configuring ESLint in Nx projects and workspaces, providing automated configuration management for both individual projects and workspace-wide setups.

Core Imports

import { lintProjectGenerator, lintInitGenerator, Linter, LinterType } from '@nx/eslint';
import type { Tree, GeneratorCallback } from '@nx/devkit';

Capabilities

Lint Project Generator

Main generator for adding ESLint configuration to a specific project within an Nx workspace.

/**
 * Generates lint configuration for a specific project
 * @param tree - Nx DevKit tree for file system operations
 * @param options - Configuration options for the generator
 * @returns Generator callback for async operations
 */
function lintProjectGenerator(tree: Tree, options: LintProjectOptions): GeneratorCallback;

interface LintProjectOptions {
  /** Name of the project to configure */
  project: string;
  /** Linter type to use */
  linter?: Linter | LinterType;
  /** File patterns to include in linting */
  eslintFilePatterns?: string[];
  /** Paths to TypeScript configuration files */
  tsConfigPaths?: string[];
  /** Skip formatting files after generation */
  skipFormat: boolean;
  /** Enable parser options project for type-aware rules */
  setParserOptionsProject?: boolean;
  /** Skip updating package.json */
  skipPackageJson?: boolean;
  /** Unit test runner being used */
  unitTestRunner?: string;
  /** Whether this is the root project */
  rootProject?: boolean;
  /** Keep existing dependency versions */
  keepExistingVersions?: boolean;
  /** Add Nx plugin for project inference */
  addPlugin?: boolean;
  /** ESLint configuration format to use */
  eslintConfigFormat?: 'mjs' | 'cjs';
}

Usage Examples:

import { Tree } from '@nx/devkit';
import { lintProjectGenerator } from '@nx/eslint';

// Basic project setup
await lintProjectGenerator(tree, {
  project: 'my-lib',
  skipFormat: false
});

// Advanced configuration
await lintProjectGenerator(tree, {
  project: 'my-app',
  linter: 'eslint',
  eslintFilePatterns: ['src/**/*.ts', 'src/**/*.tsx'],
  setParserOptionsProject: true,
  eslintConfigFormat: 'mjs',
  addPlugin: true,
  keepExistingVersions: false
});

// Root project setup
await lintProjectGenerator(tree, {
  project: 'workspace-root',
  rootProject: true,
  eslintFilePatterns: ['./src'],
  skipFormat: false
});

Lint Init Generator

Generator for initializing ESLint in the workspace, setting up global configuration and dependencies.

/**
 * Initializes ESLint plugin in the workspace
 * @param tree - Nx DevKit tree for file system operations
 * @param options - Initialization options
 * @returns Promise resolving to generator callback
 */
function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;

interface LinterInitOptions {
  /** Skip updating package.json dependencies */
  skipPackageJson?: boolean;
  /** Keep existing dependency versions */
  keepExistingVersions?: boolean;
  /** Update package.json scripts */
  updatePackageScripts?: boolean;
  /** Add Nx plugin for automatic inference */
  addPlugin?: boolean;
  /** ESLint configuration format */
  eslintConfigFormat?: 'mjs' | 'cjs';
}

Usage Examples:

import { lintInitGenerator } from '@nx/eslint';

// Basic workspace initialization
await lintInitGenerator(tree, {
  addPlugin: true
});

// Skip package.json updates
await lintInitGenerator(tree, {
  skipPackageJson: true,
  addPlugin: false,
  eslintConfigFormat: 'mjs'
});

// Keep existing versions
await lintInitGenerator(tree, {
  keepExistingVersions: true,
  updatePackageScripts: true
});

Internal Generator Function

Internal implementation providing additional configuration options.

/**
 * Internal lint project generator with extended options
 * @param tree - Nx DevKit tree
 * @param options - Extended configuration options
 * @returns Promise resolving to generator callback
 */
function lintProjectGeneratorInternal(
  tree: Tree, 
  options: LintProjectOptions & {
    addExplicitTargets?: boolean;
    addPackageJsonDependencyChecks?: boolean;
  }
): Promise<GeneratorCallback>;

ESLint Initialization Function

Core initialization logic for ESLint setup.

/**
 * Core ESLint initialization function
 * @param tree - Nx DevKit tree  
 * @param options - Initialization options
 * @returns Promise resolving to generator callback
 */
function initEsLint(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;

Generator Configuration

Available Generators

The package provides the following configured generators via generators.json:

  • init: Set up the ESLint plugin (hidden)
  • workspace-rules-project: Create workspace lint rules project (hidden)
  • workspace-rule: Create new workspace ESLint rule
  • convert-to-flat-config: Convert workspace to ESLint flat config
  • convert-to-inferred: Convert to use plugin inference

Generator Schemas

Each generator includes JSON schema validation for options:

interface GeneratorSchema {
  factory: string;
  schema: string;
  description: string;
  hidden?: boolean;
}

Usage in nx.json or project.json:

{
  "generators": {
    "@nx/eslint:lint-project": {
      "linter": "eslint",
      "eslintConfigFormat": "mjs"
    }
  }
}

Install with Tessl CLI

npx tessl i tessl/npm-nx--eslint

docs

executor.md

generators.md

index.md

plugin.md

utilities.md

tile.json