Running ESLint from the Command Line
What you'll learn: How to execute ESLint against your JavaScript files using terminal commands and interpret the results.
Now that ESLint is installed in your project, it's time to actually use it. Running ESLint from the command line is like sending an inspector through your codebase—you point it at files or directories, and it reports back what it finds.
Basic Execution
The simplest command checks a single file:
npx eslint myfile.js
To check an entire directory (and all its subdirectories):
npx eslint src/
You can check multiple targets at once:
npx eslint file1.js file2.js utils/
Understanding the Output
ESLint prints problems directly to your terminal. Each issue shows:
- The file and line number
- The severity (warning or error)
- The rule that was violated
- A brief description
Think of it like a spell-checker underlining mistakes—ESLint tells you where and what the problem is.
Useful CLI Flags
--fix automatically corrects fixable issues:
npx eslint src/ --fix
--format changes output style (e.g., json, html, stylish):
npx eslint src/ --format json
--quiet suppresses warnings, showing only errors:
npx eslint src/ --quiet
Exit Codes
ESLint exits with code 0 if no errors were found (warnings don't count), and 1 if errors exist. This makes it perfect for CI/CD pipelines that need pass/fail checks.
Key Takeaway: Running ESLint from the command line lets you inspect files and directories for code quality issues, with flags like --fix for auto-correction and various output formats for different use cases.