Skip to content

Rule proposal: no-unnecessary-callback-wrapper #10953

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

Closed
6 tasks done
jroru opened this issue Mar 14, 2025 · 3 comments
Closed
6 tasks done

Rule proposal: no-unnecessary-callback-wrapper #10953

jroru opened this issue Mar 14, 2025 · 3 comments
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: new plugin rule New rule request for eslint-plugin locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look

Comments

@jroru
Copy link

jroru commented Mar 14, 2025

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

As noted in TSLINT_RULE_ALTERNATIVES , there is not currently an equivalent eslint rule for TSLint's no-unnecessary-callback-wrapper.

Maybe there should be - for the reasons listed on TSLint docs:

There’s generally no reason to wrap a function with a callback wrapper if it’s directly called anyway. Doing so creates extra inline lambdas that slow the runtime down.

Fail Cases

const next = () => {};

debounce(() => {
  next();
});
debounce(() => next());

Pass Cases

const next = () => {};

debounce(next);

Additional Info

No response

@jroru jroru added enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 14, 2025
@kirkwaiblinger
Copy link
Member

Hi @joru ! From looking at that rule (and checking the source code), I don't see anything about it that is specific to typescript or that requires type information to report correctly. Therefore, I don't think we can consider it for this plugin, even though it was part of tslint... Have you checked around for a similar rule in popular JS plugins?

@kirkwaiblinger kirkwaiblinger added awaiting response Issues waiting for a reply from the OP or another party triage Waiting for team members to take a look and removed triage Waiting for team members to take a look labels Mar 15, 2025
@bradzacher
Copy link
Member

I don't see anything about it that is specific to typescript or that requires type information to report correctly

Technically it should use type information for cases like

declare function acceptsCb(cb: (arg1: string) => void): void;

declare function cb(...args: number[]): void;

acceptsCb(() => cb()); // no ts error
acceptsCb(cb); // will TS error

My 2c:
The motivation behind this rule is so low value -- you're saving a single FN closure which would cost nanoseconds. There's an argument for standardisation of code but even then it's a minor win, IMO.

I'm personally -1 for owning an implementation of this rule for this reason, but also I'm -1 because it's been many years since tslint was deprecated and this is the first someone has asked for the rule -- so the rule didn't see high usage within tslint. We also haven't ever had an issue asking for a similar rule (ignoring tslint) -- which further suggests that it's not something the community cares for.

@JoshuaKGoldberg
Copy link
Member

Closing out as not in scope for typescript-eslint. We have a pretty limited maintenance budget and can't take on every rule that gets proposed. But if you're interested in writing this yourself, https://typescript-eslint.io/developers has docs for writing a custom rule. If you publish this as a standalone plugin and a lot of folks take it on, that would be evidence we should re-consider. 🙂 thanks for filing!

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 15, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: new plugin rule New rule request for eslint-plugin locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

4 participants