CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nx--eslint-plugin

ESLint plugin for Nx monorepos with boundary enforcement and dependency management rules.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

plugin-validation.mddocs/

Plugin Configuration Validation

The nx-plugin-checks rule validates Nx plugin configuration files to ensure proper structure, valid implementation paths, and correct schema definitions for generators, executors, and migrations.

Capabilities

Nx Plugin Checks Rule

Validates common Nx plugin configuration files including generators.json, executors.json, migrations.json, and their TypeScript implementations.

/**
 * ESLint rule that validates Nx plugin configuration files
 * Rule name: "@nx/nx-plugin-checks"
 */
interface NxPluginChecksRule {
  name: "nx-plugin-checks";
  meta: {
    docs: {
      description: "Checks common nx-plugin configuration files for validity";
    };
    schema: [NxPluginChecksOptions];
    messages: Record<MessageIds, string>;
  };
  defaultOptions: [NxPluginChecksOptions];
  create: (context: RuleContext) => RuleListener;
}

Configuration Options

Complete configuration interface for plugin validation behavior.

interface NxPluginChecksOptions {
  /** Path to the project's generators.json file, relative to project root */
  generatorsJson?: string;
  
  /** Path to the project's executors.json file, relative to project root */
  executorsJson?: string;
  
  /** Path to the project's migrations.json file, relative to project root */
  migrationsJson?: string;
  
  /** Path to the project's package.json file, relative to project root */
  packageJson?: string;
  
  /** List of valid version specifiers for package versions */
  allowedVersionStrings: string[];
  
  /** Path to TypeScript configuration file for implementation validation */
  tsConfig?: string;
}

Default Configuration

Standard defaults for most Nx plugin projects.

const DEFAULT_OPTIONS: NxPluginChecksOptions = {
  generatorsJson: 'generators.json',
  executorsJson: 'executors.json', 
  migrationsJson: 'migrations.json',
  packageJson: 'package.json',
  allowedVersionStrings: ['*', 'latest', 'next'],
  tsConfig: 'tsconfig.lib.json'
};

Error Messages

All possible validation messages returned by the rule.

type MessageIds =
  | "missingRequiredSchema"
  | "invalidSchemaPath"
  | "missingImplementation"
  | "invalidImplementationPath"
  | "invalidImplementationModule"
  | "unableToReadImplementationExports"
  | "invalidVersion"
  | "missingVersion"
  | "noGeneratorsOrSchematicsFound"
  | "noExecutorsOrBuildersFound"
  | "valueShouldBeObject";

Usage Examples:

// Basic plugin validation
{
  rules: {
    "@nx/nx-plugin-checks": "error"
  }
}

// Custom configuration paths
{
  rules: {
    "@nx/nx-plugin-checks": [
      "error",
      {
        generatorsJson: "src/generators.json",
        executorsJson: "src/executors.json",
        migrationsJson: "migrations.json",
        packageJson: "package.json",
        tsConfig: "tsconfig.json"
      }
    ]
  }
}

// Custom allowed version strings
{
  rules: {
    "@nx/nx-plugin-checks": [
      "error",
      {
        allowedVersionStrings: ["*", "latest", "next", "beta", "alpha"]
      }
    ]
  }
}

Validation Behaviors

The rule performs comprehensive validation across multiple areas:

  1. File Existence: Verifies configuration files exist at specified paths
  2. JSON Structure: Validates JSON syntax and basic structure
  3. Schema Validation: Ensures required schema properties are present and valid
  4. Implementation Validation: Checks that implementation files exist and export correct functions
  5. Version Validation: Validates version strings against allowed patterns
  6. Cross-Reference Validation: Ensures consistency between configuration files and package.json

Generator Configuration Validation

For generators.json files, the rule validates:

interface GeneratorConfig {
  generators: {
    [name: string]: {
      factory: string; // Path to implementation function
      schema: string; // Path to JSON schema file
      description?: string;
      aliases?: string[];
      hidden?: boolean;
    };
  };
}

Validation Checks:

  • Factory implementation file exists and exports the specified function
  • Schema file exists and contains valid JSON schema
  • Implementation function has correct signature
  • All required properties are present

Executor Configuration Validation

For executors.json files, the rule validates:

interface ExecutorConfig {
  executors: {
    [name: string]: {
      implementation: string; // Path to implementation function
      schema: string; // Path to JSON schema file
      description?: string;
      hasher?: string; // Path to custom hasher function
    };
  };
}

Validation Checks:

  • Implementation file exists and exports default executor function
  • Schema file exists and contains valid JSON schema
  • Custom hasher function exists if specified
  • Implementation function returns proper executor result

Migration Configuration Validation

For migrations.json files, the rule validates:

interface MigrationConfig {
  generators?: {
    [version: string]: {
      version: string;
      description?: string;
      factory?: string; // Path to migration function
      cli?: "nx"; // CLI compatibility
    };
  };
  packageJsonUpdates?: {
    [version: string]: {
      version: string;
      packages: {
        [packageName: string]: {
          version: string;
          alwaysAddToPackageJson?: boolean;
        };
      };
    };
  };
}

Validation Checks:

  • Version strings match semantic versioning patterns
  • Migration factory functions exist and are properly implemented
  • Package version specifications are valid
  • Migration descriptions are informative

Package.json Integration

The rule also validates package.json integration:

interface PackageJsonPluginConfig {
  "nx-migrations"?: {
    migrations: string; // Path to migrations.json
  };
  generators?: string; // Path to generators.json (legacy)
  schematics?: string; // Path to generators.json (Angular compatibility)
  executors?: string; // Path to executors.json  
  builders?: string; // Path to executors.json (Angular compatibility)
}

Validation Checks:

  • Migration configuration points to valid migrations.json
  • Generator/schematic paths point to valid files
  • Executor/builder paths point to valid files
  • Plugin configuration is consistent across files

TypeScript Implementation Validation

When tsConfig is specified, the rule performs advanced TypeScript analysis:

  • Validates that implementation files compile successfully
  • Checks function exports match configuration expectations
  • Validates parameter types for generator/executor functions
  • Ensures proper return types for all plugin functions

Integration with Nx Plugin System

The rule understands and validates against Nx plugin conventions:

  • Supports both generators.json and schematics.json naming
  • Supports both executors.json and builders.json naming
  • Validates against Nx plugin API requirements
  • Integrates with Nx workspace configuration standards

Install with Tessl CLI

npx tessl i tessl/npm-nx--eslint-plugin

docs

configurations.md

dependency-checks.md

index.md

module-boundaries.md

plugin-validation.md

workspace-rules.md

tile.json