Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): [switch-exhaustiveness-check] add requireDefaultForNonUnion option#7880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JoshuaKGoldberg merged 9 commits intotypescript-eslint:mainfromST-DDT:rule/switch-exhaustiveness-check/requireDefaultForNonUnion
Nov 19, 2023
Merged

feat(eslint-plugin): [switch-exhaustiveness-check] add requireDefaultForNonUnion option#7880

JoshuaKGoldberg merged 9 commits intotypescript-eslint:mainfromST-DDT:rule/switch-exhaustiveness-check/requireDefaultForNonUnion
Nov 19, 2023

Conversation

ST-DDT
Copy link
Contributor

@ST-DDTST-DDT commentedNov 4, 2023
edited
Loading

PR Checklist

Overview

This PR adds therequireDefaultForNonUnion option to theswitch-exhaustiveness-check rule.
If enabled, all switches on non-union types require a default case to ensure they are "exhaustive".
The rule is disabled by default, although I would recommend changing this in a future major release, because why would you not want all of your switch cases to be exhaustive.

The rule already has the check for union types so it was easy to use the else branch to add the check for the default case.

constvalue:number=Math.floor(Math.random()*3);switch(value){case0:return0;case1:return1;}

->

constvalue:number=Math.floor(Math.random()*3);switch(value){case0:return0;case1:return1;default:{thrownewError('default case')}}

This cannot be achieved with thedefault-case rule, because that also requires the default case for union types which would hide the potential errors caused by extending the union with another case.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@ST-DDT!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint.

@netlifyNetlify
Copy link

netlifybot commentedNov 4, 2023
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit9a8ae4c
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/655a1fdfe30cfc0008def515
😎 Deploy Previewhttps://deploy-preview-7880--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 90 (🔴 down 8 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@ST-DDTST-DDT changed the titlerule(switch-exhaustiveness-check): add requireDefaultForNonUnion optionfeat(switch-exhaustiveness-check): add requireDefaultForNonUnion optionNov 4, 2023
@ST-DDTST-DDT changed the titlefeat(switch-exhaustiveness-check): add requireDefaultForNonUnion optionfeat: add requireDefaultForNonUnion option to switch-exhaustiveness-checkNov 4, 2023
@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedNov 4, 2023
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit7b77360. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 19 targets

Sent with 💌 fromNxCloud.

@bradzacherbradzacher changed the titlefeat: add requireDefaultForNonUnion option to switch-exhaustiveness-checkfeat(eslint-plugin): [switch-exhaustiveness-check] add requireDefaultForNonUnion optionNov 10, 2023
@bradzacherbradzacher added the enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule labelNov 10, 2023
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesNov 11, 2023
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, thanks! Just a little bit of nitpicking left - if you don't like the suggestions or don't have a chance to address them, no worries. We can merge roughly as-is.

@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelNov 11, 2023
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesNov 19, 2023
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

✨ swell, thanks!

@JoshuaKGoldberg
Copy link
Member

Ah, merge conflicts. I'll take care of them and merge.

@JoshuaKGoldberg
Copy link
Member

Integration test failures are unrelated.5dbf622

@JoshuaKGoldbergJoshuaKGoldberg merged commit4cfcd45 intotypescript-eslint:mainNov 19, 2023
@ST-DDTST-DDT deleted the rule/switch-exhaustiveness-check/requireDefaultForNonUnion branchNovember 19, 2023 22:54
@ArnaudBarre
Copy link
Contributor

Thank you very much for this! Love this <3

But more me this more close to the bug fix, this option should not exist and always be enabled. I don't think anyone choosing to enable this rule will be agaisnt having this check that really catch bugs or shows a missing union in your types

ST-DDT and acidoxee reacted with thumbs up emojiJoshuaKGoldberg reacted with laugh emojiST-DDT reacted with heart emoji

@ST-DDT
Copy link
ContributorAuthor

@ArnaudBarre Should we create a new issue for that?

@JoshuaKGoldberg
Copy link
Member

That would be the general right practice, yes 🙂. But I can tell you right now that this rule is far opinionated to not have this as an option. As a user of it I wouldmaybe only ever use it for unions. It'd be quite restrictive to have it apply toallswitch statements. Sometimes you really just want toswitch over a few values! It's IMO not our place as a linter to tell people not to use a totally valid pattern of code like that.

