-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
max-params.js
105 lines (96 loc) · 3.35 KB
/
max-params.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @fileoverview Tests for max-params rule.
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/max-params"),
RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("max-params", rule, {
valid: [
"function test(d, e, f) {}",
{ code: "var test = function(a, b, c) {};", options: [3] },
{ code: "var test = (a, b, c) => {};", options: [3], parserOptions: { ecmaVersion: 6 } },
{ code: "var test = function test(a, b, c) {};", options: [3] },
// object property options
{ code: "var test = function(a, b, c) {};", options: [{ max: 3 }] }
],
invalid: [
{
code: "function test(a, b, c) {}",
options: [2],
errors: [{
message: "Function 'test' has too many parameters (3). Maximum allowed is 2.",
type: "FunctionDeclaration"
}]
},
{
code: "function test(a, b, c, d) {}",
errors: [{
message: "Function 'test' has too many parameters (4). Maximum allowed is 3.",
type: "FunctionDeclaration"
}]
},
{
code: "var test = function(a, b, c, d) {};",
options: [3],
errors: [{
message: "Function has too many parameters (4). Maximum allowed is 3.",
type: "FunctionExpression"
}]
},
{
code: "var test = (a, b, c, d) => {};",
options: [3],
parserOptions: { ecmaVersion: 6 },
errors: [{
message: "Arrow function has too many parameters (4). Maximum allowed is 3.",
type: "ArrowFunctionExpression"
}]
},
{
code: "(function(a, b, c, d) {});",
options: [3],
errors: [{
message: "Function has too many parameters (4). Maximum allowed is 3.",
type: "FunctionExpression"
}]
},
{
code: "var test = function test(a, b, c) {};",
options: [1],
errors: [{
message: "Function 'test' has too many parameters (3). Maximum allowed is 1.",
type: "FunctionExpression"
}]
},
// object property options
{
code: "function test(a, b, c) {}",
options: [{ max: 2 }],
errors: [{
message: "Function 'test' has too many parameters (3). Maximum allowed is 2.",
type: "FunctionDeclaration"
}]
},
// Error location should not cover the entire function; just the name.
{
code: `function test(a, b, c) {
// Just to make it longer
}`,
options: [{ max: 2 }],
errors: [{
line: 1,
column: 1,
endLine: 1,
endColumn: 14
}]
}
]
});