eslint-plugin-crisp 1.0.82 → 1.0.83
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/README.md +1 -0
- package/index.js +2 -2
- package/package.json +1 -1
- package/recommended-vue.js +1 -0
- package/rules/align-comments.js +104 -0
package/README.md
CHANGED
|
@@ -106,6 +106,7 @@ Each item has emojis denoting:
|
|
|
106
106
|
|
|
107
107
|
| Name | Description | 🟠 | 🟢 |
|
|
108
108
|
| :- | :- | :- | :- |
|
|
109
|
+
| [crisp/align-comments](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/align-comments.js) | Enforces alignment of comments compared to the previous line (the `indent` rule doesn't check this case) | 🟢 |
|
|
109
110
|
| [crisp/align-consecutive-class-assignements](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/align-consecutive-class-assignements.js) | Enforces alignment of consecutive assignment statements in a class constructor | 🟠 |
|
|
110
111
|
| [crisp/align-one-var](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/align-one-var.js) | Enforces alignment of variables in 'one-var' statements | 🟠 |
|
|
111
112
|
| [crisp/align-requires](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/align-requires.js) | Enforces alignment of require statements | 🟠 |
|
package/index.js
CHANGED
|
@@ -4,6 +4,8 @@ module.exports = {
|
|
|
4
4
|
"recommended-vue": require("./recommended-vue")
|
|
5
5
|
},
|
|
6
6
|
rules: {
|
|
7
|
+
"align-comments": require("./rules/align-comments"),
|
|
8
|
+
"align-consecutive-class-assignements": require("./rules/align-consecutive-class-assignements"),
|
|
7
9
|
"align-one-var": require("./rules/align-one-var"),
|
|
8
10
|
"align-requires": require("./rules/align-requires"),
|
|
9
11
|
"const": require("./rules/const"),
|
|
@@ -30,10 +32,8 @@ module.exports = {
|
|
|
30
32
|
"one-space-after-operator": require("./rules/one-space-after-operator"),
|
|
31
33
|
"regex-in-constructor": require("./rules/regex-in-constructor"),
|
|
32
34
|
"ternary-parenthesis": require("./rules/ternary-parenthesis"),
|
|
33
|
-
"multiline-comment-end-backslash": require("./rules/multiline-comment-end-backslash"),
|
|
34
35
|
"two-lines-between-class-members": require("./rules/two-lines-between-class-members"),
|
|
35
36
|
"variable-names": require("./rules/variable-names"),
|
|
36
|
-
"align-consecutive-class-assignements": require("./rules/align-consecutive-class-assignements"),
|
|
37
37
|
"vue-computed-order": require("./rules/vue-computed-order"),
|
|
38
38
|
"vue-emits-order": require("./rules/vue-emits-order"),
|
|
39
39
|
"vue-header-check": require("./rules/vue-header-check"),
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "layout",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "enforce comments alignment with the next line",
|
|
6
|
+
category: "Stylistic Issues",
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
fixable: "whitespace",
|
|
10
|
+
schema: [],
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
create(context) {
|
|
14
|
+
const sourceCode = context.getSourceCode();
|
|
15
|
+
const processedComments = new Set();
|
|
16
|
+
|
|
17
|
+
function checkNode(node) {
|
|
18
|
+
// Ignore nodes without location info
|
|
19
|
+
if (!node.loc) {
|
|
20
|
+
return
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const comments = sourceCode.getCommentsBefore(node);
|
|
24
|
+
|
|
25
|
+
comments.forEach(comment => {
|
|
26
|
+
if (processedComments.has(comment)) {
|
|
27
|
+
return
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const commentLine = comment.loc.start.line;
|
|
31
|
+
const commentEndLine = comment.loc.end.line;
|
|
32
|
+
const nodeLine = node.loc.start.line;
|
|
33
|
+
const commentIndent = comment.loc.start.column;
|
|
34
|
+
const nodeIndent = node.loc.start.column;
|
|
35
|
+
|
|
36
|
+
// Ignore comments on the same line as code
|
|
37
|
+
for (let line = commentLine; line <= commentEndLine; line++) {
|
|
38
|
+
const lineText = sourceCode.lines[line - 1].trim();
|
|
39
|
+
|
|
40
|
+
// Ignore if the line contains code
|
|
41
|
+
if (lineText && !lineText.startsWith("//")) {
|
|
42
|
+
return
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (commentIndent !== nodeIndent) {
|
|
47
|
+
processedComments.add(comment);
|
|
48
|
+
|
|
49
|
+
context.report({
|
|
50
|
+
node,
|
|
51
|
+
message: "Comment should be aligned with the next line.",
|
|
52
|
+
|
|
53
|
+
fix(fixer) {
|
|
54
|
+
const indent = " ".repeat(nodeIndent);
|
|
55
|
+
const commentText = sourceCode.getText(comment);
|
|
56
|
+
const fixedComment = `\n${indent}${commentText.trim()}`;
|
|
57
|
+
return fixer.replaceTextRange([comment.range[0], comment.range[1]], fixedComment);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
Program(node) {
|
|
66
|
+
node.body.forEach(statement => {
|
|
67
|
+
checkNode(statement);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
BlockStatement(node) {
|
|
72
|
+
node.body.forEach(statement => {
|
|
73
|
+
checkNode(statement);
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
ArrowFunctionExpression(node) {
|
|
78
|
+
if (node.body.type === "BlockStatement") {
|
|
79
|
+
node.body.body.forEach(statement => {
|
|
80
|
+
checkNode(statement);
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
checkNode(node.body);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
FunctionExpression(node) {
|
|
88
|
+
if (node.body.type === "BlockStatement") {
|
|
89
|
+
node.body.body.forEach(statement => {
|
|
90
|
+
checkNode(statement);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
FunctionDeclaration(node) {
|
|
96
|
+
if (node.body.type === "BlockStatement") {
|
|
97
|
+
node.body.body.forEach(statement => {
|
|
98
|
+
checkNode(statement);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
};
|