Skip to content

Commit

Permalink
fix(eslint-plugin): [unified-signatures] no parameters function (#6940)
Browse files Browse the repository at this point in the history
* fix: [unified-signatures] no parameters function

* change: [unified-signatures] check every b.params[i]

* quick lil refactor

---------

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
  • Loading branch information
u-abyss and JoshuaKGoldberg committed Apr 24, 2023
1 parent 8974fb1 commit 2970861
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/unified-signatures.ts
Expand Up @@ -213,7 +213,8 @@ export default util.createRule<Options, MessageIds>({
b.typeParameters !== undefined ? b.typeParameters.params : undefined;

if (ignoreDifferentlyNamedParameters) {
for (let i = 0; i < a.params.length; i += 1) {
const commonParamsLength = Math.min(a.params.length, b.params.length);
for (let i = 0; i < commonParamsLength; i += 1) {
if (
a.params[i].type === b.params[i].type &&
getStaticParameterName(a.params[i]) !==
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/unified-signatures.test.ts
Expand Up @@ -177,6 +177,28 @@ function f(v: number, u?: string): void {}
},
{
code: `
function f(v: boolean): number;
function f(): string;
`,
options: [{ ignoreDifferentlyNamedParameters: true }],
},
{
code: `
function f(v: boolean, u: boolean): number;
function f(v: boolean): string;
`,
options: [{ ignoreDifferentlyNamedParameters: true }],
},
{
code: `
function f(v: number, u?: string): void {}
function f(v: number): void;
function f(): string;
`,
options: [{ ignoreDifferentlyNamedParameters: true }],
},
{
code: `
function f(a: boolean, ...c: number[]): void;
function f(a: boolean, ...d: string[]): void;
function f(a: boolean, ...c: (number | string)[]): void {}
Expand Down

0 comments on commit 2970861

Please sign in to comment.