Skip to main content

Node.js ESLint API Usage

Use this pattern when embedding linting in scripts, custom tooling, or release checks.

Minimal API flow​

import { ESLint } from "eslint";
import immutable from "eslint-plugin-immutable-2";

const eslint = new ESLint({
overrideConfig: {
files: ["**/*.{js,ts}"],
plugins: {
immutable,
},
rules: {
"immutable/no-let": "error",
},
},
});

const fileResults = await eslint.lintFiles(["src/**/*.{js,ts}"]);

const textResults = await eslint.lintText(
"let total = 0;\nfor (const value of values) total += value;",
{ filePath: "virtual.js" }
);

const allResults = [...fileResults, ...textResults];

await ESLint.outputFixes(allResults);

const formatter = await eslint.loadFormatter("stylish");
console.log(formatter.format(allResults));

API usage notes​

  • lintFiles(...) is best for repository scans.
  • lintText(...) is useful for generated/virtual content.
  • ESLint.outputFixes(...) writes autofix changes to disk for file-based results.
  • loadFormatter(...) lets you switch output style per integration context.

Debugging API integrations​

  • Compare API output with CLI output for the same target files.
  • Use --print-config with matching file paths to validate effective settings.
  • Ensure API runtime uses the same Node version and dependency graph as CI.