eslint-plugin-crisp 1.7.15 → 1.7.16
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
|
@@ -30,6 +30,8 @@ export default {
|
|
|
30
30
|
"Methods block must contain at least one separator comment: " +
|
|
31
31
|
"'// --> ACTIONS <--', '// --> HELPERS <--', " +
|
|
32
32
|
"or '// --> EVENT LISTENERS <--'.",
|
|
33
|
+
missingSeparatorSpacing:
|
|
34
|
+
"Methods separator comments must be followed by a blank line.",
|
|
33
35
|
unorderedSeparator:
|
|
34
36
|
"Methods separator comments must be ordered: '// --> ACTIONS <--', " +
|
|
35
37
|
"then '// --> HELPERS <--', then '// --> EVENT LISTENERS <--'."
|
|
@@ -147,6 +149,75 @@ export default {
|
|
|
147
149
|
};
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
function checkSeparatorSpacing(comment, comments, properties) {
|
|
153
|
+
const nextSeparator = comments.find((candidate) => {
|
|
154
|
+
return (
|
|
155
|
+
candidate.range[0] > comment.range[1] &&
|
|
156
|
+
candidate.type === "Line" &&
|
|
157
|
+
SEPARATOR_LIKE_PATTERN.test(candidate.value.trim())
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
const firstProperty = properties.find((property) => {
|
|
161
|
+
return (
|
|
162
|
+
property.range[0] > comment.range[1] &&
|
|
163
|
+
(!nextSeparator || property.range[0] < nextSeparator.range[0])
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (!firstProperty) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const firstLeadingComment = sourceCode
|
|
172
|
+
.getCommentsBefore(firstProperty)
|
|
173
|
+
.find((candidate) => {
|
|
174
|
+
return (
|
|
175
|
+
candidate.range[0] > comment.range[1] &&
|
|
176
|
+
(!nextSeparator || candidate.range[0] < nextSeparator.range[0])
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
const firstNode = firstLeadingComment || firstProperty;
|
|
180
|
+
|
|
181
|
+
if (firstNode.loc.start.line > comment.loc.end.line + 1) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const spacingFix = (fixer) => {
|
|
186
|
+
const lineStart = sourceCode.getIndexFromLoc({
|
|
187
|
+
line: firstNode.loc.start.line,
|
|
188
|
+
column: 0
|
|
189
|
+
});
|
|
190
|
+
const indentation = sourceCode.text.slice(
|
|
191
|
+
lineStart,
|
|
192
|
+
firstNode.range[0]
|
|
193
|
+
);
|
|
194
|
+
const currentSpacing = sourceCode.text.slice(
|
|
195
|
+
comment.range[1],
|
|
196
|
+
firstNode.range[0]
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
if (
|
|
200
|
+
indentation.trim() !== "" ||
|
|
201
|
+
currentSpacing.trim() !== ""
|
|
202
|
+
) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const linebreak = currentSpacing.includes("\r\n") ? "\r\n" : "\n";
|
|
207
|
+
|
|
208
|
+
return fixer.replaceTextRange(
|
|
209
|
+
[comment.range[1], firstNode.range[0]],
|
|
210
|
+
`${linebreak}${linebreak}${indentation}`
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
context.report({
|
|
215
|
+
node: comment,
|
|
216
|
+
messageId: "missingSeparatorSpacing",
|
|
217
|
+
fix: spacingFix
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
150
221
|
function checkMethods(node) {
|
|
151
222
|
const properties = node.value.properties;
|
|
152
223
|
|
|
@@ -171,11 +242,21 @@ export default {
|
|
|
171
242
|
let hasInvalidSeparator = false;
|
|
172
243
|
|
|
173
244
|
comments.forEach((comment) => {
|
|
245
|
+
const separator = comment.value.trim();
|
|
246
|
+
|
|
174
247
|
if (comment.type !== "Line") {
|
|
248
|
+
if (SEPARATOR_LIKE_PATTERN.test(separator)) {
|
|
249
|
+
hasInvalidSeparator = true;
|
|
250
|
+
|
|
251
|
+
context.report({
|
|
252
|
+
node: comment,
|
|
253
|
+
messageId: "invalidSeparator"
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
175
257
|
return;
|
|
176
258
|
}
|
|
177
259
|
|
|
178
|
-
const separator = comment.value.trim();
|
|
179
260
|
const separatorOrder = SEPARATOR_ORDER.get(separator);
|
|
180
261
|
|
|
181
262
|
if (separatorOrder === undefined) {
|
|
@@ -212,6 +293,17 @@ export default {
|
|
|
212
293
|
});
|
|
213
294
|
});
|
|
214
295
|
|
|
296
|
+
comments
|
|
297
|
+
.filter((comment) => {
|
|
298
|
+
return (
|
|
299
|
+
comment.type === "Line" &&
|
|
300
|
+
SEPARATOR_ORDER.has(comment.value.trim())
|
|
301
|
+
);
|
|
302
|
+
})
|
|
303
|
+
.forEach((comment) => {
|
|
304
|
+
checkSeparatorSpacing(comment, comments, properties);
|
|
305
|
+
});
|
|
306
|
+
|
|
215
307
|
let lastSeparatorOrder = -1;
|
|
216
308
|
const unorderedEntries = separatorEntries.filter((entry) => {
|
|
217
309
|
if (entry.order < lastSeparatorOrder) {
|
|
@@ -13,6 +13,7 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
13
13
|
export default {
|
|
14
14
|
methods: {
|
|
15
15
|
// --> ACTIONS <--
|
|
16
|
+
|
|
16
17
|
save() {}
|
|
17
18
|
}
|
|
18
19
|
};
|
|
@@ -23,6 +24,7 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
23
24
|
export default {
|
|
24
25
|
methods: {
|
|
25
26
|
// --> HELPERS <--
|
|
27
|
+
|
|
26
28
|
format() {}
|
|
27
29
|
}
|
|
28
30
|
};
|
|
@@ -33,6 +35,7 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
33
35
|
export default {
|
|
34
36
|
methods: {
|
|
35
37
|
// --> EVENT LISTENERS <--
|
|
38
|
+
|
|
36
39
|
onSave() {}
|
|
37
40
|
}
|
|
38
41
|
};
|
|
@@ -43,8 +46,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
43
46
|
export default {
|
|
44
47
|
methods: {
|
|
45
48
|
// --> ACTIONS <--
|
|
49
|
+
|
|
46
50
|
save() {},
|
|
47
51
|
// --> EVENT LISTENERS <--
|
|
52
|
+
|
|
48
53
|
onSave() {}
|
|
49
54
|
}
|
|
50
55
|
};
|
|
@@ -55,10 +60,13 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
55
60
|
export default defineComponent({
|
|
56
61
|
methods: {
|
|
57
62
|
// --> ACTIONS <--
|
|
63
|
+
|
|
58
64
|
save() {},
|
|
59
65
|
// --> HELPERS <--
|
|
66
|
+
|
|
60
67
|
format() {},
|
|
61
68
|
// --> EVENT LISTENERS <--
|
|
69
|
+
|
|
62
70
|
onSave() {}
|
|
63
71
|
}
|
|
64
72
|
});
|
|
@@ -80,6 +88,7 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
80
88
|
export default {
|
|
81
89
|
methods: {
|
|
82
90
|
// --> ACTIONS <--
|
|
91
|
+
|
|
83
92
|
save() {
|
|
84
93
|
// --> EVENT LISTENERS <--
|
|
85
94
|
const status = "saved";
|
|
@@ -87,6 +96,7 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
87
96
|
return status;
|
|
88
97
|
},
|
|
89
98
|
// --> HELPERS <--
|
|
99
|
+
|
|
90
100
|
format() {}
|
|
91
101
|
}
|
|
92
102
|
};
|
|
@@ -100,10 +110,13 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
100
110
|
export default defineComponent({
|
|
101
111
|
methods: {
|
|
102
112
|
// --> ACTIONS <--
|
|
113
|
+
|
|
103
114
|
save() {},
|
|
104
115
|
// --> HELPERS <--
|
|
116
|
+
|
|
105
117
|
format() {},
|
|
106
118
|
// --> EVENT LISTENERS <--
|
|
119
|
+
|
|
107
120
|
onSave() {}
|
|
108
121
|
}
|
|
109
122
|
});
|
|
@@ -121,11 +134,42 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
121
134
|
}
|
|
122
135
|
]
|
|
123
136
|
},
|
|
137
|
+
{
|
|
138
|
+
code: `
|
|
139
|
+
export default {
|
|
140
|
+
methods: {
|
|
141
|
+
// --> ACTIONS <--
|
|
142
|
+
/**
|
|
143
|
+
* Saves content
|
|
144
|
+
*/
|
|
145
|
+
save() {}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
`,
|
|
149
|
+
output: `
|
|
150
|
+
export default {
|
|
151
|
+
methods: {
|
|
152
|
+
// --> ACTIONS <--
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Saves content
|
|
156
|
+
*/
|
|
157
|
+
save() {}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
`,
|
|
161
|
+
errors: [
|
|
162
|
+
{
|
|
163
|
+
messageId: "missingSeparatorSpacing"
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
},
|
|
124
167
|
{
|
|
125
168
|
code: `
|
|
126
169
|
export default {
|
|
127
170
|
methods: {
|
|
128
171
|
// --> HELPERS <--
|
|
172
|
+
|
|
129
173
|
help() {},
|
|
130
174
|
// --> OTHER <--
|
|
131
175
|
run() {}
|
|
@@ -138,13 +182,33 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
138
182
|
}
|
|
139
183
|
]
|
|
140
184
|
},
|
|
185
|
+
{
|
|
186
|
+
code: `
|
|
187
|
+
export default {
|
|
188
|
+
methods: {
|
|
189
|
+
// --> ACTIONS <--
|
|
190
|
+
|
|
191
|
+
save() {},
|
|
192
|
+
/* --> OTHER <-- */
|
|
193
|
+
run() {}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
`,
|
|
197
|
+
errors: [
|
|
198
|
+
{
|
|
199
|
+
messageId: "invalidSeparator"
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
},
|
|
141
203
|
{
|
|
142
204
|
code: `
|
|
143
205
|
export default {
|
|
144
206
|
methods: {
|
|
145
207
|
// --> HELPERS <--
|
|
208
|
+
|
|
146
209
|
format() {},
|
|
147
210
|
// --> ACTIONS <--
|
|
211
|
+
|
|
148
212
|
save() {}
|
|
149
213
|
}
|
|
150
214
|
};
|
|
@@ -153,8 +217,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
153
217
|
export default {
|
|
154
218
|
methods: {
|
|
155
219
|
// --> ACTIONS <--
|
|
220
|
+
|
|
156
221
|
save() {},
|
|
157
222
|
// --> HELPERS <--
|
|
223
|
+
|
|
158
224
|
format() {}
|
|
159
225
|
}
|
|
160
226
|
};
|
|
@@ -242,8 +308,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
242
308
|
export default {
|
|
243
309
|
methods: {
|
|
244
310
|
// --> ACTIONS <--
|
|
311
|
+
|
|
245
312
|
save() {},
|
|
246
313
|
// --> ACTIONS <--
|
|
314
|
+
|
|
247
315
|
publish() {}
|
|
248
316
|
}
|
|
249
317
|
};
|
|
@@ -260,8 +328,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
260
328
|
export default defineComponent({
|
|
261
329
|
methods: {
|
|
262
330
|
// --> EVENT LISTENERS <--
|
|
331
|
+
|
|
263
332
|
onSave() {},
|
|
264
333
|
// --> HELPERS <--
|
|
334
|
+
|
|
265
335
|
format() {}
|
|
266
336
|
}
|
|
267
337
|
});
|
|
@@ -270,8 +340,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
270
340
|
export default defineComponent({
|
|
271
341
|
methods: {
|
|
272
342
|
// --> HELPERS <--
|
|
343
|
+
|
|
273
344
|
format() {},
|
|
274
345
|
// --> EVENT LISTENERS <--
|
|
346
|
+
|
|
275
347
|
onSave() {}
|
|
276
348
|
}
|
|
277
349
|
});
|
|
@@ -305,8 +377,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
305
377
|
export default defineComponent({
|
|
306
378
|
methods: {
|
|
307
379
|
// --> EVENT LISTENERS <--
|
|
380
|
+
|
|
308
381
|
onSave() {},
|
|
309
382
|
// --> ACTIONS <--
|
|
383
|
+
|
|
310
384
|
save() {}
|
|
311
385
|
}
|
|
312
386
|
});
|
|
@@ -317,8 +391,10 @@ ruleTester.run("vue-methods-separator", rule, {
|
|
|
317
391
|
export default defineComponent({
|
|
318
392
|
methods: {
|
|
319
393
|
// --> ACTIONS <--
|
|
394
|
+
|
|
320
395
|
save() {},
|
|
321
396
|
// --> EVENT LISTENERS <--
|
|
397
|
+
|
|
322
398
|
onSave() {}
|
|
323
399
|
}
|
|
324
400
|
});
|