eslint-plugin-crisp 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
category: "Stylistic Issues",
|
|
7
7
|
recommended: false,
|
|
8
8
|
},
|
|
9
|
-
fixable: "
|
|
9
|
+
fixable: "code",
|
|
10
10
|
schema: [
|
|
11
11
|
{
|
|
12
12
|
type: "object",
|
|
@@ -27,13 +27,15 @@ export default {
|
|
|
27
27
|
const config = context.options[0] || {};
|
|
28
28
|
const checkColon = config.checkColon !== false;
|
|
29
29
|
|
|
30
|
-
const checkSpacing = (operatorToken) => {
|
|
30
|
+
const checkSpacing = (operatorToken, valueNode, indentationNode) => {
|
|
31
31
|
if (!operatorToken) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const tokenBefore = sourceCode.getTokenBefore(operatorToken);
|
|
36
|
-
const tokenAfter = sourceCode.getTokenAfter(operatorToken
|
|
36
|
+
const tokenAfter = sourceCode.getTokenAfter(operatorToken, {
|
|
37
|
+
includeComments: true
|
|
38
|
+
});
|
|
37
39
|
const beforeText = sourceCode.text.slice(
|
|
38
40
|
tokenBefore.range[1],
|
|
39
41
|
operatorToken.range[0]
|
|
@@ -44,6 +46,10 @@ export default {
|
|
|
44
46
|
);
|
|
45
47
|
const hasSpaceBefore = /[ \t]$/.test(beforeText);
|
|
46
48
|
const hasOneSpaceAfter = afterText === " ";
|
|
49
|
+
const hasLineBreakAfter = (
|
|
50
|
+
/^[\s]*$/.test(afterText) &&
|
|
51
|
+
/[\r\n]/.test(afterText)
|
|
52
|
+
);
|
|
47
53
|
|
|
48
54
|
if (!hasSpaceBefore || !hasOneSpaceAfter) {
|
|
49
55
|
context.report({
|
|
@@ -60,11 +66,37 @@ export default {
|
|
|
60
66
|
));
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
if (!hasOneSpaceAfter
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
if (!hasOneSpaceAfter) {
|
|
70
|
+
if (/^[ \t]*$/.test(afterText)) {
|
|
71
|
+
fixes.push(fixer.replaceTextRange(
|
|
72
|
+
[operatorToken.range[1], tokenAfter.range[0]],
|
|
73
|
+
" "
|
|
74
|
+
));
|
|
75
|
+
} else if (hasLineBreakAfter && valueNode) {
|
|
76
|
+
const firstValueToken = sourceCode.getTokenAfter(operatorToken);
|
|
77
|
+
|
|
78
|
+
if (firstValueToken.value === "(") {
|
|
79
|
+
fixes.push(fixer.replaceTextRange(
|
|
80
|
+
[operatorToken.range[1], tokenAfter.range[0]],
|
|
81
|
+
" "
|
|
82
|
+
));
|
|
83
|
+
} else {
|
|
84
|
+
const indentation = " ".repeat(
|
|
85
|
+
indentationNode.loc.start.column
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
fixes.push(
|
|
89
|
+
fixer.replaceTextRange(
|
|
90
|
+
[operatorToken.range[1], tokenAfter.range[0]],
|
|
91
|
+
` (${afterText}`
|
|
92
|
+
),
|
|
93
|
+
fixer.insertTextAfter(
|
|
94
|
+
valueNode,
|
|
95
|
+
`\n${indentation})`
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
68
100
|
}
|
|
69
101
|
|
|
70
102
|
return fixes.length ? fixes : null;
|
|
@@ -81,7 +113,7 @@ export default {
|
|
|
81
113
|
token => token.value === node.operator
|
|
82
114
|
);
|
|
83
115
|
|
|
84
|
-
checkSpacing(operatorToken);
|
|
116
|
+
checkSpacing(operatorToken, node.right, node);
|
|
85
117
|
},
|
|
86
118
|
VariableDeclarator(node) {
|
|
87
119
|
if (node.init) {
|
|
@@ -91,7 +123,7 @@ export default {
|
|
|
91
123
|
token => token.value === "="
|
|
92
124
|
);
|
|
93
125
|
|
|
94
|
-
checkSpacing(operatorToken);
|
|
126
|
+
checkSpacing(operatorToken, node.init, node.parent);
|
|
95
127
|
}
|
|
96
128
|
},
|
|
97
129
|
|
|
@@ -7,6 +7,9 @@ ruleTester.run("one-space-after-operator", rule, {
|
|
|
7
7
|
valid: [
|
|
8
8
|
"let value = 1; value = 2;",
|
|
9
9
|
"let value = 1; value += 2;",
|
|
10
|
+
`let helpdeskLayout = /** @type {import("vue").ComputedRef<HelpdeskLayoutContext>} */ (
|
|
11
|
+
inject("helpdeskLayout")
|
|
12
|
+
);`,
|
|
10
13
|
"const object = { key : value };",
|
|
11
14
|
"const object = { method() {} };",
|
|
12
15
|
{
|
|
@@ -56,6 +59,63 @@ ruleTester.run("one-space-after-operator", rule, {
|
|
|
56
59
|
}
|
|
57
60
|
]
|
|
58
61
|
},
|
|
62
|
+
{
|
|
63
|
+
code: "const value =/** @type {number} */ (input);",
|
|
64
|
+
output: "const value = /** @type {number} */ (input);",
|
|
65
|
+
errors: [
|
|
66
|
+
{
|
|
67
|
+
message: "There should be at least one space before and exactly one space after '='"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
code: `let value =
|
|
73
|
+
first ||
|
|
74
|
+
second;`,
|
|
75
|
+
output: `let value = (
|
|
76
|
+
first ||
|
|
77
|
+
second
|
|
78
|
+
);`,
|
|
79
|
+
errors: [
|
|
80
|
+
{
|
|
81
|
+
message: "There should be at least one space before and exactly one space after '='"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
code: `function update() {
|
|
87
|
+
value +=
|
|
88
|
+
first *
|
|
89
|
+
second;
|
|
90
|
+
}`,
|
|
91
|
+
output: `function update() {
|
|
92
|
+
value += (
|
|
93
|
+
first *
|
|
94
|
+
second
|
|
95
|
+
);
|
|
96
|
+
}`,
|
|
97
|
+
errors: [
|
|
98
|
+
{
|
|
99
|
+
message: "There should be at least one space before and exactly one space after '+='"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
code: `let value =
|
|
105
|
+
(
|
|
106
|
+
first ||
|
|
107
|
+
second
|
|
108
|
+
);`,
|
|
109
|
+
output: `let value = (
|
|
110
|
+
first ||
|
|
111
|
+
second
|
|
112
|
+
);`,
|
|
113
|
+
errors: [
|
|
114
|
+
{
|
|
115
|
+
message: "There should be at least one space before and exactly one space after '='"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
59
119
|
{
|
|
60
120
|
code: "const object = { key: value };",
|
|
61
121
|
output: "const object = { key : value };",
|