ESLint — what a linter catches that tsc does not¶
Level: 201 · for readers whose code already passes tsc --strict
Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.
One line: tsc --strict exits 0 on a promise nobody awaits, an assignment inside if, a map callback that returns nothing and a variable never read — all type-correct — and ESLint rules such as no-floating-promises and no-cond-assign exist to reject exactly these.
Keywords: ESLint, eslint.config.js, typescript-eslint, no-floating-promises, no-cond-assign
What the finished page will answer¶
- Which of a floating promise,
if (count = n), amapcallback withoutreturnand an unused variable doestsc --strictreport, and which does ESLint report? - What happens at run time to the promise nobody awaited when it rejects?
- Why does
no-floating-promisesneed type information, and what doesparserOptions.projectServicegive it? - Which of these rules does
js.configs.recommendedturn on, and which must be added by hand? - What does
// eslint-disable-next-linesilence, and how doesreportUnusedDisableDirectivesfind stale ones?
Examples it will need¶
-
linting_what_tsc_accepts_sh.sh— tsc --strict's exit status 0 on a file with a floating promise, an assignment in if, a map callback without return and an unused variable -
linting_floating_promise_at_run_time_sh.sh— the same floating promise run by node: the unhandled rejection on stderr and exit status 1 -
linting_eslint_reports_sh.sh— ESLint's report on the same file with js.configs.recommended and typescript-eslint's recommendedTypeChecked, one line per rule
See also¶
- Unhandled errors — what the floating promise does when it rejects
===and==— the==thateqeqeqforbidsmap,filter,reduceand friends — why amapcallback must return- Prettier — layout, which a linter should leave to the formatter
- Rust: Strict clippy: denying the panic, and the arithmetic that comes with it ↗ — clippy, Rust's linter, set to deny