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

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

Static Properties

Linter.version

const version = Linter.version;
version
string
The ESLint version string.

Instance Methods

verify()

Verifies text against the specified rules.
const messages = linter.verify(textOrSourceCode, config, filenameOrOptions);
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.
const result = linter.verifyAndFix(text, config, filenameOrOptions);
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.
const sourceCode = linter.getSourceCode();
sourceCode
SourceCode | null
The SourceCode object from the last verify() call, or null.

getSuppressedMessages()

Gets suppressed messages from the last verification.
const suppressedMessages = linter.getSuppressedMessages();
suppressedMessages
SuppressedLintMessage[]
Array of messages that were suppressed by directives.

getTimes()

Gets timing information from the last verification (when stats are enabled).
const times = linter.getTimes();
times
object

getFixPassCount()

Gets the number of autofix passes made in the last run.
const count = linter.getFixPassCount();
count
number
The number of autofix passes.

hasFlag()

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

Examples

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

const linter = new Linter();

const code = "var foo = 'bar';";
const config = {
  rules: {
    "no-var": "error",
    "quotes": ["error", "double"]
  }
};

const messages = linter.verify(code, config);
console.log(messages);
// [
//   {
//     ruleId: 'no-var',
//     severity: 2,
//     message: 'Unexpected var, use let or const instead.',
//     line: 1,
//     column: 1,
//     ...
//   },
//   ...
// ]

Differences from ESLint Class

The Linter class differs from the ESLint class in several ways:
FeatureLinterESLint
File I/ONoYes
Config file loadingNoYes
CachingNoYes
FormattersNoYes
Glob patternsNoYes
Synchronous APIYesNo
Use caseLow-level, in-memory lintingFull linting workflow
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.