eslint-plugin-crisp 1.0.60 → 1.0.62

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
@@ -36,6 +36,7 @@ module.exports = {
36
36
  "vue-header-check": require("./rules/vue-header-check"),
37
37
  "vue-html-quotes": require("./rules/vue-html-quotes"),
38
38
  "vue-no-regex-data": require("./rules/vue-no-regex-data"),
39
- "vue-props-declaration-order": require("./rules/vue-props-declaration-order")
39
+ "vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
40
+ "vue-props-declaration-multiline": require("./rules/vue-props-declaration-multiline")
40
41
  }
41
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -321,6 +321,7 @@ module.exports = {
321
321
  "crisp/vue-header-check": "error",
322
322
  "crisp/vue-html-quotes": "error",
323
323
  "crisp/vue-no-regex-data": "error",
324
+ "crisp/vue-props-declaration-multiline": "error",
324
325
  "crisp/vue-props-declaration-order": "error"
325
326
  }
326
327
  }
@@ -0,0 +1,46 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "enforce multi-line declaration for Vue props",
6
+ category: "Stylistic Issues",
7
+ recommended: false,
8
+ },
9
+ fixable: "code",
10
+ schema: [], // no options
11
+ },
12
+
13
+ create(context) {
14
+ return {
15
+ 'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) {
16
+ node.properties.forEach(prop => {
17
+ // Ensuring we only target the top-level prop definitions
18
+ if (prop.value.type === "ObjectExpression") {
19
+ const propDefinition = prop.value;
20
+
21
+ // Check if the prop definition is on a single line
22
+ if (propDefinition.loc.start.line === propDefinition.loc.end.line) {
23
+ context.report({
24
+ node: prop,
25
+ message: "Props should be declared in multiple lines.",
26
+
27
+ fix(fixer) {
28
+ const sourceCode = context.getSourceCode();
29
+ const propText = sourceCode.getText(propDefinition);
30
+
31
+ // Construct the multi-line version of the prop
32
+ const expandedProp = propText
33
+ .replace("{", "{\n")
34
+ .replace("}", "\n}")
35
+ .replace(/, /g, ",\n");
36
+
37
+ return fixer.replaceText(propDefinition, expandedProp);
38
+ }
39
+ });
40
+ }
41
+ }
42
+ });
43
+ }
44
+ };
45
+ }
46
+ };