eslint-plugin-crisp 1.0.30 → 1.0.32
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 +1 -0
- package/package.json +1 -1
- package/recommended-vue.js +1 -1
- package/recommended.js +1 -0
- package/rules/methods-ordering.js +68 -0
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ module.exports = {
|
|
|
16
16
|
"jsdoc-enforce-access": require("./rules/jsdoc-enforce-access"),
|
|
17
17
|
"jsdoc-enforce-classdesc": require("./rules/jsdoc-enforce-classdesc"),
|
|
18
18
|
"methods-naming": require("./rules/methods-naming"),
|
|
19
|
+
"methods-ordering": require("./rules/methods-ordering"),
|
|
19
20
|
"multiline-comment-end-backslash": require("./rules/multiline-comment-end-backslash"),
|
|
20
21
|
"no-async": require("./rules/no-async"),
|
|
21
22
|
"no-var-in-blocks": require("./rules/no-var-in-blocks"),
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -66,6 +66,7 @@ module.exports = {
|
|
|
66
66
|
"crisp/header-check": "error",
|
|
67
67
|
"crisp/header-comments-check": "error",
|
|
68
68
|
"crisp/methods-naming": "error",
|
|
69
|
+
"crisp/methods-ordering": "error",
|
|
69
70
|
"crisp/multiline-comment-end-backslash": "error",
|
|
70
71
|
"crisp/no-async": "error",
|
|
71
72
|
"crisp/no-var-in-blocks": "error",
|
|
@@ -131,7 +132,6 @@ module.exports = {
|
|
|
131
132
|
// General Vue rules
|
|
132
133
|
"vue/html-quotes": "off",
|
|
133
134
|
"vue/no-v-html": "off",
|
|
134
|
-
"vue/prefer-prop-type-boolean-first": "error",
|
|
135
135
|
"vue/prefer-true-attribute-shorthand": "error",
|
|
136
136
|
"vue/attributes-order": [
|
|
137
137
|
"error",
|
package/recommended.js
CHANGED
|
@@ -120,6 +120,7 @@ module.exports = {
|
|
|
120
120
|
"exceptions": ["_", "$"]
|
|
121
121
|
}],
|
|
122
122
|
"crisp/methods-naming": "error",
|
|
123
|
+
"crisp/methods-ordering": "error",
|
|
123
124
|
"crisp/one-space-after-operator": "error",
|
|
124
125
|
"crisp/ternary-parenthesis": "error",
|
|
125
126
|
"crisp/align-consecutive-class-assignements": "error",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const doctrine = require("doctrine");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
create(context) {
|
|
5
|
+
let methodOrder = []; // Keep track of method order
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
MethodDefinition(node) {
|
|
9
|
+
const commentsBefore = context.getSourceCode().getCommentsBefore(node);
|
|
10
|
+
|
|
11
|
+
// Check if there is a comment matching `--> {VALUE} <--` before the node
|
|
12
|
+
const nodeComment = commentsBefore.find(comment => comment.type === "Line" && /--> (.*) <--/.test(comment.value));
|
|
13
|
+
|
|
14
|
+
// Reset methodOrder if a matching comment was found
|
|
15
|
+
if (nodeComment) {
|
|
16
|
+
methodOrder = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Reset methodOrder if the method name is "constructor"
|
|
20
|
+
if (node.kind === "constructor") {
|
|
21
|
+
methodOrder = [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Parse JSDoc
|
|
25
|
+
const jsDocComment = commentsBefore.find(comment => comment.type === "Block" && comment.value.startsWith("*"));
|
|
26
|
+
|
|
27
|
+
// If there is no JSDoc, ignore this method
|
|
28
|
+
if (!jsDocComment) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse the jsDocComment using doctrine
|
|
33
|
+
const jsDoc = doctrine.parse(`/*${jsDocComment.value}*/`, { unwrap: true });
|
|
34
|
+
|
|
35
|
+
// Extract visibility from JSDoc
|
|
36
|
+
const visibilityTag = jsDoc.tags.find(tag => ["public", "protected", "private"].includes(tag.title));
|
|
37
|
+
|
|
38
|
+
// If there is no visibility tag, ignore this method
|
|
39
|
+
if (!visibilityTag) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const methodKind = visibilityTag.title;
|
|
44
|
+
|
|
45
|
+
// Check order of methods
|
|
46
|
+
if (methodKind === "public") {
|
|
47
|
+
if (methodOrder.includes("protected") || methodOrder.includes("private")) {
|
|
48
|
+
context.report({
|
|
49
|
+
node,
|
|
50
|
+
message: "Public methods should be defined before protected or private methods."
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
methodOrder.push("public");
|
|
54
|
+
} else if (methodKind === "protected") {
|
|
55
|
+
if (methodOrder.includes("private")) {
|
|
56
|
+
context.report({
|
|
57
|
+
node,
|
|
58
|
+
message: "Protected methods should be defined before private methods."
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
methodOrder.push("protected");
|
|
62
|
+
} else if (methodKind === "private") {
|
|
63
|
+
methodOrder.push("private");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|