eslint-plugin-crisp 1.4.10 → 1.4.11
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/index.js +2 -0
- package/package.json +1 -1
- package/recommended-vue.js +1 -0
- package/rules/vue-data-comment.js +76 -0
package/index.js
CHANGED
|
@@ -41,6 +41,7 @@ import ruleVariableNames from "./rules/variable-names.js";
|
|
|
41
41
|
import ruleVueAttributeComma from "./rules/vue-attribute-comma.js";
|
|
42
42
|
import ruleVueAttributeLinebreak from "./rules/vue-attribute-linebreak.js";
|
|
43
43
|
import ruleVueComputedOrder from "./rules/vue-computed-order.js";
|
|
44
|
+
import ruleVueDataComment from "./rules/vue-data-comment.js";
|
|
44
45
|
import ruleVueEmitsOrder from "./rules/vue-emits-order.js";
|
|
45
46
|
import ruleVueHeaderCheck from "./rules/vue-header-check.js";
|
|
46
47
|
import ruleVueHtmlIndent from "./rules/vue-html-indent.js";
|
|
@@ -106,6 +107,7 @@ const plugin = {
|
|
|
106
107
|
"vue-attribute-comma": ruleVueAttributeComma,
|
|
107
108
|
"vue-attribute-linebreak": ruleVueAttributeLinebreak,
|
|
108
109
|
"vue-computed-order": ruleVueComputedOrder,
|
|
110
|
+
"vue-data-comment": ruleVueDataComment,
|
|
109
111
|
"vue-emits-order": ruleVueEmitsOrder,
|
|
110
112
|
"vue-header-check": ruleVueHeaderCheck,
|
|
111
113
|
"vue-html-indent": ruleVueHtmlIndent,
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -375,6 +375,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
375
375
|
"crisp/vue-attribute-comma": "error",
|
|
376
376
|
"crisp/vue-attribute-linebreak": "error",
|
|
377
377
|
"crisp/vue-computed-order": "error",
|
|
378
|
+
"crisp/vue-data-comment": "error",
|
|
378
379
|
"crisp/vue-emits-order": "error",
|
|
379
380
|
"crisp/vue-header-check": "error",
|
|
380
381
|
"crisp/vue-html-indent": "error",
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "enforce comment as first line in Vue data() return object",
|
|
6
|
+
category: "Stylistic Issues",
|
|
7
|
+
recommended: false
|
|
8
|
+
},
|
|
9
|
+
fixable: null,
|
|
10
|
+
schema: []
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
create(context) {
|
|
14
|
+
const COMMENT_PATTERN = /^--> (STATE|DATA|ROUTE PARAMS|COMPONENTS) <--$/;
|
|
15
|
+
const COMMENT_LIKE_PATTERN = /^--> .+ <--$/;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
'Property[key.name="data"] > FunctionExpression > BlockStatement > ReturnStatement > ObjectExpression'(node) {
|
|
19
|
+
const properties = node.properties;
|
|
20
|
+
|
|
21
|
+
if (!properties || properties.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const sourceCode = context.getSourceCode();
|
|
26
|
+
const comments = sourceCode.getCommentsInside(node);
|
|
27
|
+
|
|
28
|
+
if (comments.length === 0) {
|
|
29
|
+
context.report({
|
|
30
|
+
node,
|
|
31
|
+
message:
|
|
32
|
+
"data() return object must start with a comment: " +
|
|
33
|
+
"'// --> STATE <--', '// --> DATA <--', " +
|
|
34
|
+
"'// --> ROUTE PARAMS <--', or '// --> COMPONENTS <--'."
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const firstComment = comments[0];
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
firstComment.type !== "Line" ||
|
|
44
|
+
!COMMENT_PATTERN.test(firstComment.value.trim())
|
|
45
|
+
) {
|
|
46
|
+
context.report({
|
|
47
|
+
node: firstComment,
|
|
48
|
+
message:
|
|
49
|
+
"data() return object must start with a comment: " +
|
|
50
|
+
"'// --> STATE <--', '// --> DATA <--', " +
|
|
51
|
+
"'// --> ROUTE PARAMS <--', or '// --> COMPONENTS <--'."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
comments.forEach((comment) => {
|
|
56
|
+
if (comment.type === "Line") {
|
|
57
|
+
const trimmed = comment.value.trim();
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
COMMENT_LIKE_PATTERN.test(trimmed) &&
|
|
61
|
+
!COMMENT_PATTERN.test(trimmed)
|
|
62
|
+
) {
|
|
63
|
+
context.report({
|
|
64
|
+
node: comment,
|
|
65
|
+
message:
|
|
66
|
+
"Invalid comment. Must be '// --> STATE <--', " +
|
|
67
|
+
"'// --> DATA <--', '// --> ROUTE PARAMS <--', " +
|
|
68
|
+
"or '// --> COMPONENTS <--'."
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|