Disable default-case ESLint rule for type-checked TypeScript files#94316
Merged
Conversation
Contributor
Tests PassedCommit: a568bca |
Contributor
Stats cancelledCommit: a568bca |
`@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.
default-case ESLint rule for TypeScript filesdefault-case ESLint rule for type-checked TypeScript files
a43a425 to
a568bca
Compare
timneutkens
approved these changes
Jun 2, 2026
eps1lon
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@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
requireDefaultForNonUnionoption so that switches on plain types such asstringornumberstill require a default, preserving the coverage thatdefault-casepreviously gave us. We scope thedefault-case: offoverride to exactly the files where the type-checked rule runs — the samefilesandignoresas the switch-exhaustiveness check — and cross-reference the two config blocks so the globs stay in sync. That waydefault-casestays enabled for JavaScript files,.mtsfiles, and the directories the type-checked config skips, so no switch is left unchecked.The two
// eslint-disable-next-line default-casedirectives inpostcss-loaderandhead.tsxare no longer the right escape hatch: withrequireDefaultForNonUnionthe 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 explicitdefaultcase instead, which both rules accept and which makes the previously implicit fall-through behavior explicit.