Course contentsShow
← Web Development
Lesson 1435 of 2,98226. Code Quality ToolsFree lesson

Running ESLint and Fixing Issues

Using ESLint CLI commands, --fix flag, and integrating with npm scripts for automated checks.

Running ESLint and Fixing Issues

You'll learn how to execute ESLint from the command line, automatically fix problems, and integrate linting into your development workflow.

Now that you've configured ESLint, it's time to actually run it and clean up your code. Think of this like running a spell-checker on a document—you need to execute the check, review the issues, and decide which ones to fix automatically versus manually.

Basic ESLint CLI Commands

The simplest way to run ESLint is through the command line:

npx eslint yourfile.js

To check multiple files or entire directories:

npx eslint src/
npx eslint "src/**/*.js"

This scans your code and reports all violations based on your configured rules.

The --fix Flag

Many ESLint issues can be automatically corrected. The --fix flag tells ESLint to fix everything it safely can:

npx eslint src/ --fix

This handles formatting issues, missing semicolons, quote style inconsistencies, and other mechanical fixes. Complex logic issues still require manual intervention.

Integrating with npm Scripts

Rather than typing long commands repeatedly, add ESLint to your package.json scripts:

{
  "scripts": {
    "lint": "eslint src/",
    "lint:fix": "eslint src/ --fix"
  }
}

Now you can simply run:

npm run lint
npm run lint:fix

This makes linting accessible to your entire team and integrates seamlessly with CI/CD pipelines. You can even add a pre-commit hook to run linting before every Git commit.

Key Takeaway: Use eslint with the --fix flag for automatic corrections, and integrate linting commands into npm scripts to make code quality checks a standard part of your workflow.