Lesson 12 / 25

Fixing Issues Automatically

Use --fix flag to auto-correct ESLint violations.

Auto-fix capabilities

ESLint can fix many issues automatically: semicolons, quotes, unused variables. Not all issues are auto-fixable (some need human judgment).

Running eslint --fix

Auto-fix a single file or all files in a directory.

# Fix a single file
eslint src/app.js --fix

# Fix all JS files in src/
eslint src/**/*.js --fix

# Add to package.json
"scripts": { "lint:fix": "eslint . --fix" }

Output:

Fixed issues in src/ directory

Review before committing

Always review --fix changes before committing. Some auto-fixes might not match your intent, and it's good to catch issues manually.

Quick check

Quick check: Can --fix solve all ESLint violations?

  • No, some issues require manual review.
  • Yes, it fixes everything.
  • Only for semicolon issues.
Answer

No, some issues require manual review. — --fix handles many issues but leaves complex or context-dependent problems for human judgment.