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): [prefer-promise-reject-errors] add rule#8011

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

auvred
Copy link
Member

PR Checklist

Overview

I tried to migrate theoriginal rule with only type information added (it allows to detectPromiseConstructor like andError like variables)

Also I movedisErrorLike function to thetype-utils package (I hope it's the right place for this function) as its logic may be reused both inprefer-promise-reject-errors andno-throw-literal

I copied incorrect and correct examples fromno-throw-literal because I found them applicable. But maybe there are too many examples for this rule

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@auvred!

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 commentedDec 1, 2023
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commitbd20782
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/659a6189a92e2f00080aa1f9
😎 Deploy Previewhttps://deploy-preview-8011--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.

@auvredauvred marked this pull request as draftDecember 1, 2023 15:16
@auvredauvred marked this pull request as ready for reviewDecember 2, 2023 09:04
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.

Awesome, really solid work here - thanks for working on it@auvred!

It's interesting that this is the first rule to really need to check whether something is actually a'PromiseConstructor'. Others have just approximated comparisons toThenable.

A few touchups & refactors requested, but the general direction looks great to me! 🚀

auvred reacted with heart emoji
Comment on lines 72 to 86
function isPromiseConstructorLike(type: ts.Type): boolean {
const symbol = type.getSymbol();

if (symbol?.getName() === 'PromiseConstructor') {
const declarations = symbol.getDeclarations() ?? [];
for (const declaration of declarations) {
const sourceFile = declaration.getSourceFile();
if (program.isSourceFileDefaultLibrary(sourceFile)) {
return true;
}
}
}

return false;
}

Choose a reason for hiding this comment

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

[Refactor] This is roughly the same logic asisErrorLike's for checking if it's a built-in of a particular name. Could you extract into a shared helper for this too?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Not sure about the function name, but I extracted it:https://github.com/typescript-eslint/typescript-eslint/pull/8011/files#diff-75626015398ba4cc6293d6ec23077170a50f23e306b326a44966e44448c3edf2


TODO: refactor these places to use this function

if(symbol&&symbol.escapedName===FUNCTION_CONSTRUCTOR){
constdeclarations=symbol.getDeclarations()??[];
for(constdeclarationofdeclarations){
constsourceFile=declaration.getSourceFile();
if(services.program.isSourceFileDefaultLibrary(sourceFile)){
returntrue;
}
}
}
if(symbol){
constdeclarations=symbol.getDeclarations()??[];
for(constdeclarationofdeclarations){
constsourceFile=declaration.getSourceFile();
if(services.program.isSourceFileDefaultLibrary(sourceFile)){
context.report({ node,messageId:'noFunctionConstructor'});
return;
}
}

Choose a reason for hiding this comment

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

LGTM! If you want to do that refactor in this PR I'd happily approve. Or we can leave it as agood first issue followup. Either way.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Let's open a followup withgood first issue ;)

JoshuaKGoldberg reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelDec 5, 2023
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesDec 29, 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.

This looks lovely, thanks! 🙌

No blocking requests (other than the"guarantee" nit) from me. Just some touchup suggestions. Feel free to wontfix or do them, and then we can merge. Or if you don't have time I'll take another look soon. Cheers!

@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelDec 29, 2023
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@auvredauvredforce-pushed thefeat/prefer-promise-reject-errors-rule branch fromad4dc75 to895f1b5CompareDecember 29, 2023 19:46
Tjstretchalot added a commit to Tjstretchalot/typescript-eslint that referenced this pull requestJan 2, 2024
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.

Sorry, two blocking requests:

  • The variable readability change actually introduced a performance regression - lmk if the suggestion doesn't make sense?
  • Apologies, I missed commenting on a couple of missing test cases

Since I already approved I do feel bad now requesting changes. If you don't have energy+time then no worries. I can apply these soon.

auvred reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added awaiting responseIssues waiting for a reply from the OP or another party and removed 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelsJan 4, 2024
@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelJan 4, 2024
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.

Super, thanks! This looks great. 🚀

Neil Patrick Harris giving two thumbs up and grinning

@JoshuaKGoldbergJoshuaKGoldberg merged commit1aa8664 intotypescript-eslint:mainJan 9, 2024
Tjstretchalot added a commit to Tjstretchalot/typescript-eslint that referenced this pull requestJan 10, 2024
Tjstretchalot added a commit to Tjstretchalot/typescript-eslint that referenced this pull requestJan 12, 2024
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJan 17, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@StyleShitStyleShitStyleShit requested changes

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Base rule extension: [prefer-promise-reject-errors]
3 participants
@auvred@JoshuaKGoldberg@StyleShit

[8]ページ先頭

©2009-2025 Movatter.jp