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

fix(eslint-plugin): [switch-exhaustiveness-check] enum members with new line or single quotes are not being fixed correctly#7806

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

Conversation

StyleShit
Copy link
Contributor

Closes#7768

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@StyleShit!

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.

@netlify
Copy link

netlifybot commentedOct 20, 2023
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit82d5b37
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/6536cd5a4249380008cbf566
😎 Deploy Previewhttps://deploy-preview-7806--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 9 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.

case Enum.a: { throw new Error('Not implemented yet: Enum.a case') }
case Enum[\`key-with

new-line\`]: { throw new Error('Not implemented yet: Enum[\`key-with\\n\\n new-line\`] case') }
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

wasn't sure about this. should we throw an error with actual new lines or\n is fine?

Choose a reason for hiding this comment

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

Yeah good question. It's such a rare case, I don't think it matters too much. But in general having error messages be on one line is easier to read.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

should we just strip out any spaces, tabs, and new lines?

OK... it might look weird in some cases... IDK

key=`key-with          new-line`error="not implemented: 'key-withnew-line'";

anyway, as you said, it's a rare case that probably isn't worth the effort

Comment on lines +104 to +107
<!--tabs-->

### ❌ Incorrect

Copy link
ContributorAuthor

@StyleShitStyleShitOct 20, 2023
edited
Loading

Choose a reason for hiding this comment

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

it's probably not displayed correctly, would be happy to get some help here regarding how we should display this (maybe add a subtitle?):

https://deploy-preview-7806--typescript-eslint.netlify.app/rules/switch-exhaustiveness-check#examples

Choose a reason for hiding this comment

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

<!-- /tabs --> is what you're looking for.

I'd also request a brief sentence before each of the examples explaining what they're for. It's kind of hard to piece together just from the code.

Vague starting proposal (just off the top of my head, not attached to this):

When theswitch doesn't have exhaustive cases, either filling them all out or adding adefault will correct the rule's complaint.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yup

@StyleShitStyleShit changed the titlefeat(eslint-plugin): [switch-exhaustiveness-check] members with new line or single quotes are not being fixed correctlyfeat(eslint-plugin): [switch-exhaustiveness-check] enum members with new line or single quotes are not being fixed correctlyOct 20, 2023
@nx-cloud
Copy link

nx-cloudbot commentedOct 20, 2023
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit82d5b37. 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.

@StyleShitStyleShit changed the titlefeat(eslint-plugin): [switch-exhaustiveness-check] enum members with new line or single quotes are not being fixed correctlyfix(eslint-plugin): [switch-exhaustiveness-check] enum members with new line or single quotes are not being fixed correctlyOct 21, 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.

Looks great to me, thanks! With the exception of the/tabs bit, this is all just small non-blocking nitpicks from me.

Hammer hammering a nail in wood. Caption: 'nailed it'

@@ -1,15 +1,15 @@
---
description: 'Require switch-case statements to be exhaustive with union type.'
description: 'Require switch-case statements to be exhaustive with union type or enum.'

Choose a reason for hiding this comment

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

[Proofreading] Existing typo with the singular/plural, heh:

Suggested change
description: 'Require switch-case statements to be exhaustive with uniontype or enum.'
description: 'Require switch-case statements to be exhaustive with uniontypes and enums.'

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done

Comment on lines +104 to +107
<!--tabs-->

### ❌ Incorrect

Choose a reason for hiding this comment

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

<!-- /tabs --> is what you're looking for.

I'd also request a brief sentence before each of the examples explaining what they're for. It's kind of hard to piece together just from the code.

Vague starting proposal (just off the top of my head, not attached to this):

When theswitch doesn't have exhaustive cases, either filling them all out or adding adefault will correct the rule's complaint.

Cherry,
}

const fruit = Fruit.Cherry as Fruit;

Choose a reason for hiding this comment

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

[Style] This is a little closer to the intent:

Suggested change
const fruit = Fruit.Cherry as Fruit;
declareconst fruit: Fruit;

(this and elsewhere)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yup, I actually wanted to do that, but followed the existing code
changed :)

case Enum.a: { throw new Error('Not implemented yet: Enum.a case') }
case Enum[\`key-with

new-line\`]: { throw new Error('Not implemented yet: Enum[\`key-with\\n\\n new-line\`] case') }

Choose a reason for hiding this comment

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

Yeah good question. It's such a rare case, I don't think it matters too much. But in general having error messages be on one line is easier to read.

}

const errorMessage = `Not implemented yet: ${caseTest} case`;
// escape single quotes and newlines, so that the error message is a readable and valid code.

Choose a reason for hiding this comment

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

Suggested change
// escape single quotes and newlines, so that the error message isareadable and valid code.
// escape single quotes and newlines, so that the error message is readable and valid code.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm gonna learn English here more than ASTs

JoshuaKGoldberg reacted with laugh emoji
@@ -17,7 +17,7 @@ export default createRule({
type: 'suggestion',
docs: {
description:
'Require switch-case statements to be exhaustive with union type',
'Require switch-case statements to be exhaustive with union type or enum',

Choose a reason for hiding this comment

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

(same existing typo-ish)

Suggested change
'Require switch-case statements to be exhaustive with uniontype orenum',
'Require switch-case statements to be exhaustive with uniontypes orenums',

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelOct 22, 2023
@StyleShit
Copy link
ContributorAuthor

StyleShit commentedOct 23, 2023
edited
Loading

Looks great to me, thanks! With the exception of the/tabs bit, this is all just small non-blocking nitpicks from me.

Hammer hammering a nail in wood. Caption: 'nailed it'

Nits are blockers for me 😄

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelOct 23, 2023
Copy link
Member

@Josh-CenaJosh-Cena left a comment

Choose a reason for hiding this comment

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

Suggested test case:

enumE{"'a' `b` \"c\""=1}declareconsta:Enum;switch(a){}

Comment on lines 75 to 79
const requiresBackticks = missingBranchName?.match(/[\r\n]/g);

caseTest = requiresBackticks
? `${symbolName}[\`${missingBranchName}\`]`
: `${symbolName}['${missingBranchName}']`;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if it's discussed yet, but if we are escaping characters in the error message anyway, I would prefer text here to also be escaped instead of wrapping in backticks. Otherwise, you would also need to deal with` in the text. (Do we even deal with' correctly?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

OK, so your suggested case breaks the code (nice catch!)
But I'm not sure that I understand what you mean in this comment, can you maybe show some pseudo code and/or cases?

Copy link
Member

@Josh-CenaJosh-CenaOct 23, 2023
edited
Loading

Choose a reason for hiding this comment

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

It means we simply outputcase '${escapedCaseTest}': { throw new Error('Not implemented yet: "${escapedCaseTest}" case') }. One consistent string literal to be used in both places. Then, you would only need to take care of',\n, and\r in your escaping logic. By the way, if you want to be pedantic, you also need to take care of\u2028 and\u2029, which are alsoline terminators.

In terms of cases, it means we output:

switch(a){case'a\nb':{thrownewError('Not implemented yet: "a\nb" case')}}

Instead of:

switch(a){case`ab`:{thrownewError('Not implemented yet: "a\nb" case')}}

I'm sure no one writes code like the latter, especially with deeper indentations.

Copy link
ContributorAuthor

@StyleShitStyleShitOct 23, 2023
edited
Loading

Choose a reason for hiding this comment

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

I'm not sure that we can use the sameescapedCaseTest variable, because we still need to re-escape It before using it in the error, right? Or am I missing something?

Copy link
ContributorAuthor

@StyleShitStyleShitOct 23, 2023
edited
Loading

Choose a reason for hiding this comment

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

Have a look atthis one

Is that what you mean?

@bradzacherbradzacher added the bugSomething isn't working labelNov 10, 2023
Copy link
Member

@Josh-CenaJosh-Cena left a comment

Choose a reason for hiding this comment

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

This looks good to me :)

@Josh-CenaJosh-Cena added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelNov 15, 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.

A guy chest shaking/dancing happily with his arms out

@JoshuaKGoldbergJoshuaKGoldberg merged commita034d0a intotypescript-eslint:mainNov 16, 2023
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsNov 24, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@Josh-CenaJosh-CenaJosh-Cena approved these changes

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 mergebugSomething isn't working
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: [switch-exhaustiveness-check] Some cases for member names are not being fixed properly
4 participants
@StyleShit@JoshuaKGoldberg@Josh-Cena@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp