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): [no-unnecessary-template-expression] handle template literal type#10612

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 12 commits intotypescript-eslint:mainfromyeonjuan:fixes/9971
Jan 27, 2025

Conversation

yeonjuan
Copy link
Contributor

@yeonjuanyeonjuan commentedJan 5, 2025
edited
Loading

PR Checklist

Overview

This pr addresses#9971.
I didn't apply all the tests written forTemplateLiterals toTemplateLiteralTypes because it shares most of its logic withTemplateLiterals.
This includes tests for basic behavior similar toTemplateLiteral and some behavior that must be handled separately forTemplateLiteralType.

typeType= `${"aa"}`;// errortypeType= `a${"aa"}`;// errortypeType= `a${"aa"/* comments */}`;;// no-error// enumenumMyEnum{A="A",B="B"}typeType= `${MyEnum}`;//  no-errortypeType= `${MyEnum.A}`;// error// TSNullKeyword & TSUndefinedKeywordtypeType= `${null}`;// errortypeType= `${undefined}`;// error

omril1 reacted with rocket emoji
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@yeonjuan!

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 commentedJan 5, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit14beb1a
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/67936bfc87b19c00089abc4e
😎 Deploy Previewhttps://deploy-preview-10612--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: 97 (🔴 down 1 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.

@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedJan 5, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commit14beb1a.

CommandStatusDurationResult
nx run-many --target=build --exclude website --...✅ Succeeded1sView ↗
nx run-many --target=clean✅ Succeeded10sView ↗

☁️Nx Cloud last updated this comment at2025-01-24 14:41:58 UTC

@yeonjuanyeonjuanforce-pushed thefixes/9971 branch 2 times, most recently frome4f963b to849fa9aCompareJanuary 5, 2025 10:39
@codecovCodecov
Copy link

codecovbot commentedJan 5, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.23%. Comparing base(31be053) to head(14beb1a).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main   #10612      +/-   ##==========================================+ Coverage   87.15%   87.23%   +0.08%==========================================  Files         448      450       +2       Lines       15576    15677     +101       Branches     4551     4589      +38     ==========================================+ Hits        13575    13676     +101  Misses       1645     1645                Partials      356      356
FlagCoverage Δ
unittest87.23% <100.00%> (+0.08%)⬆️

Flags with carried forward coverage won't be shown.Click here to find out more.

Files with missing linesCoverage Δ
...in/src/rules/no-unnecessary-template-expression.ts100.00% <100.00%> (+1.11%)⬆️

... and14 files with indirect coverage changes

@yeonjuanyeonjuan marked this pull request as ready for reviewJanuary 6, 2025 14:51
@yeonjuanyeonjuan changed the titlefix(eslint-plugin): handle expressions in template literal typefix(eslint-plugin): [no-unnecessary-template-expression] handle template literal typeJan 9, 2025
Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Well done on managing to reuse the existing code even though the AST is slightly different! And especially kudos for making it a readable git diff! (PSA to other readers - you need to have the "ignore whitespace" feature enabled in order to read this PR).

Requesting some changes but I think the overall approach is good!