I'm not saying this to shut your ideas down. If you feel strongly that I'm wrong here and we should discuss in an issue, then absolutely let's continue the conversation there. We can always discuss there, and even if it's not immediately accepted we can always put theevaluating community engagement label on it. Just posting now as a warning before you go through the effort of filing an issue. 😄

ST-DDT reacted with thumbs up emoji

@ST-DDT
Copy link
ContributorAuthor

Vylpes pushed a commit to Vylpes/random-bunny that referenced this pull requestNov 27, 2023
This PR contains the following updates:| Package | Type | Update | Change ||---|---|---|---|| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`6.8.0` -> `6.12.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/6.8.0/6.12.0) |---### Release Notes<details><summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>### [`v6.12.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#6120-2023-11-20)[Compare Source](typescript-eslint/typescript-eslint@v6.11.0...v6.12.0)##### Bug Fixes-   **eslint-plugin:** \[class-methods-use-this] detect a problematic case for private/protected members if `ignoreClassesThatImplementAnInterface` is set ([#&#8203;7705](typescript-eslint/typescript-eslint#7705)) ([155aa1f](typescript-eslint/typescript-eslint@155aa1f))-   **eslint-plugin:** \[no-unnecessary-condition] fix false positive with computed member access and branded key type ([#&#8203;7706](typescript-eslint/typescript-eslint#7706)) ([f151b26](typescript-eslint/typescript-eslint@f151b26))-   **eslint-plugin:** \[switch-exhaustiveness-check] enum members with new line or single quotes are not being fixed correctly ([#&#8203;7806](typescript-eslint/typescript-eslint#7806)) ([a034d0a](typescript-eslint/typescript-eslint@a034d0a)), closes [#&#8203;7768](typescript-eslint/typescript-eslint#7768)##### Features-   \[member-ordering] add accessor support for member-ordering ([#&#8203;7927](typescript-eslint/typescript-eslint#7927)) ([3c8312d](typescript-eslint/typescript-eslint@3c8312d))-   **eslint-plugin:** \[switch-exhaustiveness-check] add requireDefaultForNonUnion option ([#&#8203;7880](typescript-eslint/typescript-eslint#7880)) ([4cfcd45](typescript-eslint/typescript-eslint@4cfcd45))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.### [`v6.11.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#6110-2023-11-13)[Compare Source](typescript-eslint/typescript-eslint@v6.10.0...v6.11.0)##### Bug Fixes-   **eslint-plugin:** \[explicit-function-return-type] support JSX attributes in `allowTypedFunctionExpressions` ([#&#8203;7553](typescript-eslint/typescript-eslint#7553)) ([be2777c](typescript-eslint/typescript-eslint@be2777c))-   **eslint-plugin:** \[no-unnecessary-qualifier] handle nested namespace id ([#&#8203;7883](typescript-eslint/typescript-eslint#7883)) ([a668f5b](typescript-eslint/typescript-eslint@a668f5b))##### Features-   add `no-unsafe-unary-minus` rule ([#&#8203;7390](typescript-eslint/typescript-eslint#7390)) ([c4709c2](typescript-eslint/typescript-eslint@c4709c2))-   add types for flat config files ([#&#8203;7273](typescript-eslint/typescript-eslint#7273)) ([66cd0c0](typescript-eslint/typescript-eslint@66cd0c0))-   allow typescript@5.3.0-RC as devDependency ([#&#8203;7821](typescript-eslint/typescript-eslint#7821)) ([b6c40b4](typescript-eslint/typescript-eslint@b6c40b4))-   **eslint-plugin:** no-unsafe-enum-comparison handles switch cases ([#&#8203;7898](typescript-eslint/typescript-eslint#7898)) ([72cb9e4](typescript-eslint/typescript-eslint@72cb9e4))-   **utils:** add ESLint `CodePath` selector types ([#&#8203;7551](typescript-eslint/typescript-eslint#7551)) ([99a026f](typescript-eslint/typescript-eslint@99a026f))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.### [`v6.10.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#6100-2023-11-06)[Compare Source](typescript-eslint/typescript-eslint@v6.9.1...v6.10.0)##### Bug Fixes-   **eslint-plugin:** \[no-unused-vars] handle logical assignment ([#&#8203;7854](typescript-eslint/typescript-eslint#7854)) ([11e57c5](typescript-eslint/typescript-eslint@11e57c5))-   **eslint-plugin:** \[require-await] add support for "await using" ([#&#8203;7866](typescript-eslint/typescript-eslint#7866)) ([855abea](typescript-eslint/typescript-eslint@855abea))##### Features-   **eslint-plugin:** \[ban-ts-comments] suggest ts-expect-error over ts-ignore ([#&#8203;7849](typescript-eslint/typescript-eslint#7849)) ([5e73a48](typescript-eslint/typescript-eslint@5e73a48))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.#### [6.9.1](typescript-eslint/typescript-eslint@v6.9.0...v6.9.1) (2023-10-30)##### Bug Fixes-   **eslint-plugin:** \[naming-convention] allow PascalCase for imports ([#&#8203;7841](typescript-eslint/typescript-eslint#7841)) ([7ad86ee](typescript-eslint/typescript-eslint@7ad86ee))-   **eslint-plugin:** \[no-unused-expressions] handle TSInstantiationExpression expression ([#&#8203;7831](typescript-eslint/typescript-eslint#7831)) ([31988e0](typescript-eslint/typescript-eslint@31988e0))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.### [`v6.9.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#691-2023-10-30)[Compare Source](typescript-eslint/typescript-eslint@v6.9.0...v6.9.1)##### Bug Fixes-   **eslint-plugin:** \[naming-convention] allow PascalCase for imports ([#&#8203;7841](typescript-eslint/typescript-eslint#7841)) ([7ad86ee](typescript-eslint/typescript-eslint@7ad86ee))-   **eslint-plugin:** \[no-unused-expressions] handle TSInstantiationExpression expression ([#&#8203;7831](typescript-eslint/typescript-eslint#7831)) ([31988e0](typescript-eslint/typescript-eslint@31988e0))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.### [`v6.9.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#690-2023-10-23)[Compare Source](typescript-eslint/typescript-eslint@v6.8.0...v6.9.0)##### Bug Fixes-   **eslint-plugin:** \[no-confusing-void-expression] handle unfixable cases ([#&#8203;7674](typescript-eslint/typescript-eslint#7674)) ([7e52f27](typescript-eslint/typescript-eslint@7e52f27))-   **eslint-plugin:** \[no-unsafe-return] allow returning anything if explicitly returning any ([#&#8203;7708](typescript-eslint/typescript-eslint#7708)) ([c6124b2](typescript-eslint/typescript-eslint@c6124b2))##### Features-   **eslint-plugin:** \[max-params] don't count `this: void` parameter ([#&#8203;7696](typescript-eslint/typescript-eslint#7696)) ([6398d3f](typescript-eslint/typescript-eslint@6398d3f)), closes [#&#8203;7538](typescript-eslint/typescript-eslint#7538)-   **eslint-plugin:** \[naming-convention] add support for default and namespace imports ([#&#8203;7269](typescript-eslint/typescript-eslint#7269)) ([bb15aae](typescript-eslint/typescript-eslint@bb15aae))-   **eslint-plugin:** \[no-restricted-imports] support import = require ([#&#8203;7709](typescript-eslint/typescript-eslint#7709)) ([4c8edcf](typescript-eslint/typescript-eslint@4c8edcf))-   **eslint-plugin:** \[no-unsafe-enum-comparison] add switch suggestion ([#&#8203;7691](typescript-eslint/typescript-eslint#7691)) ([53d5263](typescript-eslint/typescript-eslint@53d5263)), closes [#&#8203;7643](typescript-eslint/typescript-eslint#7643)-   **eslint-plugin:** \[prefer-readonly] private fields support ([#&#8203;7686](typescript-eslint/typescript-eslint#7686)) ([0e875bf](typescript-eslint/typescript-eslint@0e875bf))You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.</details>---### Configuration📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.🔕 **Ignore**: Close this PR and you won't be reminded about this update again.--- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box---This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->Reviewed-on:https://gitea.vylpes.xyz/RabbitLabs/random-bunny/pulls/107Reviewed-by: Vylpes <ethan@vylpes.com>Co-authored-by: Renovate Bot <renovate@vylpes.com>Co-committed-by: Renovate Bot <renovate@vylpes.com>
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsNov 28, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we mergeenhancement: plugin rule optionNew rule option for an existing eslint-plugin rule
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[switch-exhaustiveness-check] Require default case if discriminant type is not a union
4 participants
@ST-DDT@JoshuaKGoldberg@ArnaudBarre@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp