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
Configuration options for the ESLint instance.
Static Properties
ESLint.version
The ESLint version string (e.g., “9.0.0”).
ESLint.configType
The type of configuration used by this class. Always returns
"flat".ESLint.defaultConfig
The default configuration that ESLint uses internally.
Instance Methods
lintFiles()
Lints files matching the given patterns.File patterns to lint. Can be file paths, directory paths, or glob patterns.
Array of linting results for each file.
lintText()
Lints the provided source code text.The source code to lint.
Array containing a single linting result.
loadFormatter()
Loads a formatter to format lint results.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
calculateConfigForFile()
Calculates the configuration for a given file.The path to the file.
The calculated configuration object, or
undefined if no configuration applies.findConfigFile()
Finds the config file being used.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.The path to check.
true if the path is ignored, false otherwise.getRulesMetaForResults()
Returns metadata for rules used in the results.The lint results to get metadata for.
Object mapping rule IDs to their metadata.
hasFlag()
Checks if a feature flag is enabled.The feature flag name to check.
true if the flag is enabled, false otherwise.Static Methods
ESLint.outputFixes()
Writes fixes to files.The lint results containing fixes to apply.
ESLint.getErrorResults()
Filters results to only include errors.The lint results to filter.
Results containing only error messages.
ESLint.fromOptionsModule()
Creates an ESLint instance from an options module URL.URL to a module that exports ESLint options.
A new ESLint instance.
Examples
- Basic Linting
- Autofix
- Lint Text