eslint-plugin-crisp 1.7.23 → 1.7.24

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 CHANGED
@@ -247,6 +247,7 @@ Each item has emojis denoting:
247
247
  | [crisp/vue-no-component-class-shorthand](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-component-class-shorthand.js) | Disallows Pug class shorthand on Vue components | | 🟢 |
248
248
  | [crisp/vue-no-mixed-class](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-mixed-class.js) | Disallows using both `class` and `:class` on the same element | | 🟢 |
249
249
  | [crisp/vue-no-mixed-class-shorthand](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-mixed-class-shorthand.js) | Disallows mixing Pug class shorthand and class attributes | | 🟢 | |
250
+ | [crisp/vue-no-multiline-object-shorthand](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-multiline-object-shorthand.js) | Requires explicit property keys and values in multiline objects; allows single-line objects, methods, direct component registrations and direct default export objects | | 🟢 | |
250
251
  | [crisp/vue-no-name-option](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-name-option.js) | Disallows explicit component names in Vue single-file components | | 🟢 |
251
252
  | [crisp/vue-no-regex-data](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-regex-data.js) | Disallows regular expressions to be declared in Vue data object | | 🟢 |
252
253
  | [crisp/vue-props-declaration-line-break](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-line-break.js) | Enforces line break between type and default function in prop definition | | 🟢 |
package/index.js CHANGED
@@ -56,6 +56,7 @@ import ruleVueNameProp from "./rules/vue-name-prop.js";
56
56
  import ruleVueNoComponentClassShorthand from "./rules/vue-no-component-class-shorthand.js";
57
57
  import ruleVueNoMixedClass from "./rules/vue-no-mixed-class.js";
58
58
  import ruleVueNoMixedClassShorthand from "./rules/vue-no-mixed-class-shorthand.js";
59
+ import ruleVueNoMultilineObjectShorthand from "./rules/vue-no-multiline-object-shorthand.js";
59
60
  import ruleVueNoNameOption from "./rules/vue-no-name-option.js";
60
61
  import ruleVueNoRegexData from "./rules/vue-no-regex-data.js";
61
62
  import ruleVuePiniaActionSingleParameter from "./rules/vue-pinia-action-single-parameter.js";
