ESLint: JavaScript & TypeScript Static Code Analysis
Complete guide to the ESLint VS Code extension, flat config (eslint.config.js), auto-fixing on save, rules, and integration with TypeScript.
What It Does
The ESLint extension (dbaeumer.vscode-eslint) integrates the ESLint static analysis engine into VS Code, highlighting syntax errors, code smells, bad practices, and security vulnerabilities directly in the code editor as you type.
Why Use It
- Catches Bugs Early: Identifies unhandled promises, undefined variables, missing React Hook dependencies, and type mismatches before runtime.
- Auto-Fix on Save: Automatically fixes autofixable violations (e.g. removing unused imports or adding missing
constdeclarations) every time you save. - Team Standardization: Enforces shared engineering standards across teams.
Installation
- VS Code Marketplace: Search for
dbaeumer.vscode-eslintand click Install. - CLI:
code --install-extension dbaeumer.vscode-eslint
Configuration
1. VS Code Settings (.vscode/settings.json)
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}2. ESLint Flat Config (eslint.config.mjs / eslint.config.js)
import js from "@eslint/js";
import tseslint from "typescript-eslint";
import reactHooks from "eslint-plugin-react-hooks";
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
"react-hooks": reactHooks,
},
rules: {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
},
}
);Use Cases & Examples
Catching Missing React Hook Dependencies
If you reference a state variable inside useEffect without adding it to the dependency array:
useEffect(() => {
fetchUserData(userId); // Warning: React Hook useEffect has a missing dependency: 'userId'
}, []);Hovering over the squiggly line and pressing Cmd/Ctrl + . allows ESLint to automatically insert userId into the array!
Alternatives
- Biome: Rust-powered linter; significantly faster execution but with a smaller ecosystem of custom community plugins.
- Oxllint: High-speed linter focused on catching JavaScript/TypeScript bugs with zero configuration.
Performance & Security Considerations
- Type-Aware Linting Performance: Rules requiring type-checking (
@typescript-eslint/recommended-type-checked) parse full TypeScript ASTs and can slow down large monorepos. Keep type-aware rules enabled for CI and run lighter linting inside the editor. - Workspace Trust: Only enable the ESLint extension on trusted workspaces, as ESLint executes arbitrary JavaScript plugins bundled in
node_modules.
Related Guides
Prettier: Opinionated Code Formatter
Complete guide to the Prettier VS Code extension, configuration (.prettierrc), format on save, Tailwind CSS plugin sorting, and avoiding ESLint conflicts.
GitLens: Git Supercharged
Complete guide to the GitLens VS Code extension, inline blame annotations, visual commit graph, file history revisions, and branch comparisons.