Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/eslint/eslint/llms.txt

Use this file to discover all available pages before exploring further.

The ESLint class is the primary interface for integrating ESLint into Node.js applications. It supports flat config and provides high-level methods for linting files, formatting results, and managing configurations.

Constructor

const { ESLint } = require("eslint");
const eslint = new ESLint(options);
options
object
Configuration options for the ESLint instance.

Static Properties

ESLint.version

const version = ESLint.version;
version
string
The ESLint version string (e.g., “9.0.0”).

ESLint.configType

const configType = ESLint.configType; // "flat"
configType
string
The type of configuration used by this class. Always returns "flat".

ESLint.defaultConfig

const defaultConfig = ESLint.defaultConfig;
defaultConfig
FlatConfigArray
The default configuration that ESLint uses internally.

Instance Methods

lintFiles()

Lints files matching the given patterns.
const results = await eslint.lintFiles(patterns);
patterns
string | string[]
required
File patterns to lint. Can be file paths, directory paths, or glob patterns.
results
LintResult[]
Array of linting results for each file.

lintText()

Lints the provided source code text.
const results = await eslint.lintText(code, options);
code
string
required
The source code to lint.
options
object
results
LintResult[]
Array containing a single linting result.

loadFormatter()

Loads a formatter to format lint results.
const formatter = await eslint.loadFormatter(name);
const formatted = formatter.format(results, resultsMeta);
name
string
default:"stylish"
Name of the formatter. Can be:
  • A built-in formatter name (e.g., "stylish", "json")
  • A third-party formatter (e.g., "eslint-formatter-pretty")
  • A file path to a custom formatter
formatter
object

calculateConfigForFile()

Calculates the configuration for a given file.
const config = await eslint.calculateConfigForFile(filePath);
filePath
string
required
The path to the file.
config
object | undefined
The calculated configuration object, or undefined if no configuration applies.

findConfigFile()

Finds the config file being used.
const configPath = await eslint.findConfigFile(filePath);
filePath
string
The path to find the config file for. Defaults to cwd.
configPath
string | undefined
The path to the config file, or undefined if not found.

isPathIgnored()

Checks if a path is ignored by ESLint.
const ignored = await eslint.isPathIgnored(filePath);
filePath
string
required
The path to check.
ignored
boolean
true if the path is ignored, false otherwise.

getRulesMetaForResults()

Returns metadata for rules used in the results.
const rulesMeta = eslint.getRulesMetaForResults(results);
results
LintResult[]
required
The lint results to get metadata for.
rulesMeta
Record<string, RulesMeta>
Object mapping rule IDs to their metadata.

hasFlag()

Checks if a feature flag is enabled.
const enabled = eslint.hasFlag(flag);
flag
string
required
The feature flag name to check.
enabled
boolean
true if the flag is enabled, false otherwise.

Static Methods

ESLint.outputFixes()

Writes fixes to files.
await ESLint.outputFixes(results);
results
LintResult[]
required
The lint results containing fixes to apply.

ESLint.getErrorResults()

Filters results to only include errors.
const errorResults = ESLint.getErrorResults(results);
results
LintResult[]
required
The lint results to filter.
errorResults
LintResult[]
Results containing only error messages.

ESLint.fromOptionsModule()

Creates an ESLint instance from an options module URL.
const eslint = await ESLint.fromOptionsModule(optionsURL);
optionsURL
URL
required
URL to a module that exports ESLint options.
eslint
ESLint
A new ESLint instance.

Examples

const { ESLint } = require("eslint");

async function main() {
  const eslint = new ESLint();
  const results = await eslint.lintFiles(["src/**/*.js"]);
  
  const formatter = await eslint.loadFormatter("stylish");
  const resultText = formatter.format(results);
  console.log(resultText);
}

main();