Skip to main content
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

options
object
Configuration options for the ESLint instance.

Static Properties

ESLint.version

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

ESLint.configType

configType
string
The type of configuration used by this class. Always returns "flat".

ESLint.defaultConfig

defaultConfig
FlatConfigArray
The default configuration that ESLint uses internally.

Instance Methods

lintFiles()

Lints files matching the given 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.
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.
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.
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.
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.
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.
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.
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.
results
LintResult[]
required
The lint results containing fixes to apply.

ESLint.getErrorResults()

Filters results to only include errors.
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.
optionsURL
URL
required
URL to a module that exports ESLint options.
eslint
ESLint
A new ESLint instance.

Examples