What Is ESLint and Why Does Linting Matter?
Learn what ESLint is, how AST-based linting catches bugs, and why teams enforce it via CI and pre-commit hooks.
Expected Interview Answer
ESLint is a static-analysis tool that parses JavaScript/TypeScript source into an abstract syntax tree and applies configurable rules to flag bugs, style inconsistencies, and anti-patterns before code ever runs.
ESLint works by parsing each file into an AST, then walking that tree with a set of rule plugins that inspect specific node patterns β an unused variable, a missing dependency in a React hook, a loose equality check β and report violations with file and line context. Rules are grouped into shareable configs (like `eslint:recommended` or `airbnb`) so teams can adopt a consistent baseline instead of hand-picking every rule, and `--fix` can auto-correct many mechanical violations like spacing or import ordering. Because it runs entirely on the syntax tree without executing code, ESLint catches classes of bugs unit tests often miss, such as unreachable code, accidental global variables, or unhandled promise rejections. Teams typically wire it into a pre-commit hook and CI pipeline so violations are caught locally and block merges before they reach production.
- Catches bugs statically before code ever executes
- Enforces a consistent style across a team without manual review nagging
- Auto-fixes many mechanical violations via --fix
- Integrates into pre-commit hooks and CI to block bad code early
AI Mentor Explanation
ESLint is like a match referee who reviews the teamβs playing eleven and equipment against the rulebook before the toss, flagging an illegal bat or an unregistered player. The referee does not play the match; they inspect the setup against a fixed set of regulations and reject anything non-compliant. Some issues, like a jersey number mismatch, get corrected on the spot automatically. That inspect-against-rules-before-play process is exactly what ESLint does to source code before it ever runs.
Step-by-Step Explanation
Step 1
Parse source into an AST
ESLint uses a parser (Espree, or @typescript-eslint for TS) to turn each file into an abstract syntax tree.
Step 2
Walk the tree with configured rules
Each active rule visits specific node types (e.g. VariableDeclarator, CallExpression) and inspects them.
Step 3
Report or auto-fix violations
Violations are reported with file/line context; fixable rules apply corrections when run with --fix.
Step 4
Enforce via CI/pre-commit
The lint command runs in CI and pre-commit hooks so violations block merges before reaching production.
What Interviewer Expects
- Understanding that ESLint performs static AST analysis, not runtime checks
- Ability to distinguish linting from formatting (Prettier) and type-checking (TypeScript)
- Awareness of shareable configs and plugin rule sets
- Mention of CI/pre-commit integration to enforce standards automatically
Common Mistakes
- Confusing ESLint (code-quality/bug rules) with Prettier (pure formatting)
- Assuming linting catches all bugs, ignoring that it cannot verify runtime behavior
- Not knowing that --fix only resolves mechanically fixable rules
- Forgetting to explain why CI enforcement matters more than local-only linting
Best Answer (HR Friendly)
βESLint is a tool that automatically reads through JavaScript code and flags problems β things like unused variables, risky patterns, or inconsistent style β before the code is even run. It helps a team catch mistakes early and keep the codebase consistent without someone manually reviewing every line for style issues.β
Code Example
import js from '@eslint/js'
export default [
js.configs.recommended,
{
rules: {
'no-unused-vars': 'error',
'eqeqeq': ['error', 'always'],
'no-console': 'warn',
},
},
]
// Run: npx eslint src/ --fixFollow-up Questions
- How does ESLint differ from Prettier and from TypeScript type-checking?
- What is the difference between a warning and an error severity in ESLint?
- How would you set up a pre-commit hook to run ESLint automatically?
- What is a shareable config and why would a team adopt one instead of custom rules?
MCQ Practice
1. What does ESLint primarily analyze to find issues?
ESLint parses code into an AST and applies rules to that static tree structure.
2. What does the --fix flag do?
--fix rewrites code for rules that support automatic correction, like spacing or quote style.
3. How does ESLint differ from Prettier?
ESLint targets logical issues and style rules; Prettier is an opinionated formatter with no logic checks.
Flash Cards
What does ESLint analyze? β The abstract syntax tree of JavaScript/TypeScript source files.
What does --fix do? β Auto-applies corrections for mechanically fixable rule violations.
ESLint vs Prettier? β ESLint checks code quality/bugs; Prettier only formats style.
Where should linting run to be effective? β Locally in pre-commit hooks and again in CI to block bad merges.