@@ -133,6 +134,7 @@ const plugin = {
133
134
  "vue-no-component-class-shorthand": ruleVueNoComponentClassShorthand,
134
135
  "vue-no-mixed-class": ruleVueNoMixedClass,
135
136
  "vue-no-mixed-class-shorthand": ruleVueNoMixedClassShorthand,
137
+ "vue-no-multiline-object-shorthand": ruleVueNoMultilineObjectShorthand,
136
138
  "vue-no-name-option": ruleVueNoNameOption,
137
139
  "vue-no-regex-data": ruleVueNoRegexData,
138
140
  "vue-pinia-action-single-parameter": ruleVuePiniaActionSingleParameter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.7.23",
3
+ "version": "1.7.24",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -112,13 +112,6 @@ export default function configRecommendedVue(pluginCrisp) {
112
112
  {
113
113
  "selector": "SwitchCase > *.consequent[type!='BlockStatement']",
114
114
  "message": "Switch cases without braces are disallowed."
115
- },
116
-
117
- // Require explicit object property keys and values, but allow shorthand methods
118
- // Exempt direct entries in components objects and direct export default objects
119
- {
120
- "selector": "ObjectExpression > Property[shorthand=true]:not(Property[key.name='components'] > ObjectExpression > Property):not(Property[key.value='components'] > ObjectExpression > Property):not(ExportDefaultDeclaration > ObjectExpression > Property)",
121
- "message": "Use explicit keys and values instead of shorthand properties."
122
115
  }
123
116
  ],
124
117
  "no-tabs": "error",
@@ -404,6 +397,7 @@ export default function configRecommendedVue(pluginCrisp) {
404
397
  "crisp/vue-no-component-class-shorthand": "error",
405
398
  "crisp/vue-no-mixed-class": "error",
406
399
  "crisp/vue-no-mixed-class-shorthand": "error",
400
+ "crisp/vue-no-multiline-object-shorthand": "error",
407
401
  "crisp/vue-no-name-option": "error",
408
402
  "crisp/vue-no-regex-data": "error",
409
403
  "crisp/vue-pinia-action-single-parameter": "error",
@@ -0,0 +1,49 @@
1
+ export default {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "Require explicit property keys and values in multiline objects, except component registrations and default exports."
6
+ },
7
+ schema: [],
8
+ messages: {
9
+ explicitProperty: "Use explicit keys and values instead of shorthand properties in multiline objects."
10
+ }
11
+ },
12
+
13
+ create(context) {
14
+ return {
15
+ ObjectExpression(node) {
16
+ if (node.loc.start.line === node.loc.end.line) {
17
+ return;
18
+ }
19
+
20
+ const parent = node.parent;
21
+
22
+ if (parent.type === "ExportDefaultDeclaration") {
23
+ return;
24
+ }
25
+
26
+ if (
27
+ parent.type === "Property" &&
28
+ parent.value === node &&
29
+ !parent.computed &&
30
+ (
31
+ (parent.key.type === "Identifier" && parent.key.name === "components") ||
32
+ (parent.key.type === "Literal" && parent.key.value === "components")
33
+ )
34
+ ) {
35
+ return;
36
+ }
37
+
38
+ for (const property of node.properties) {
39
+ if (property.type === "Property" && property.shorthand) {
40
+ context.report({
41
+ node: property,
42
+ messageId: "explicitProperty"
43
+ });
44
+ }
45
+ }
46
+ }
47
+ };
48
+ }
49
+ };
@@ -20,77 +20,6 @@ test("all recommended configs reject multiple spaces", () => {
20
20
  }
21
21
  });
22
22
 
23
- test("JS and TS recommended configs reject and expand property and method shorthand", () => {
24
- for (const configName of ["recommended", "recommended-ts"]) {
25
- const rules = plugin.configs[configName].find(
26
- config => config.rules?.["object-shorthand"]
27
- ).rules;
28
-
29
- assert.deepEqual(rules["object-shorthand"], ["error", "never"]);
30
- assert.ok(!JSON.stringify(rules["no-restricted-syntax"] ?? []).includes("shorthand"));
31
-
32
- const linter = new Linter();
33
- const config = [{ rules: { "object-shorthand": rules["object-shorthand"] } }];
34
- const input = "const object = { value, method() {} };";
35
- const messages = linter.verify(input, config);
36
-
37
- assert.equal(messages.length, 2);
38
- assert.ok(messages.every(message => message.ruleId === "object-shorthand"));
39
-
40
- const result = linter.verifyAndFix(input, config);
41
-
42
- assert.equal(result.output, "const object = { value: value, method: function() {} };");
43
- assert.deepEqual(result.messages, []);
44
- }
45
- });
46
-
47
- test("Vue recommended config rejects property shorthand but allows methods and components", () => {
48
- for (const configName of ["recommended-vue"]) {
49
- const rules = plugin.configs[configName].find(
50
- config => config.rules?.["no-restricted-syntax"]
51
- ).rules;
52
-
53
- assert.ok(plugin.configs[configName].every(
54
- config => !Object.hasOwn(config.rules ?? {}, "object-shorthand")
55
- ));
56
-
57
- const linter = new Linter();
58
- const config = [{
59
- rules: {
60
- "no-restricted-syntax": rules["no-restricted-syntax"]
61
- }
62
- }];
63
-
64
- for (const input of [
65
- "const object = { value };",
66
- "this.setTreeContent({ section, locale, path, value: contentData });",
67
- "const object = { components: { nested: { value } } };",
68
- "export default { nested: { value } };",
69
- "const object = { value }; export default object;",
70
- "defineComponent({ data() { return { value }; } });"
71
- ]) {
72
- const messages = linter.verify(input, config);
73
-
74
- assert.ok(messages.length > 0, `${configName}: ${input}`);
75
- assert.ok(messages.every(message =>
76
- message.ruleId === "no-restricted-syntax" &&
77
- message.message === "Use explicit keys and values instead of shorthand properties."
78
- ));
79
- }
80
-
81
- for (const input of [
82
- "const object = { value: value, method() {} };",
83
- "export default { base, form, initiate, layouts, common, hugo, editor, settings };",
84
- "export default { components: { ContentNavigate }, mounted() {} };",
85
- "export default defineComponent({ components: { ContentNavigate }, data() { return {}; } });",
86
- "defineComponent({ 'components': { ContentNavigate } });",
87
- "const { value } = object;"
88
- ]) {
89
- assert.deepEqual(linter.verify(input, config), [], `${configName}: ${input}`);
90
- }
91
- }
92
- });
93
-
94
23
  test("recommended config uses standard default parameter spacing", () => {
95
24
  const result = new Linter().verifyAndFix(
96
25
  "function greet(name=\"World\") {}",
@@ -0,0 +1,60 @@
1
+ import rule from "../../rules/vue-no-multiline-object-shorthand.js";
2
+ import createRuleTester from "../rule-tester.js";
3
+ import vueParser from "vue-eslint-parser";
4
+
5
+ const ruleTester = createRuleTester();
6
+
7
+ ruleTester.run("vue-no-multiline-object-shorthand", rule, {
8
+ valid: [
9
+ "this.removeFeedAlertLocal({ feedAlertId });",
10
+ "const payload = { section, locale };",
11
+ "call(\n { feedAlertId }\n);",
12
+ "const payload = {\n section: section,\n method() {}\n};",
13
+ "export default {\n base,\n form\n};",
14
+ "defineComponent({ components: {\n ContentNavigate\n} });",
15
+ "defineComponent({ 'components': {\n ContentNavigate\n} });",
16
+ "const { section } = payload;",
17
+ "const payload = {\n ...other\n};",
18
+ {
19
+ filename: "example.vue",
20
+ languageOptions: { parser: vueParser },
21
+ code: "<script>export default { methods: { remove() { this.removeFeedAlertLocal({ feedAlertId }); } } };</script>"
22
+ }
23
+ ],
24
+
25
+ invalid: [
26
+ {
27
+ code: "this.removeFeedAlertLocal({\n feedAlertId\n});",
28
+ errors: [{ messageId: "explicitProperty" }]
29
+ },
30
+ {
31
+ code: "const payload = {\n section, locale\n};",
32
+ errors: [
33
+ { messageId: "explicitProperty" },
34
+ { messageId: "explicitProperty" }
35
+ ]
36
+ },
37
+ {
38
+ code: "export default { nested: {\n value\n} };",
39
+ errors: [{ messageId: "explicitProperty" }]
40
+ },
41
+ {
42
+ code: "defineComponent({ components: { nested: {\n value\n} } });",
43
+ errors: [{ messageId: "explicitProperty" }]
44
+ },
45
+ {
46
+ code: "defineComponent({ data() { return {\n value\n}; } });",
47
+ errors: [{ messageId: "explicitProperty" }]
48
+ },
49
+ {
50
+ code: "const payload = { [components]: {\n value\n} };",
51
+ errors: [{ messageId: "explicitProperty" }]
52
+ },
53
+ {
54
+ filename: "example.vue",
55
+ languageOptions: { parser: vueParser },
56
+ code: "<script>export default { methods: { remove() { this.removeFeedAlertLocal({\n feedAlertId\n}); } } };</script>",
57
+ errors: [{ messageId: "explicitProperty" }]
58
+ }
59
+ ]
60
+ });