Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linter): eslint/no-useless-call #4393

Closed
wants to merge 8 commits into from

Conversation

poyoho
Copy link
Contributor

@poyoho poyoho commented Jul 21, 2024

No description provided.

poyoho added 2 commits July 20, 2024 17:52
@poyoho poyoho marked this pull request as ready for review July 21, 2024 14:56
Copy link

graphite-app bot commented Jul 21, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-linter Area - Linter label Jul 21, 2024
///
/// ### Why is this bad?
///
/// This rule is aimed to flag usage of Function.prototype.call() and Function.prototype.apply() that can be replaced with the normal function invocation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate more here? Maybe take the explanation from ESLint's website?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is from eslint website.
I think it will do more think than normal function.

}

fn is_apply_member(call_expr: &CallExpression, member_expr: &StaticMemberExpression) -> bool {
(member_expr.property.name == "call" && call_expr.arguments.len() >= 1) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

use is_method_call

Copy link
Contributor Author

@poyoho poyoho Jul 22, 2024

Choose a reason for hiding this comment

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

Thank you for your review, it has greatly benefited me. But it seem not. The call_expr.callee should skip the chain expression

poyoho added 4 commits July 23, 2024 00:44
@poyoho poyoho changed the title feat: eslint/no-useless-call feat(linter): eslint/no-useless-call Jul 23, 2024
};

if is_validate_this_arg(ctx, expected_this, this_expr) {
ctx.diagnostic(no_useless_call_diagnostic(call_expr.callee.span()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a fixer for this rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to we can't fix the expression what had the chain expression.

And the fix way is from foo.call(undefined, 1, 2); -> foo(1, 2); ?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

codspeed-hq bot commented Jul 26, 2024

CodSpeed Performance Report

Merging #4393 will degrade performances by 4.89%

Comparing poyoho:feat/no_useless_call (b82f1a2) with main (4d10c6c)

Summary

❌ 2 regressions
✅ 30 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main poyoho:feat/no_useless_call Change
linter[cal.com.tsx] 775 ms 814.9 ms -4.89%
linter[checker.ts] 1.3 s 1.4 s -4.06%

@DonIsaac
Copy link
Contributor

DonIsaac commented Sep 6, 2024

Hi @poyoho 👋 any updates on this PR?

@poyoho
Copy link
Contributor Author

poyoho commented Oct 1, 2024

I will keep following up slowly. 😁

@Boshen Boshen marked this pull request as draft November 21, 2024 07:47
@Boshen
Copy link
Member

Boshen commented Nov 25, 2024

Close as stale. Feel free to come back and finish this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants