Skip to main content
The Linter class is a low-level API for verifying JavaScript code. Unlike the ESLint class, Linter does not handle file I/O or configuration file loading. It works directly with code strings and configuration objects.

Constructor

options
object
Configuration options for the Linter instance.

Static Properties

Linter.version

version
string
The ESLint version string.

Instance Methods

verify()

Verifies text against the specified rules.
textOrSourceCode
string | SourceCode
required
The JavaScript code to verify, or a SourceCode object.
config
Config | Config[]
required
The configuration object or array of configuration objects.
filenameOrOptions
string | object
The filename or options object.
messages
LintMessage[]
Array of lint messages.

verifyAndFix()

Performs multiple autofix passes over the text.
text
string
required
The source text to apply fixes to.
config
Config | Config[]
required
The ESLint config object or array.
filenameOrOptions
string | object
The filename or options object.
result
object

getSourceCode()

Gets the SourceCode object from the last verification.
sourceCode
SourceCode | null
The SourceCode object from the last verify() call, or null.

getSuppressedMessages()

Gets suppressed messages from the last verification.
suppressedMessages
SuppressedLintMessage[]
Array of messages that were suppressed by directives.

getTimes()

Gets timing information from the last verification (when stats are enabled).
times
object

getFixPassCount()

Gets the number of autofix passes made in the last run.
count
number
The number of autofix passes.

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.

Examples

Differences from ESLint Class

The Linter class differs from the ESLint class in several ways: Use Linter when you need fine-grained control and already have the code and configuration in memory. Use ESLint for a complete linting workflow with file handling.