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 );
Configuration options for the ESLint instance. Enable or disable inline configuration comments.
Base config, extended by all configs used with this instance.
Enable result caching to improve performance.
cacheLocation
string
default: ".eslintcache"
Path to the cache file.
cacheStrategy
'metadata' | 'content'
default: "metadata"
Strategy used to detect changed files.
concurrency
number | 'auto' | 'off'
default: "off"
Maximum number of linting threads. Use "auto" to choose automatically.
Current working directory. Defaults to process.cwd().
If false, lintFiles() doesn’t throw when no target files are found.
fix
boolean | function
default: "false"
Execute in autofix mode. If a function, should return a boolean.
Array of rule types to apply fixes for (e.g., ["problem", "suggestion"]).
Array of feature flags to enable.
Set to false to skip glob resolution of input file paths.
False disables all ignore patterns except for the default ones.
Ignore file patterns in addition to config ignores. Relative to cwd.
Override config, overrides all configs used with this instance.
Config file path, or true to disable config file lookup.
When true, missing patterns don’t cause the operation to fail.
Preloaded plugins to use.
Enable statistics collection on lint results.
Show warnings when the file list includes ignored files.
Static Properties
ESLint.version
const version = ESLint . version ;
The ESLint version string (e.g., “9.0.0”).
ESLint.configType
const configType = ESLint . configType ; // "flat"
The type of configuration used by this class. Always returns "flat".
ESLint.defaultConfig
const defaultConfig = ESLint . defaultConfig ;
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.
Array of linting results for each file. Show LintResult properties
The absolute path to the file.
Array of suppressed lint messages.
Number of fixable errors.
Number of fixable warnings.
The fixed code (only present if fixes were applied).
Information about deprecated rules used.
lintText()
Lints the provided source code text.
const results = await eslint . lintText ( code , options );
The path to the file. Used for configuration matching.
When true, warns if the filePath is ignored.
Array containing a single linting result.
Loads a formatter to format lint results.
const formatter = await eslint . loadFormatter ( name );
const formatted = formatter . format ( results , resultsMeta );
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
Function that formats results: (results, resultsMeta) => string
calculateConfigForFile()
Calculates the configuration for a given file.
const config = await eslint . calculateConfigForFile ( filePath );
The calculated configuration object, or undefined if no configuration applies.
findConfigFile()
Finds the config file being used.
const configPath = await eslint . findConfigFile ( filePath );
The path to find the config file for. Defaults to cwd.
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 );
true if the path is ignored, false otherwise.
Returns metadata for rules used in the results.
const rulesMeta = eslint . getRulesMetaForResults ( results );
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 );
The feature flag name to check.
true if the flag is enabled, false otherwise.
Static Methods
ESLint.outputFixes()
Writes fixes to files.
await ESLint . outputFixes ( results );
The lint results containing fixes to apply.
ESLint.getErrorResults()
Filters results to only include errors.
const errorResults = ESLint . getErrorResults ( results );
The lint results to filter.
Results containing only error messages.
ESLint.fromOptionsModule()
Creates an ESLint instance from an options module URL.
const eslint = await ESLint . fromOptionsModule ( optionsURL );
URL to a module that exports ESLint options.
Examples
Basic Linting
Autofix
Lint Text
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 ();
const { ESLint } = require ( "eslint" );
async function fixFiles () {
const eslint = new ESLint ({ fix: true });
const results = await eslint . lintFiles ([ "src/**/*.js" ]);
await ESLint . outputFixes ( results );
const hasErrors = results . some (
result => result . errorCount > 0
);
if ( hasErrors ) {
const formatter = await eslint . loadFormatter ( "stylish" );
console . log ( formatter . format ( results ));
process . exit ( 1 );
}
}
fixFiles ();
const { ESLint } = require ( "eslint" );
async function lintCode () {
const eslint = new ESLint ({
overrideConfig: {
rules: {
"no-console" : "error" ,
"no-var" : "error"
}
}
});
const code = "var x = 1; console.log(x);" ;
const results = await eslint . lintText ( code , {
filePath: "example.js"
});
console . log ( results [ 0 ]. messages );
}
lintCode ();