diff --git a/packages/eslint-plugin/src/rules/max-params.ts b/packages/eslint-plugin/src/rules/max-params.ts index acd02f052d15..c2920e901c16 100644 --- a/packages/eslint-plugin/src/rules/max-params.ts +++ b/packages/eslint-plugin/src/rules/max-params.ts @@ -13,7 +13,9 @@ import { getESLintCoreRule } from '../util/getESLintCoreRule'; type FunctionLike = | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression; + | TSESTree.FunctionExpression + | TSESTree.TSDeclareFunction + | TSESTree.TSFunctionType; type FunctionRuleListener = (node: T) => void; @@ -97,6 +99,8 @@ export default createRule({ ArrowFunctionExpression: wrapListener(baseRules.ArrowFunctionExpression), FunctionDeclaration: wrapListener(baseRules.FunctionDeclaration), FunctionExpression: wrapListener(baseRules.FunctionExpression), + TSDeclareFunction: wrapListener(baseRules.FunctionDeclaration), + TSFunctionType: wrapListener(baseRules.FunctionDeclaration), }; }, }); diff --git a/packages/eslint-plugin/tests/rules/max-params.test.ts b/packages/eslint-plugin/tests/rules/max-params.test.ts index 0bbbdcdc92be..3edbd34ae346 100644 --- a/packages/eslint-plugin/tests/rules/max-params.test.ts +++ b/packages/eslint-plugin/tests/rules/max-params.test.ts @@ -57,6 +57,18 @@ class Foo { `, options: [{ countVoidThis: true, max: 2 }], }, + { + code: ` +declare function makeDate(m: number, d: number, y: number): Date; + `, + options: [{ max: 3 }], + }, + { + code: ` +type sum = (a: number, b: number) => number; + `, + options: [{ max: 2 }], + }, ], invalid: [ { code: 'function foo(a, b, c, d) {}', errors: [{ messageId: 'exceed' }] }, @@ -98,5 +110,19 @@ class Foo { `, errors: [{ messageId: 'exceed' }], }, + { + code: ` +declare function makeDate(m: number, d: number, y: number): Date; + `, + errors: [{ messageId: 'exceed' }], + options: [{ max: 1 }], + }, + { + code: ` +type sum = (a: number, b: number) => number; + `, + errors: [{ messageId: 'exceed' }], + options: [{ max: 1 }], + }, ], }); diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index a946d3365a55..6632125e3b15 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -113,7 +113,12 @@ declare module 'eslint/lib/rules/max-params' { unknown, { ArrowFunctionExpression(node: TSESTree.ArrowFunctionExpression): void; - FunctionDeclaration(node: TSESTree.FunctionDeclaration): void; + FunctionDeclaration( + node: + | TSESTree.FunctionDeclaration + | TSESTree.TSDeclareFunction + | TSESTree.TSFunctionType, + ): void; FunctionExpression(node: TSESTree.FunctionExpression): void; } >;