ESLint

10.2.1 · active · verified Sat Apr 18

ESLint is a powerful, pluggable tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, enforcing coding standards and catching potential issues. It uses an AST-based parser and is entirely pluggable. The current stable version is v10.2.1. It follows a frequent release cadence for minor features and bug fixes, with major versions introducing breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to programmatically use the ESLint class to lint a string of JavaScript code with a custom configuration, reporting any found issues.

import { ESLint } from 'eslint';

async function lintCode(code: string): Promise<void> {
  const eslint = new ESLint({
    useEslintrc: false, // Don't use .eslintrc.* files
    overrideConfigFile: true, // Use this config file
    overrideConfig: {
      languageOptions: {
        ecmaVersion: 2022,
        sourceType: "module",
        globals: {
          console: "readonly"
        }
      },
      rules: {
        "no-unused-vars": "warn",
        "prefer-const": "error"
      }
    }
  });

  const results = await eslint.lintText(code);

  console.log(`Linting results for: "${code}"`);
  results.forEach(result => {
    result.messages.forEach(message => {
      console.log(
        `  Line ${message.line}, Col ${message.column}: ${message.message} (${message.ruleId})`
      );
    });
  });
}

lintCode(`
  var x = 1; // no-unused-vars (warn), prefer-const (error)
  console.log('hello');
  const y = 2;
`).catch(console.error);

view raw JSON →