Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[unified-signatures] Don't trigger on mergeable declaration with different parameter name #2386

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
sindresorhus opened this issue Aug 11, 2020 · 3 comments · Fixed by #4659
Closed
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sindresorhus
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/unified-signatures": "error"
  }
}
declare const findUp: {
	(name: string | readonly string[], options?: findUp.Options): Promise<string | undefined>;

	(matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
};

Expected Result

I expected it not to be a violation as a different parameter name is a good indication that the overloads are not compatible.

Actual Result

  ✖   57:4  These overloads can be combined into one signature taking string | string[] | (directory: string) => findUp.Match.                            @typescript-eslint/unified-signatures
  ✖  134:3  These overloads can be combined into one signature taking string | string[] | (directory: string) => (findUp.Match | Promise<findUp.Match>).  @typescript-eslint/unified-signatures

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 3.9.0
@typescript-eslint/parser 3.9.0
TypeScript 3.9.7
ESLint 7.6.0
node 10.22.0
npm 6.14.7
@sindresorhus sindresorhus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Aug 11, 2020
@bradzacher
Copy link
Member

bradzacher commented Aug 11, 2020

This rule aims to keep the source code as maintainable as possible by reducing the amount of overloads.

If the signatures themselves are mergeable, then it seems like it aligns with the rule to merge them, regardless of parameter names.

I wouldn't hugely want to rely upon parameter names in this rule.

different parameter name is a good indication that the overloads are not compatible

In some cases, maybe. In others - no.

declare const foo: {
  (argument: string);
  (argment: boolean);
  (arg: number);
}

Are all 3 signatures here unifiable or not? Probably not if you're looking at naming. Could probably implement a heuristic like the Levenshtein distance to check for this. It's a lot of code to maintain for an rarer case / requirement though.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Aug 11, 2020
@sindresorhus
Copy link
Author

If the signatures themselves are mergeable, then it seems like it aligns with the rule to merge them, regardless of parameter names.

The overloads I showed are completely separate though, functionality-wise, and in the actual code, they have separate doc comments too.

Here's the actual code: https://github.com/sindresorhus/find-up/blob/e852e9cfd020844fac0ea2ff073c378cc302db4d/index.d.ts#L84-L135

In some cases, maybe. In others - no.

That example is not realistic. A realistic example would be something like:

declare const foo: {
  (argument: string);
  (arguments: string[]);
}

Could probably implement a heuristic like the Levenshtein distance to check for this.

That's too far, I think. But a simple pluralization check could make sense.

@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed awaiting response Issues waiting for a reply from the OP or another party labels Aug 17, 2020
@bradzacher
Copy link
Member

Happy to accept a PR for a default off option which tells the rule to ignore signatures if the param names are different.

@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants