CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rushstack--eslint-patch

Enhance ESLint with better support for large scale monorepos

Pending
Overview
Eval results
Files

modern-module-resolution.mddocs/

Modern Module Resolution

Modern Module Resolution patch solves the longstanding issue where ESLint requires plugins to be installed as peer dependencies in every project that uses a shareable config, even when the config package itself provides those plugins.

Capabilities

Module Resolution Patch

Applies runtime patches to ESLint's ConfigArrayFactory to resolve plugins relative to the config file instead of the project root.

/**
 * Applies the modern module resolution patch to ESLint
 * Must be required before ESLint processes any configuration
 */
require("@rushstack/eslint-patch/modern-module-resolution");

Usage Example:

// .eslintrc.js
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
  extends: ['@your-company/eslint-config'], // This config can now provide its own plugins
  parserOptions: { tsconfigRootDir: __dirname }
};

ESLint Version Support

The patch automatically detects and handles different ESLint versions:

  • ESLint 6.x: Patches _loadPlugin method with importerPath parameter
  • ESLint 7.x/8.x: Patches _loadPlugin method with context object
  • ESLint 9.x: Supports both legacy and flat config modes

Plugin Resolution Behavior

When ESLint attempts to load a plugin:

  1. Primary Resolution: Tries to resolve plugin relative to the config file location
  2. Fallback Resolution: If primary fails with MODULE_NOT_FOUND or invalid path, falls back to original ESLint behavior
  3. Error Propagation: Non-resolution errors are re-thrown unchanged
// Internal patch behavior (not directly callable)
interface ModuleResolver {
  resolve(moduleName: string, relativeToPath: string): string;
}

Config Package Structure

With this patch, config packages can be structured as follows:

{
  "name": "@your-company/eslint-config",
  "dependencies": {
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "eslint-plugin-react": "^7.0.0"
  },
  "peerDependencies": {
    "eslint": "^8.0.0"
  }
}

Consumer projects only need:

{
  "devDependencies": {
    "@rushstack/eslint-patch": "^1.12.0",
    "@your-company/eslint-config": "^1.0.0",
    "eslint": "^8.0.0"
  }
}

Compatibility Notes

  • ESLint Flat Config: ESLint 8.21.0+ includes native flat config mode (ESLINT_USE_FLAT_CONFIG) that may reduce need for this patch
  • Editor Extensions: Works with VS Code ESLint extension, WebStorm, and other editor integrations
  • Monorepo Support: Particularly useful in Rush Stack monorepos and similar setups

Error Handling

The patch handles several error scenarios:

  • MODULE_NOT_FOUND: Falls back to original resolution
  • ERR_INVALID_ARG_VALUE: Falls back to original resolution (invalid importer path)
  • Other errors: Re-thrown unchanged to preserve original ESLint error handling

Install with Tessl CLI

npx tessl i tessl/npm-rushstack--eslint-patch

docs

bulk-suppressions.md

custom-config-package-names.md

index.md

modern-module-resolution.md

tile.json