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

chore(type-utils): reuse newly added "is builtin symbol like" logic#8287

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

Closed

Conversation

arkapratimc
Copy link
Contributor

@arkapratimcarkapratimc commentedJan 22, 2024
edited
Loading

fixes:#8234

PR Checklist

Overview

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @arka1002!

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 22, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit7c96190
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/65ae788bf15b9f0008692838
😎 Deploy Previewhttps://deploy-preview-8287--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: 99 (🟢 up 2 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.

* let I = (callback: Function) => {}
* ^ FunctionLike
*/
export function isFunctionLike(program: ts.Program, type: ts.Type): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

typescript package already exports the function with same nameisFunctionLike. Having two functions with the same name may cause confusion.

export function isFunctionLike(program: ts.Program, type: ts.Type): boolean {
return (
isBuiltinSymbolLike(program, type, 'Function') ||
isBuiltinSymbolLike(program, type, 'FunctionConstructor')
Copy link
Member

Choose a reason for hiding this comment

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

The original rule didn't check for symbols with nameFunctionConstructor. Should we add tests that contain symbols with nameFunctionConstructor? But that is probably not within the scope of this pr. IMO we shouldn't change the rule logic in this pr

Copy link
ContributorAuthor

@arkapratimcarkapratimcJan 22, 2024
edited
Loading

Choose a reason for hiding this comment

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

I just want to ask a small question -

This rule is checking FunctionConstructor right ? Like, in this case, the escapedName of the symbol is 'FunctionConstructor'.

code:"const fn = new Function('a', 'b', 'return a + b');",
errors:[
{
messageId:'noFunctionConstructor',
line:1,
column:12,
},
],

Copy link
Member

Choose a reason for hiding this comment

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

You're rightFunction here hasFunctionConstructor type. I missed this because in the source code of rule both symbol name and callee identifier's name are compared toFUNCTION_CONSTRUCTOR

Then +1 on renamingisFunctionLike... Not sure what's the best name for it. MaybeisFunctionTypeLike or something like this?

Also we should consider that#8094 most likely will introduce changes toisBuiltinSymbolLike.
As per#8094 (comment):
isBuiltinSymbolLike(program, type, 'Function') || isBuiltinSymbolLike(program, type, 'FunctionConstructor') recursively visits all subtypes twice, we can optimize to not do the same job twice.#8094 does the following:

isBuiltinSymbolLike(services.program,calleeType,name=>name==='PromiseConstructor'||name==='Promise')

Perhaps we can wait until#8094 is merged and then do the same

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, sure.

Choose a reason for hiding this comment

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

But that is probably not within the scope of this pr. IMO we shouldn't change the rule logic in this pr

Yeah this is just a refactor (chore). If you want to change how it works that'd be a separate issue.

👍 I'll mark this as blocked on#8094. Thanks :)

arkapratimc reacted with thumbs up emoji
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldbergApr 23, 2024
edited
Loading

Choose a reason for hiding this comment

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

#8094 is closed - so we can now pretend it doesn't exist*. cc @arka1002, I'm un-blocking this PR. Sorry for the long wait!

*(though if you end up taking in code from it, we'll need aCo-authored-by: Timothy Moore <mtimothy984@gmail.com> in the PR description)

Comment on lines 82 to 85
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
if (symbol && symbol.escapedName === FUNCTION_CONSTRUCTOR) {
const declarations = symbol.getDeclarations() ?? [];
for (const declaration of declarations) {
const sourceFile = declaration.getSourceFile();
if (services.program.isSourceFileDefaultLibrary(sourceFile)) {
return true;
}
}
return isFunctionLike(services.program, type);
}
Copy link
Member

Choose a reason for hiding this comment

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

isFunctionLike internally already checks that the type has a symbol, and that symbol is namedFunction, so the condition above is redundant.

@@ -1,3 +1,4 @@
import { isFunctionLike } from '@typescript-eslint/type-utils';
Copy link
Member

Choose a reason for hiding this comment

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

@typescript-eslint/type-utils shouldn't be imported directly. This function should probably be imported fromsrc/utils, as other rules do

// this is done for convenience - saves migrating all of the old rules
export*from'@typescript-eslint/type-utils';

arkapratimc reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added the blocked by another PRPRs which are ready to go but waiting on another PR labelJan 24, 2024
@JoshuaKGoldbergJoshuaKGoldberg added awaiting responseIssues waiting for a reply from the OP or another party and removed blocked by another PRPRs which are ready to go but waiting on another PR labelsApr 23, 2024
@JoshuaKGoldberg
Copy link
Member

👋 ping @arka1002, just checking in - is this PR still something you have the time and energy for?

@arkapratimc
Copy link
ContributorAuthor

Closing it 👍

JoshuaKGoldberg reacted with thumbs up emoji

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJun 3, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

@auvredauvredauvred requested changes

Assignees
No one assigned
Labels
awaiting responseIssues waiting for a reply from the OP or another party
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Repo: reuse newly added "is builtin symbol like" logic fromtype-utils
3 participants
@arkapratimc@JoshuaKGoldberg@auvred

[8]ページ先頭

©2009-2025 Movatter.jp