JoshuaKGoldberg reacted with thumbs up emoji
@kirkwaiblingerkirkwaiblinger added the awaiting responseIssues waiting for a reply from the OP or another party labelJan 20, 2025
@@ -976,6 +976,9 @@ ruleTester.run('no-unnecessary-template-expression', rule, {
valid: [
"const string = 'a';",
'const string = `a`;',
'const string = `NaN: ${/* comment */ NaN}`;',
'const string = `undefined: ${/* comment */ undefined}`;',
'const string = `Infinity: ${Infinity /* comment */}`;',
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixes#10684

kirkwaiblinger reacted with heart emoji
@yeonjuan
Copy link
ContributorAuthor

yeonjuan commentedJan 20, 2025
edited
Loading

@kirkwaiblinger Thank you for your review. I've fixed it! 👍de4d428

Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Looking great! Couple questions, no real blockers.

@@ -51,6 +57,15 @@ const wrappedIntersection = `${intersectionWithString}`;

const ab1 = `ab`;
const ab2 = `ab`;
type AB = `AB`;

// Transforming enum members into string unions using template literals is allowed.

Choose a reason for hiding this comment

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

Just curious, what's the reasoning for this? I'm not familiar with this usage, so I'm curious for a reference on it, and not seeing one on the issue

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@kirkwaiblinger
I should have written an explanation for this, but I missed it. This is an easy way to change an enum to a union type, and the union type is not the same as the enum.

playground

enumEnum{A='A',B='B',C='C'}typeUnion= `${Enum}`;functionfoo(a:Enum){}foo("A");// ts error: Argument of type '"A"' is not assignable to parameter of type 'EnumA'.foo(Enum.A);functionbar(a:Union){}bar("A");

typescript-eslint is also using this approach.

kirkwaiblinger reacted with thumbs up emoji

Choose a reason for hiding this comment

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

Ok 👍 Seems plausible to me! I'll defer to you and other reviewers on this, thanks for the explanation!

return isStringLike(type);
}

function isEnumType(type: ts.Type): boolean {

Choose a reason for hiding this comment

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

It looks like enums have a type flagts.TypeFlags.EnumLike set. Can we just use that?

Copy link
ContributorAuthor

@yeonjuanyeonjuanJan 23, 2025
edited
Loading

Choose a reason for hiding this comment

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

@kirkwaiblinger
This function is for checking if it is an enum declaration symbol (not member).

enumEnum{A='A'}typeA= `${Enum}`;

That doesn't seem work because both enum declaration and enum members have theEnumLike flag.
Perhaps it would be better to rename the function tohasEnumDeclarationSymbol , what do you think?

Choose a reason for hiding this comment

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

Ah, gotcha. Then, I think it's good as is! If anything, a comment with example like

/** * Checks for whole enum types, i.e. `MyEnum`, and not their values, i.e. `MyEnum.A` */

might be more helpful. But fine either way!

yeonjuan reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sounds good, I've added the comment.14beb1a

kirkwaiblinger
kirkwaiblinger previously approved these changesJan 23, 2025
Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

Great work!!

@typescript-eslint/triage-team Looking for a second review on this since it's tricky stuff!

@kirkwaiblingerkirkwaiblinger removed the awaiting responseIssues waiting for a reply from the OP or another party labelJan 23, 2025
@kirkwaiblingerkirkwaiblinger requested a review froma teamJanuary 23, 2025 17:29
@kirkwaiblingerkirkwaiblinger added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJan 24, 2025
@kirkwaiblingerkirkwaiblinger requested a review froma teamJanuary 24, 2025 14:40
@github-actionsgithub-actionsbot removed the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJan 24, 2025
@kirkwaiblingerkirkwaiblinger added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJan 24, 2025
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.

Napolean Dynamite emphatically muttering 'SWEET!'

@JoshuaKGoldbergJoshuaKGoldberg merged commitf1e9a5d intotypescript-eslint:mainJan 27, 2025
65 of 67 checks passed
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestJan 29, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.21.0 | 8.22.0 || npm        | @typescript-eslint/parser        | 8.21.0 | 8.22.0 |## [v8.22.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8220-2025-01-27)##### 🩹 Fixes-   **eslint-plugin:** \[no-unnecessary-template-expression] handle template literal type ([#10612](typescript-eslint/typescript-eslint#10612))-   **eslint-plugin:** \[prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor ([#10552](typescript-eslint/typescript-eslint#10552))-   **eslint-plugin:** \[no-extraneous-class] handle accessor keyword ([#10678](typescript-eslint/typescript-eslint#10678))-   **eslint-plugin:** \[no-shadow] don't report unnecessarily on valid ways of using module augmentation ([#10616](typescript-eslint/typescript-eslint#10616))-   **eslint-plugin:** \[no-duplicate-type-constituents] handle nested types ([#10638](typescript-eslint/typescript-eslint#10638))-   **eslint-plugin:** \[prefer-nullish-coalescing] doesn't report on ternary but on equivalent || ([#10517](typescript-eslint/typescript-eslint#10517))##### ❤️ Thank You-   mdm317-   Olivier Zalmanski [@OlivierZal](https://github.com/OlivierZal)-   Ronen Amiel-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)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.
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestJan 29, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.21.0 | 8.22.0 || npm        | @typescript-eslint/parser        | 8.21.0 | 8.22.0 |## [v8.22.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8220-2025-01-27)##### 🩹 Fixes-   **eslint-plugin:** \[no-unnecessary-template-expression] handle template literal type ([#10612](typescript-eslint/typescript-eslint#10612))-   **eslint-plugin:** \[prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor ([#10552](typescript-eslint/typescript-eslint#10552))-   **eslint-plugin:** \[no-extraneous-class] handle accessor keyword ([#10678](typescript-eslint/typescript-eslint#10678))-   **eslint-plugin:** \[no-shadow] don't report unnecessarily on valid ways of using module augmentation ([#10616](typescript-eslint/typescript-eslint#10616))-   **eslint-plugin:** \[no-duplicate-type-constituents] handle nested types ([#10638](typescript-eslint/typescript-eslint#10638))-   **eslint-plugin:** \[prefer-nullish-coalescing] doesn't report on ternary but on equivalent || ([#10517](typescript-eslint/typescript-eslint#10517))##### ❤️ Thank You-   mdm317-   Olivier Zalmanski [@OlivierZal](https://github.com/OlivierZal)-   Ronen Amiel-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)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.
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsFeb 4, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@kirkwaiblingerkirkwaiblingerkirkwaiblinger 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 merge
Projects
None yet
Milestone
No milestone
3 participants
@yeonjuan@JoshuaKGoldberg@kirkwaiblinger

[8]ページ先頭

©2009-2025 Movatter.jp