Skip to main content

Command Line Interface

The ESLint Command Line Interface (CLI) lets you execute linting from the terminal. The CLI has a variety of options that you can pass to configure ESLint.

Basic Usage

ESLint requires Node.js for installation. Most users use npx to run ESLint on the command line:
npx eslint [options] [file|dir|glob]*
npx eslint file1.js file2.js
When passing a glob as a parameter, it is expanded by your shell. Quote your parameter if you need it to run in Windows: npx eslint "lib/**"

CLI Options Reference

Basic Configuration

Use a specific configuration file instead of the default eslint.config.js.
npx eslint -c ~/my.eslint.config.js file.js
Type: String (path to file)
Disables automatic lookup for eslint.config.js files.
npx eslint --no-config-lookup file.js
Opens the config inspector to visualize your configuration.
npx eslint --inspect-config
This runs @eslint/config-inspector to help you understand what your configuration is doing.
Specify additional file extensions to lint beyond the default .js, .mjs, and .cjs.
npx eslint . --ext .ts
npx eslint . --ext .ts --ext .tsx
npx eslint . --ext .ts,.tsx
Type: String or Array Default: .js, .mjs, .cjs
Define global variables so they are not flagged as undefined by the no-undef rule.
npx eslint --global require,exports:true file.js
npx eslint --global require --global exports:true
Append :true to a variable name to allow writes to that global.
Specify the parser to be used by ESLint.
npx eslint --parser @typescript-eslint/parser file.ts
Default: espree
Specify parser options as key-value pairs.
echo '3 ** 4' | npx eslint --stdin --parser-options ecmaVersion:7
Format: key:value pairs

Rules and Plugins

Specify plugins to load. You can optionally omit the eslint-plugin- prefix.
npx eslint --plugin jquery file.js
npx eslint --plugin eslint-plugin-mocha file.js
You must install the plugin using npm before using this option.
Specify rules to be used. These are merged with configuration file rules.
npx eslint --rule 'quotes: [error, double]' file.js
npx eslint --rule 'guard-for-in: error' --rule 'brace-style: [error, 1tbs]' file.js
npx eslint --rule 'jquery/dollar-sign: error' file.js
Format: Uses levn format
Combine with --no-config-lookup to only apply command line rules.

Fix Problems

Automatically fix problems. Fixes are made to the actual files.
npx eslint --fix file.js
  • This option throws an error when code is piped to ESLint
  • Not all problems are fixable
  • Has no effect on code that uses a processor (unless the processor opts in)
Fix problems without saving changes to the file system.
getSomeText | npx eslint --stdin --fix-dry-run --format json
Useful for editor integrations that need to autofix text without saving.
Specify the types of fixes to apply.
npx eslint --fix --fix-type suggestion .
npx eslint --fix --fix-type suggestion --fix-type problem .
npx eslint --fix --fix-type suggestion,layout .
Options:
  • problem - fix potential errors in the code
  • suggestion - apply fixes that improve code
  • layout - apply fixes that don’t change the AST
  • directive - apply fixes to inline directives

Ignore Files

Disables excluding files from --ignore-pattern and the ignores configuration property.
npx eslint --no-ignore file.js
Specify patterns of files to ignore (uses minimatch syntax).
npx eslint --ignore-pattern "/lib/" --ignore-pattern "/src/vendor/*" .
Quote your patterns to avoid shell interpretation of glob patterns.

Input/Output

Lint code provided on STDIN instead of from files.
cat myFile.js | npx eslint --stdin
Specify a filename to process STDIN as.
cat myFile.js | npx eslint --stdin --stdin-filename myfile.js
Useful when processing files from STDIN and you have rules that depend on the filename.
Write the output to a specified file.
npx eslint -o ./test/test.html
Specify the output format for the console.
npx eslint --format json file.js
npx eslint -f ./customformat.js file.js
npx eslint -f pretty file.js
Built-in formatters:
  • stylish (default)
  • json
  • json-with-metadata
  • html
Force enabling or disabling of colorized output.
npx eslint --color file.js | cat
npx eslint --no-color file.js

Handle Warnings

Report errors only - disables reporting on warnings.
npx eslint --quiet file.js
Only rules set to error will be run; rules set to warn are disabled.
Specify a warning threshold to force ESLint to exit with an error status.
npx eslint --max-warnings 10 file.js
Type: Integer Default: -1 (unlimited)
When used with --quiet, rules marked as warn still run but are not reported.

Caching

Only check changed files. Dramatically improves performance by storing info about processed files.
npx eslint --cache file.js
Default cache location: .eslintcache
Autofixed files are not placed in the cache. Subsequent linting that doesn’t trigger an autofix will place it in the cache.
Specify the path to the cache file or directory.
npx eslint "src/**/*.js" --cache --cache-location "/Users/user/.eslintcache/"
Add a trailing / on *nix systems or \ on Windows if specifying a directory.
Strategy for detecting changed files in the cache.
npx eslint "src/**/*.js" --cache --cache-strategy content
Options:
  • metadata (default) - uses file modification time
  • content - uses file content hash
Use content strategy for git operations where modification time changes but content doesn’t.

Miscellaneous

Run config initialization wizard.
npx eslint --init
Runs npm init @eslint/config to help create an eslint.config.js file.
Output debugging information to the console.
npx eslint --debug test.js
Useful when you’re seeing a problem and having a hard time pinpointing it.
Output the help menu.
npx eslint --help
Output the current ESLint version.
npx eslint --version
Add detailed performance statistics to the lint results.
npx eslint --stats --format json file.js
Includes parse, fix, and lint times per rule.
Output execution environment information.
npx eslint --env-info
Displays Node.js, npm, and ESLint version information.
Control the number of worker threads used to lint files.
npx eslint --concurrency auto
npx eslint --concurrency 4
Options:
  • off (default) - lint in main thread
  • auto - determine best setting automatically
  • <number> - specific number of threads

Exit Codes

When linting files, ESLint exits with one of the following exit codes:

Exit Code 0

Linting successful with no errors. Warnings are at most equal to --max-warnings value.

Exit Code 1

Linting successful but at least one error found, or warnings exceed --max-warnings.

Exit Code 2

Linting unsuccessful due to configuration problem or internal error.

Examples

# Lint all JavaScript files in the current directory
npx eslint .

# Lint specific files
npx eslint file1.js file2.js

# Lint with a specific config
npx eslint -c my-config.js src/

Configuration

Learn how to configure ESLint using eslint.config.js

Formatters

Explore different output format options

Ignoring Code

Learn how to ignore files and patterns

Core Concepts

Understand ESLint fundamentals