Skip to content

Disable default-case ESLint rule for type-checked TypeScript files#94316

Merged
unstubbable merged 1 commit into
canaryfrom
hl/fix-eslint-default-case
Jun 2, 2026
Merged

Disable default-case ESLint rule for type-checked TypeScript files#94316
unstubbable merged 1 commit into
canaryfrom
hl/fix-eslint-default-case

Conversation

@unstubbable
Copy link
Copy Markdown
Contributor

@unstubbable unstubbable commented Jun 1, 2026

@typescript-eslint/switch-exhaustiveness-check (enabled in eslint.cli.config.mjs) already guarantees complete switch coverage on enums and discriminated unions, so requiring an additional default case on those switches in TypeScript just forced dead branches.

We turn on its requireDefaultForNonUnion option so that switches on plain types such as string or number still require a default, preserving the coverage that default-case previously gave us. We scope the default-case: off override to exactly the files where the type-checked rule runs — the same files and ignores as the switch-exhaustiveness check — and cross-reference the two config blocks so the globs stay in sync. That way default-case stays enabled for JavaScript files, .mts files, and the directories the type-checked config skips, so no switch is left unchecked.

The two // eslint-disable-next-line default-case directives in postcss-loader and head.tsx are no longer the right escape hatch: with requireDefaultForNonUnion the exhaustiveness check now wants those switches handled, and a directive for that rule would be reported as unused under the editor config where it does not run. We give each switch an explicit default case instead, which both rules accept and which makes the previously implicit fall-through behavior explicit.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Tests Passed

Commit: a568bca

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Stats cancelled

Commit: a568bca
View workflow run

@unstubbable unstubbable marked this pull request as ready for review June 1, 2026 19:57
@unstubbable unstubbable requested review from eps1lon and removed request for eps1lon June 1, 2026 19:57
@unstubbable unstubbable marked this pull request as draft June 2, 2026 09:38
`@typescript-eslint/switch-exhaustiveness-check` (enabled in
eslint.cli.config.mjs) already guarantees complete switch coverage on
enums and discriminated unions, so requiring an additional default case
on those switches in TypeScript just forced dead branches.

We turn on its `requireDefaultForNonUnion` option so that switches on
plain types such as `string` or `number` still require a default,
preserving the coverage that `default-case` previously gave us. We scope
the `default-case: off` override to exactly the files where the
type-checked rule runs — the same `files` and `ignores` as the
switch-exhaustiveness check — and cross-reference the two config blocks
so the globs stay in sync. That way `default-case` stays enabled for
JavaScript files, `.mts` files, and the directories the type-checked
config skips, so no switch is left unchecked.

The two `// eslint-disable-next-line default-case` directives in
`postcss-loader` and `head.tsx` are no longer the right escape hatch:
with `requireDefaultForNonUnion` the exhaustiveness check now wants those
switches handled, and a directive for that rule would be reported as
unused under the editor config where it does not run. We give each
switch an explicit `default` case instead, which both rules accept and
which makes the previously implicit fall-through behavior explicit.
@unstubbable unstubbable changed the title Disable default-case ESLint rule for TypeScript files Disable default-case ESLint rule for type-checked TypeScript files Jun 2, 2026
@unstubbable unstubbable force-pushed the hl/fix-eslint-default-case branch from a43a425 to a568bca Compare June 2, 2026 10:11
@unstubbable unstubbable marked this pull request as ready for review June 2, 2026 10:14
@unstubbable unstubbable requested a review from eps1lon June 2, 2026 10:14
@unstubbable unstubbable merged commit 4fff8f4 into canary Jun 2, 2026
295 of 298 checks passed
@unstubbable unstubbable deleted the hl/fix-eslint-default-case branch June 2, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants