eslint-plugin-crisp 1.0.21 → 1.0.23
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 +3 -0
- package/rules/ternary-parenthesis.js +8 -0
- package/rules/vue-header-check.js +48 -0
- package/rules/vue-no-regex-data.js +46 -0
package/index.js
CHANGED
|
@@ -31,7 +31,9 @@ module.exports = {
|
|
|
31
31
|
"align-consecutive-class-assignements": require("./rules/align-consecutive-class-assignements"),
|
|
32
32
|
"vue-computed-order": require("./rules/vue-computed-order"),
|
|
33
33
|
"vue-emits-order": require("./rules/vue-emits-order"),
|
|
34
|
+
"vue-header-check": require("./rules/vue-header-check"),
|
|
34
35
|
"vue-html-quotes": require("./rules/vue-html-quotes"),
|
|
36
|
+
"vue-no-regex-data": require("./rules/vue-no-regex-data"),
|
|
35
37
|
"vue-props-declaration-order": require("./rules/vue-props-declaration-order")
|
|
36
38
|
}
|
|
37
39
|
};
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -72,6 +72,7 @@ module.exports = {
|
|
|
72
72
|
"crisp/no-useless-template-literals": "error",
|
|
73
73
|
"crisp/one-space-after-operator": ["error", { "checkColon": false }],
|
|
74
74
|
"crisp/regex-in-constructor": "error",
|
|
75
|
+
"crisp/ternary-parenthesis": "error",
|
|
75
76
|
"crisp/variable-names": "error",
|
|
76
77
|
"crisp/no-short-parameters": [
|
|
77
78
|
"error",
|
|
@@ -178,7 +179,9 @@ module.exports = {
|
|
|
178
179
|
// Crisp Vue rules
|
|
179
180
|
"crisp/vue-computed-order": "error",
|
|
180
181
|
"crisp/vue-emits-order": "error",
|
|
182
|
+
"crisp/vue-header-check": "error",
|
|
181
183
|
"crisp/vue-html-quotes": "error",
|
|
184
|
+
"crisp/vue-no-regex-data": "error",
|
|
182
185
|
"crisp/vue-props-declaration-order": "error"
|
|
183
186
|
},
|
|
184
187
|
|
|
@@ -7,6 +7,7 @@ module.exports = {
|
|
|
7
7
|
recommended: false,
|
|
8
8
|
},
|
|
9
9
|
schema: [], // no options
|
|
10
|
+
fixable: "code",
|
|
10
11
|
},
|
|
11
12
|
create(context) {
|
|
12
13
|
return {
|
|
@@ -20,6 +21,13 @@ module.exports = {
|
|
|
20
21
|
context.report({
|
|
21
22
|
node,
|
|
22
23
|
message: "The condition in ternary expressions with an operator should be wrapped in parentheses",
|
|
24
|
+
fix(fixer) {
|
|
25
|
+
const conditionText = sourceCode.getText(node.test);
|
|
26
|
+
return [
|
|
27
|
+
fixer.insertTextBefore(node.test, "("),
|
|
28
|
+
fixer.insertTextAfter(node.test, ")"),
|
|
29
|
+
];
|
|
30
|
+
},
|
|
23
31
|
});
|
|
24
32
|
}
|
|
25
33
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: "suggestion",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Enforce Vue section headers",
|
|
9
|
+
category: "Best Practices",
|
|
10
|
+
recommended: false,
|
|
11
|
+
},
|
|
12
|
+
fixable: null // This rule is not auto-fixable
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
Program(node) {
|
|
18
|
+
const fileName = context.getFilename();
|
|
19
|
+
const fileContent = fs.readFileSync(path.resolve(fileName), "utf8");
|
|
20
|
+
|
|
21
|
+
// Determine the file extension
|
|
22
|
+
const fileExtension = path.extname(fileName);
|
|
23
|
+
|
|
24
|
+
if (fileExtension === ".vue") {
|
|
25
|
+
// Define the headers
|
|
26
|
+
const headers = ["TEMPLATE", "SCRIPT", "STYLE"];
|
|
27
|
+
|
|
28
|
+
// Define the Vue tags
|
|
29
|
+
const vueTags = ["template", "script", "style"];
|
|
30
|
+
|
|
31
|
+
// Check each tag individually
|
|
32
|
+
vueTags.forEach((tag, index) => {
|
|
33
|
+
const tagRegExp = new RegExp(`<${tag}`);
|
|
34
|
+
const headerRegExp = new RegExp(`<!--\\s*\\*{73}\\s*\\n\\s*${headers[index]}\\s*\\n\\s*\\*{73}\\s*-->\\s*\\n\\s*<${tag}`);
|
|
35
|
+
|
|
36
|
+
// If the tag exists without the corresponding header, report an error
|
|
37
|
+
if (tagRegExp.test(fileContent) && !headerRegExp.test(fileContent)) {
|
|
38
|
+
context.report({
|
|
39
|
+
node,
|
|
40
|
+
message: `The '<${tag}>' section must be preceded by the '${headers[index]}' header comment.`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "problem",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "disallow regex in Vue data object",
|
|
6
|
+
category: "Possible Errors",
|
|
7
|
+
recommended: true,
|
|
8
|
+
},
|
|
9
|
+
fixable: "code",
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
create(context) {
|
|
13
|
+
function isRegex(node) {
|
|
14
|
+
if (
|
|
15
|
+
node.type === "NewExpression" &&
|
|
16
|
+
node.callee.name === "RegExp"
|
|
17
|
+
) {
|
|
18
|
+
// Check for RegExp constructor
|
|
19
|
+
return true;
|
|
20
|
+
} else if (
|
|
21
|
+
node.type === "Literal" &&
|
|
22
|
+
node.regex
|
|
23
|
+
) {
|
|
24
|
+
// Check for RegExp literal
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
'Property[key.name="data"] > FunctionExpression > BlockStatement > ReturnStatement > ObjectExpression'(node) {
|
|
33
|
+
const properties = node.properties;
|
|
34
|
+
|
|
35
|
+
properties.forEach((property, index) => {
|
|
36
|
+
if (isRegex(property.value)) {
|
|
37
|
+
context.report({
|
|
38
|
+
node: property,
|
|
39
|
+
message: "Do not use regex in Vue data object. Please move it outside, as a constant.",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|