@@ -151,3 +151,166 @@ ruleTester.run("max-params", rule, {
151151 } ,
152152 ] ,
153153} ) ;
154+
155+ const ruleTesterTypeScript = new RuleTester ( {
156+ languageOptions : {
157+ parser : require ( "@typescript-eslint/parser" ) ,
158+ } ,
159+ } ) ;
160+
161+ ruleTesterTypeScript . run ( "max-params" , rule , {
162+ valid : [
163+ "function foo() {}" ,
164+ "const foo = function () {};" ,
165+ "const foo = () => {};" ,
166+ "function foo(a) {}" ,
167+ `
168+ class Foo {
169+ constructor(a) {}
170+ }
171+ ` ,
172+ `
173+ class Foo {
174+ method(this: void, a, b, c) {}
175+ }
176+ ` ,
177+ `
178+ class Foo {
179+ method(this: Foo, a, b) {}
180+ }
181+ ` ,
182+ {
183+ code : "function foo(a, b, c, d) {}" ,
184+ options : [ { max : 4 } ] ,
185+ } ,
186+ {
187+ code : "function foo(a, b, c, d) {}" ,
188+ options : [ { maximum : 4 } ] ,
189+ } ,
190+ {
191+ code : `
192+ class Foo {
193+ method(this: void) {}
194+ }
195+ ` ,
196+ options : [ { max : 0 } ] ,
197+ } ,
198+ {
199+ code : `
200+ class Foo {
201+ method(this: void, a) {}
202+ }
203+ ` ,
204+ options : [ { max : 1 } ] ,
205+ } ,
206+ {
207+ code : `
208+ class Foo {
209+ method(this: void, a) {}
210+ }
211+ ` ,
212+ options : [ { countVoidThis : true , max : 2 } ] ,
213+ } ,
214+ {
215+ code : `function testD(this: void, a) {}` ,
216+ options : [ { max : 1 } ] ,
217+ } ,
218+ {
219+ code : `function testD(this: void, a) {}` ,
220+ options : [ { countVoidThis : true , max : 2 } ] ,
221+ } ,
222+ {
223+ code : `const testE = function (this: void, a) {}` ,
224+ options : [ { max : 1 } ] ,
225+ } ,
226+ {
227+ code : `const testE = function (this: void, a) {}` ,
228+ options : [ { countVoidThis : true , max : 2 } ] ,
229+ } ,
230+ {
231+ code : `
232+ declare function makeDate(m: number, d: number, y: number): Date;
233+ ` ,
234+ options : [ { max : 3 } ] ,
235+ } ,
236+ {
237+ code : `
238+ type sum = (a: number, b: number) => number;
239+ ` ,
240+ options : [ { max : 2 } ] ,
241+ } ,
242+ ] ,
243+ invalid : [
244+ {
245+ code : "function foo(a, b, c, d) {}" ,
246+ errors : [ { messageId : "exceed" } ] ,
247+ } ,
248+ {
249+ code : "const foo = function (a, b, c, d) {};" ,
250+ errors : [ { messageId : "exceed" } ] ,
251+ } ,
252+ {
253+ code : "const foo = (a, b, c, d) => {};" ,
254+ errors : [ { messageId : "exceed" } ] ,
255+ } ,
256+ {
257+ code : "const foo = a => {};" ,
258+ options : [ { max : 0 } ] ,
259+ errors : [ { messageId : "exceed" } ] ,
260+ } ,
261+ {
262+ code : `
263+ class Foo {
264+ method(this: void, a, b, c, d) {}
265+ }
266+ ` ,
267+ errors : [ { messageId : "exceed" } ] ,
268+ } ,
269+ {
270+ code : `
271+ class Foo {
272+ method(this: void, a) {}
273+ }
274+ ` ,
275+ options : [ { countVoidThis : true , max : 1 } ] ,
276+ errors : [ { messageId : "exceed" } ] ,
277+ } ,
278+ {
279+ code : `function testD(this: void, a) {}` ,
280+ options : [ { countVoidThis : true , max : 1 } ] ,
281+ errors : [ { messageId : "exceed" } ] ,
282+ } ,
283+ {
284+ code : `const testE = function (this: void, a) {}` ,
285+ options : [ { countVoidThis : true , max : 1 } ] ,
286+ errors : [ { messageId : "exceed" } ] ,
287+ } ,
288+ {
289+ code : `function testFunction(test: void, a: number) {}` ,
290+ options : [ { countVoidThis : false , max : 1 } ] ,
291+ errors : [ { messageId : "exceed" } ] ,
292+ } ,
293+ {
294+ code : `
295+ class Foo {
296+ method(this: Foo, a, b, c) {}
297+ }
298+ ` ,
299+ errors : [ { messageId : "exceed" } ] ,
300+ } ,
301+ {
302+ code : `
303+ declare function makeDate(m: number, d: number, y: number): Date;
304+ ` ,
305+ options : [ { max : 1 } ] ,
306+ errors : [ { messageId : "exceed" } ] ,
307+ } ,
308+ {
309+ code : `
310+ type sum = (a: number, b: number) => number;
311+ ` ,
312+ options : [ { max : 1 } ] ,
313+ errors : [ { messageId : "exceed" } ] ,
314+ } ,
315+ ] ,
316+ } ) ;
0 commit comments