Skip to content

Commit cdbc669

Browse files
feat(eslint-plugin): [max-params] add function overload and function type support (#10312)
* feat: add function overload support * fix: type error * test: add valid test case --------- Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
1 parent 0b90e8e commit cdbc669

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Diff for: packages/eslint-plugin/src/rules/max-params.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import { getESLintCoreRule } from '../util/getESLintCoreRule';
1313
type FunctionLike =
1414
| TSESTree.ArrowFunctionExpression
1515
| TSESTree.FunctionDeclaration
16-
| TSESTree.FunctionExpression;
16+
| TSESTree.FunctionExpression
17+
| TSESTree.TSDeclareFunction
18+
| TSESTree.TSFunctionType;
1719

1820
type FunctionRuleListener<T extends FunctionLike> = (node: T) => void;
1921

@@ -97,6 +99,8 @@ export default createRule<Options, MessageIds>({
9799
ArrowFunctionExpression: wrapListener(baseRules.ArrowFunctionExpression),
98100
FunctionDeclaration: wrapListener(baseRules.FunctionDeclaration),
99101
FunctionExpression: wrapListener(baseRules.FunctionExpression),
102+
TSDeclareFunction: wrapListener(baseRules.FunctionDeclaration),
103+
TSFunctionType: wrapListener(baseRules.FunctionDeclaration),
100104
};
101105
},
102106
});

Diff for: packages/eslint-plugin/tests/rules/max-params.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ class Foo {
5757
`,
5858
options: [{ countVoidThis: true, max: 2 }],
5959
},
60+
{
61+
code: `
62+
declare function makeDate(m: number, d: number, y: number): Date;
63+
`,
64+
options: [{ max: 3 }],
65+
},
66+
{
67+
code: `
68+
type sum = (a: number, b: number) => number;
69+
`,
70+
options: [{ max: 2 }],
71+
},
6072
],
6173
invalid: [
6274
{ code: 'function foo(a, b, c, d) {}', errors: [{ messageId: 'exceed' }] },
@@ -98,5 +110,19 @@ class Foo {
98110
`,
99111
errors: [{ messageId: 'exceed' }],
100112
},
113+
{
114+
code: `
115+
declare function makeDate(m: number, d: number, y: number): Date;
116+
`,
117+
errors: [{ messageId: 'exceed' }],
118+
options: [{ max: 1 }],
119+
},
120+
{
121+
code: `
122+
type sum = (a: number, b: number) => number;
123+
`,
124+
errors: [{ messageId: 'exceed' }],
125+
options: [{ max: 1 }],
126+
},
101127
],
102128
});

Diff for: packages/eslint-plugin/typings/eslint-rules.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ declare module 'eslint/lib/rules/max-params' {
113113
unknown,
114114
{
115115
ArrowFunctionExpression(node: TSESTree.ArrowFunctionExpression): void;
116-
FunctionDeclaration(node: TSESTree.FunctionDeclaration): void;
116+
FunctionDeclaration(
117+
node:
118+
| TSESTree.FunctionDeclaration
119+
| TSESTree.TSDeclareFunction
120+
| TSESTree.TSFunctionType,
121+
): void;
117122
FunctionExpression(node: TSESTree.FunctionExpression): void;
118123
}
119124
>;

0 commit comments

Comments
 (0)