ESLint provides a comprehensive command-line interface for linting JavaScript files and projects. The CLI supports numerous options for configuration, output formatting, and behavior customization.
# Lint specific files
eslint file1.js file2.js
# Lint with glob patterns
eslint "src/**/*.js"
# Lint and fix issues automatically
eslint --fix "src/**/*.js"
# Use specific configuration file
eslint --config .eslintrc.json "src/**/*.js"Configuration and behavior control options.
# Configuration
--config <path> # Use specific config file
--no-config-lookup # Disable config file discovery
--env <environment> # Enable specific environments
# File Discovery
--ext <extensions> # Specify file extensions (default: .js)
--ignore-path <path> # Use specific ignore file
--no-ignore # Disable .eslintignore and ignore patterns
# Output Control
--format <formatter> # Output format (default: stylish)
--output-file <path> # Write output to file instead of stdout
--quiet # Report errors only (no warnings)
--max-warnings <count> # Exit with error if warnings exceed countAutomatic code fixing and problem resolution.
# Fixing
--fix # Automatically fix problems
--fix-dry-run # Show fixes without applying them
--fix-type <types> # Apply fixes for specific problem types
# Fix types: directive, problem, suggestion, layout
--fix-type problem # Fix only problem-type issues
--fix-type problem,suggestion # Fix multiple typesOptions for improving performance and caching results.
# Caching
--cache # Enable result caching
--cache-file <path> # Cache file location (default: .eslintcache)
--cache-strategy <strategy> # Cache strategy: metadata or content
# Performance
--concurrency <number> # Max concurrent linting processes (default: auto)Built-in and custom output formatters.
# Built-in formatters
eslint --format stylish file.js # Default human-readable format
eslint --format compact file.js # Compact format
eslint --format json file.js # JSON format
eslint --format junit file.js # JUnit XML format
eslint --format checkstyle file.js # Checkstyle XML format
eslint --format tap file.js # TAP format
eslint --format unix file.js # Unix format
eslint --format visualstudio file.js # Visual Studio format
eslint --format table file.js # Table format
# Custom formatter
eslint --format ./custom-formatter.js file.js
eslint --format @company/eslint-formatter file.jsOptions for troubleshooting and getting information.
# Information
--version # Show version number
--help # Show help information
--env-info # Show environment information
# Debugging
--debug # Enable debug mode
--print-config <file> # Print resolved configuration for fileSpecial-purpose commands and operations.
# Initialization
eslint --init # Initialize ESLint configuration (uses @eslint/create-config)
# Configuration inspection
eslint --print-config src/index.js # Show resolved config for file
# Statistics
eslint --stats src/**/*.js # Show performance statistics
# Experimental features
eslint --flag <flag> src/**/*.js # Enable experimental featuresESLint uses specific exit codes to indicate different conditions.
# Exit codes
0 # No errors found
1 # One or more errors found
2 # Configuration or setup error# Lint all JavaScript files in src directory
eslint src/
# Lint specific file types
eslint --ext .js,.jsx,.ts,.tsx src/
# Lint with specific configuration
eslint --config eslint.config.js src/# Fix all auto-fixable problems
eslint --fix src/
# Preview fixes without applying
eslint --fix-dry-run src/
# Fix only specific types of problems
eslint --fix --fix-type problem,suggestion src/
# Fix and show what was fixed
eslint --fix --format=@eslint/eslintrc src/# Save results to file
eslint --format json --output-file results.json src/
# Quiet mode (errors only)
eslint --quiet src/
# Fail on warnings
eslint --max-warnings 0 src/
# Multiple output formats
eslint --format stylish src/ > report.txt
eslint --format json src/ > report.json# Enable caching for faster subsequent runs
eslint --cache src/
# Custom cache location
eslint --cache --cache-file .eslintcache-custom src/
# Control concurrency
eslint --concurrency 4 src/
# Use content-based caching
eslint --cache --cache-strategy content src/# Use specific config file
eslint --config .eslintrc.production.json src/
# Disable config file lookup
eslint --no-config-lookup --config inline-config.json src/
# Print effective configuration
eslint --print-config src/index.js
# Show environment info for debugging
eslint --env-info# Lint stdin
echo "var x = 1;" | eslint --stdin --stdin-filename virtual.js
# Ignore specific patterns
eslint --ignore-pattern "build/**" --ignore-pattern "*.min.js" src/
# Multiple configurations
eslint --config base.config.js --config override.config.js src/
# Debug mode with verbose output
eslint --debug src/ 2> debug.log{
"scripts": {
"lint": "eslint src/",
"lint:fix": "eslint --fix src/",
"lint:check": "eslint --max-warnings 0 src/",
"lint:report": "eslint --format json --output-file eslint-report.json src/"
}
}# GitHub Actions / CI environments
eslint --format=@microsoft/eslint-formatter-sarif --output-file eslint-results.sarif src/
# Jenkins integration
eslint --format checkstyle --output-file checkstyle-result.xml src/
# Fail fast in CI
eslint --max-warnings 0 --format compact src/# Git pre-commit hook
#!/bin/sh
npx eslint --fix $(git diff --cached --name-only --diff-filter=ACM | grep '\.js$')
# Lint-staged integration
npx lint-stagedESLint searches for configuration files in the following order:
eslint.config.js (flat config, recommended)eslint.config.mjseslint.config.cjs.eslintrc.js (legacy).eslintrc.cjs (legacy).eslintrc.yaml (legacy).eslintrc.yml (legacy).eslintrc.json (legacy)package.json with eslintConfig property (legacy)# Disable configuration file lookup
ESLINT_USE_FLAT_CONFIG=true eslint src/
# Custom cache directory
ESLINT_CACHE_DIR=/tmp/eslint-cache eslint --cache src/
# Debug mode
DEBUG=eslint:* eslint src/