/
default-param-last.js
106 lines (101 loc) · 2.72 KB
/
default-param-last.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
106
/**
* @fileoverview Test file for default-param-last
* @author Chiawen Chen
*/
"use strict";
const rule = require("../../../lib/rules/default-param-last");
const { RuleTester } = require("../../../lib/rule-tester");
const SHOULD_BE_LAST = "shouldBeLast";
const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 8 }
});
const cannedError = {
messageId: SHOULD_BE_LAST,
type: "AssignmentPattern"
};
ruleTester.run("default-param-last", rule, {
valid: [
"function f() {}",
"function f(a) {}",
"function f(a = 5) {}",
"function f(a, b) {}",
"function f(a, b = 5) {}",
"function f(a, b = 5, c = 5) {}",
"function f(a, b = 5, ...c) {}",
"const f = () => {}",
"const f = (a) => {}",
"const f = (a = 5) => {}",
"const f = function f() {}",
"const f = function f(a) {}",
"const f = function f(a = 5) {}"
],
invalid: [
{
code: "function f(a = 5, b) {}",
errors: [
{
messageId: SHOULD_BE_LAST,
column: 12,
endColumn: 17
}
]
},
{
code: "function f(a = 5, b = 6, c) {}",
errors: [
{
messageId: SHOULD_BE_LAST,
column: 12,
endColumn: 17
},
{
messageId: SHOULD_BE_LAST,
column: 19,
endColumn: 24
}
]
},
{
code: "function f (a = 5, b, c = 6, d) {}",
errors: [cannedError, cannedError]
},
{
code: "function f(a = 5, b, c = 5) {}",
errors: [
{
messageId: SHOULD_BE_LAST,
column: 12,
endColumn: 17
}
]
},
{
code: "const f = (a = 5, b, ...c) => {}",
errors: [cannedError]
},
{
code: "const f = function f (a, b = 5, c) {}",
errors: [cannedError]
},
{
code: "const f = (a = 5, { b }) => {}",
errors: [cannedError]
},
{
code: "const f = ({ a } = {}, b) => {}",
errors: [cannedError]
},
{
code: "const f = ({ a, b } = { a: 1, b: 2 }, c) => {}",
errors: [cannedError]
},
{
code: "const f = ([a] = [], b) => {}",
errors: [cannedError]
},
{
code: "const f = ([a, b] = [1, 2], c) => {}",
errors: [cannedError]
}
]
});