Skip to content

adapter-eslint

Runs ESLint via the Node API and generates an eslint.config.js bridge file for IDE integration.

Package: @retemper/lodestar-adapter-eslint

Managed file: eslint.config.js

Config Options

OptionTypeDescription
presetsstring[]Base configs -- 'recommended', 'strict', 'stylistic' (mapped to typescript-eslint)
pluginsRecord<string, unknown>ESLint plugin packages to include
rulesRecord<string, unknown>ESLint rules with standard severity/options format
ignoresstring[]Global ignore patterns
overrides{ files: string[]; rules: Record<string, unknown> }[]File-specific rule overrides

Example

ts
import { eslintAdapter } from '@retemper/lodestar-adapter-eslint';
import importX from 'eslint-plugin-import-x';
import unicorn from 'eslint-plugin-unicorn';

eslintAdapter({
  presets: ['strict'],
  plugins: { 'import-x': importX, unicorn },
  ignores: ['dist/**', 'node_modules/**'],
  rules: {
    '@typescript-eslint/consistent-type-imports': 'error',
    'import-x/no-default-export': 'error',
    'unicorn/prefer-node-protocol': 'error',
  },
  overrides: [
    {
      files: ['**/*.spec.ts'],
      rules: { '@typescript-eslint/no-explicit-any': 'off' },
    },
  ],
});

Generated Bridge File

verifySetup checks that eslint.config.js exists at the project root with the following content:

js
import { fromLodestar } from '@retemper/lodestar-adapter-eslint';

export default await fromLodestar();

This bridge file delegates to lodestar config at runtime, so IDEs and CI both read the same rules. If the file is missing, a setup violation is reported. If the file exists but its content does not match the expected bridge, a drift violation is reported.

Running lodestar check --fix auto-creates or updates the bridge file to resolve setup violations.

How verifySetup Works

  1. Checks that eslint.config.js exists in rootDir.
  2. Reads the file content and compares it against the expected bridge file content.
  3. Returns a missing violation if the file does not exist.
  4. Returns a drift violation (with a diff of expected vs actual) if the content does not match.
  5. Returns no violations if the bridge file is correct.

Drift means the bridge file was manually edited or generated by another tool. The fix is to let lodestar regenerate it.

How check Works

The adapter uses ESLint's Node API to lint files programmatically:

  1. Builds a flat config from the adapter options (presets, plugins, rules, overrides).
  2. Creates an ESLint instance with overrideConfigFile: true so the bridge file is bypassed during checks.
  3. Runs eslint.lintFiles() on the configured file patterns.
  4. Maps each ESLint message to a lodestar Violation with the original ESLint rule ID prefixed as eslint/{rule-name}.

Severity mapping: ESLint severity 2 becomes 'error', severity 1 becomes 'warn'.

Auto-fix

The adapter implements fix(), which runs ESLint with fix: true enabled. Running lodestar check --fix invokes this to auto-fix applicable ESLint violations, then writes the changes back to disk via ESLint.outputFixes().

Released under the MIT License.