LinuxCommandLibrary

eslint

Analyze JavaScript code for style and errors

TLDR

Create the ESLint configuration file

$ eslint --init
copy

Lint one or more files
$ eslint [path/to/file1.js path/to/file2.js ...]
copy

Fix lint issues
$ eslint --fix
copy

Lint using the specified configuration file
$ eslint [[-c|--config]] [path/to/config_file] [path/to/file1.js path/to/file2.js ...]
copy

SYNOPSIS

eslint [options] <file|glob|directory>...

PARAMETERS

--cache
    Enable result caching to speed up subsequent runs

--cache-location <path>
    Path to cache location (default: .eslintcache)

--config <path>
    Configuration file path

--env <environment>[,<environment>]
    Specify environments (e.g., --env node,es6)

--ext <extensions>
    Specify file extensions to lint (default: .js)

--fix
    Automatically fix linting problems

--fix-dry-run
    Like --fix but without changing files

--fix-type <types>
    Specify types of fixes to apply

--format <formatter>
    Specify output formatter (e.g., stylish, json)

--global
    Treat args as globals

--ignore-pattern <pattern>
    Pattern for files/directories to ignore

--init
    Interactive setup for new config

--max-warnings <n>
    Number of warnings to allow before exiting nonzero

--no-eslintrc
    Disable .eslintrc lookup

--output-file <path>
    Specify file to write results

--parser <path>
    Specify parser to use

--quiet
    Report only errors, no warnings

--rule <name:severity>
    Override rule severity (e.g., --rule no-alert:off)

-v, --version
    Output version

-h, --help
    Display help

DESCRIPTION

ESLint is an open-source, pluggable linter for JavaScript and JSX code, designed to identify problematic patterns, enforce consistent coding styles, and catch potential errors early in development.

It analyzes code against configurable rules, supports ECMAScript standards up to the latest versions, and integrates with TypeScript via parsers. Key strengths include:
• Over 200 built-in rules, extensible via plugins like eslint-plugin-react.
• Automatic fixing with --fix option.
• Support for linting files, directories, globs, or stdin input.
• Multiple output formats and CI/CD integration.

Installation is via npm: npm install eslint --save-dev. Configuration occurs through .eslintrc.* files or package.json. Widely used in Node.js projects, React/Vue apps, and modern web development for maintaining code quality. ESLint promotes best practices, reduces bugs, and improves team collaboration by standardizing codebases.

CAVEATS

Requires Node.js (≥14) and npm. Installed per-project via npm, not system-wide. Performance depends on project size; use --cache for large codebases. Some rules require plugins.

CONFIGURATION FILES

Supports .eslintrc.js, .eslintrc.json, .eslintrc.yaml, or eslintConfig in package.json. Defines rules, envs, plugins, and parser options.

PLUGINS AND SHAREABLE CONFIGS

Extend with npm packages like @typescript-eslint/parser or eslint-config-airbnb. Install via npm and reference in config.

HISTORY

Created in June 2013 by Nicholas C. Zakas at Yahoo to replace JSLint/JSHint limitations. Transferred to OpenJS Foundation in 2020. Reached v9.x in 2023 with Flat Config support for better performance.

SEE ALSO

node(1), npm(1), npx(1)

Copied to clipboard