eslint-plugin-crisp 1.0.21 → 1.0.22

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 CHANGED
@@ -31,6 +31,7 @@ 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"),
35
36
  "vue-props-declaration-order": require("./rules/vue-props-declaration-order")
36
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Custom EsLint Rules for Crisp",
5
5
  "main": "index.js",
6
6
  "author": "Crisp IM SAS",
@@ -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,6 +179,7 @@ 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",
182
184
  "crisp/vue-props-declaration-order": "error"
183
185
  },
@@ -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
+ };