JavaScript can allow a mistake to survive until code runs. ESLint checks code without running it, applying configurable rules that catch likely errors or enforce a project’s coding conventions. It complements TypeScript’s type checking and tests rather than replacing either. section 2.0 section 2.2
Rules range from no-unreachable, which flags code after a return, to library-specific checks such as react/no-deprecated. Style rules can enforce team preferences; some can automatically fix code instead of merely reporting an error. Prettier has a different primary job: formatting details such as line breaks and indentation. section 1.3.2 section 2.4
Listing 2.11 Shadowing a variable
const count = 10; #A
console.log("Outer count:", count);
for (let count = 0; count < 3; count++) { #B
console.log("Inner count:", count); #C
}
console.log("Outer count still:", count);
The loop’s count shadows the outer count. JavaScript permits this, but readers must track which variable each reference means. ESLint’s no-shadow rule can flag the pattern; it must be enabled separately because it is not in the recommended rule set. section 2.2.3
More rules can catch more problems and keep a team’s style cohesive, but opinionated rules can also reject valid code. For example, the typescript-eslint strict rules forbid non-null assertions even when a preceding check establishes that a value exists. You can rewrite the code, turn off the rule in the project configuration, or make a local exception. section 2.2.2
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- * The previous condition ensured that dojoStudents.get(dojoName) exists. */ dojoStudents.set(dojoName, dojoStudents.get(dojoName)! + 1);
A local eslint-disable-next-line comment makes an exception for one non-null assertion and records why the preceding condition makes it safe here. section 2.2.2
Choose rules for the mistakes and conventions that matter to your project. Type-aware rules from typescript-eslint expand what ESLint can check, though they increase linting time. section 2.2.3 section 2.4


