eslint-plugin-crisp 1.7.22 → 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
@@ -97,7 +97,7 @@ Each item has emojis denoting:
97
97
  | [no-multi-spaces](https://eslint.org/docs/latest/rules/no-multi-spaces) | Disallows multiple consecutive spaces except for indentation | 🟠 | 🟢 | 🟣 |
98
98
  | [no-multiple-empty-lines](https://eslint.org/docs/latest/rules/no-multiple-empty-lines) | Allows a maximum of 1 consecutive empty lines | | 🟢 | 🟣 |
99
99
  | [no-mixed-spaces-and-tabs](https://eslint.org/docs/latest/rules/no-mixed-spaces-and-tabs) | Disallows mixed spaces and tabs for indentation | 🟠 | 🟢 | 🟣 |
100
- | [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) | Enforces `switch` `case`'s content to be enclosed in braces | | 🟢 | 🟣 |
100
+ | [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) | Disallows specific syntax patterns according to each configuration's coding conventions | | 🟢 | 🟣 |
101
101
  | [no-tabs](https://eslint.org/docs/latest/rules/no-tabs) | Disallows tabs | 🟠 | 🟢 | 🟣 |
102
102
  | [no-trailing-spaces](https://eslint.org/docs/latest/rules/no-trailing-spaces) | Disallows trailing whitespace at the end of lines | 🟠 | 🟢 | 🟣 |
103
103
  | [no-undef](https://eslint.org/docs/latest/rules/no-undef) | Disallows use of undeclared variables | 🟠 | 🟢 | 🟣 |
@@ -105,7 +105,7 @@ Each item has emojis denoting:
105
105
  | [no-unsafe-optional-chaining](https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining) | Disallows use of optional chaining in contexts where the `undefined` value is not allowed | 🟠 | 🟢 | 🟣 |
106
106
  | [object-curly-newline](https://eslint.org/docs/latest/rules/object-curly-newline) | Requires line breaks after opening and before closing braces | 🟠 | 🟢 | 🟣 |
107
107
  | [object-curly-spacing](https://eslint.org/docs/latest/rules/object-curly-spacing) | Requires spacing inside of braces | 🟠 | 🟢 | 🟣 |
108
- | [object-shorthand](https://eslint.org/docs/latest/rules/object-shorthand) | Disallows shorthand properties and methods in object literals, requiring explicit keys and values even when their names match | 🟠 | 🟢 | 🟣 |
108
+ | [object-shorthand](https://eslint.org/docs/latest/rules/object-shorthand) | Disallows shorthand properties and methods in object literals, requiring explicit keys and values even when their names match | 🟠 | | 🟣 |
109
109
  | [padded-blocks](https://eslint.org/docs/latest/rules/padded-blocks) | Disallows empty lines at the beginning and ending of blocks | 🟠 | 🟢 | 🟣 |
110
110
  | [padding-line-between-statements](https://eslint.org/docs/latest/rules/padding-line-between-statements) | Requires padding lines between various statements | 🟠 | 🟢 | 🟣 |
111
111
  | [prefer-arrow-callback](https://eslint.org/docs/latest/rules/prefer-arrow-callback) | Requires using arrow functions for callbacks | | 🟢 | 🟣 |
@@ -138,7 +138,7 @@ Each item has emojis denoting:
138
138
  | [crisp/methods-ordering](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/methods-ordering.js) | Ensures methods order according to their access: `public` then `protected` then `private` | 🟠 | 🟢 | 🟣 |
139
139
  | [crisp/multiline-comment-end-backslash](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/multiline-comment-end-backslash.js) | Enforces multiline comments to end with a backslash | 🟠 | 🟢 | 🟣 |
140
140
  | [crisp/newline-after-switch-case](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/newline-after-switch-case.js) | Requires newline between switch cases | 🟠 | 🟢 | 🟣 |
141
- | [crisp/no-async](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-async.js) | Disallows the use of `async/syntax`, in favor of `Promise` | 🟠 | 🟢 |
141
+ | [crisp/no-async](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-async.js) | Disallows `async`/`await` in favor of `Promise` | 🟠 | | |
142
142
  | [crisp/no-extra-line-within-function](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-extra-line-within-function.js) | Allows at most one empty line between declarations within functions | 🟠 | 🟢 | 🟣 |
143
143
  | [crisp/no-inline-function-in-ternary](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-inline-function-in-ternary.js) | Disallows inline functions in ternary branches | 🟠 | 🟢 | 🟣 |
144
144
  | [crisp/no-short-parameters](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-short-parameters.js) | Disallows one-character parameter names | 🟠 | 🟢 | 🟣 |
@@ -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.22",
3
+ "version": "1.7.24",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
package/recommended-ts.js CHANGED
@@ -102,6 +102,7 @@ export default function configRecommendedTS(pluginCrisp) {
102
102
  "no-restricted-syntax": [
103
103
  "error",
104
104
 
105
+ // Require switch case contents to be enclosed in braces
105
106
  {
106
107
  "selector": "SwitchCase > *.consequent[type!='BlockStatement']",
107
108
  "message": "Switch cases without braces are disallowed."
@@ -108,6 +108,7 @@ export default function configRecommendedVue(pluginCrisp) {
108
108
  "no-restricted-syntax": [
109
109
  "error",
110
110
 
111
+ // Require switch case contents to be enclosed in braces
111
112
  {
112
113
  "selector": "SwitchCase > *.consequent[type!='BlockStatement']",
113
114
  "message": "Switch cases without braces are disallowed."
@@ -126,7 +127,6 @@ export default function configRecommendedVue(pluginCrisp) {
126
127
  }
127
128
  ],
128
129
  "object-curly-spacing": ["error", "always"],
129
- "object-shorthand": ["error", "never"],
130
130
  "padded-blocks": ["error", "never"],
131
131
  "padding-line-between-statements": [
132
132
  "error",
@@ -175,7 +175,7 @@ export default function configRecommendedVue(pluginCrisp) {
175
175
  "crisp/methods-ordering": "error",
176
176
  "crisp/multiline-comment-end-backslash": "error",
177
177
  "crisp/newline-after-switch-case": "error",
178
- "crisp/no-async": "error",
178
+ "crisp/no-async": "off",
179
179
  "crisp/no-extra-line-within-function": "error",
180
180
  "crisp/no-inline-function-in-ternary": "error",
181
181
  "crisp/no-short-parameters": [
@@ -397,6 +397,7 @@ export default function configRecommendedVue(pluginCrisp) {
397
397
  "crisp/vue-no-component-class-shorthand": "error",
398
398
  "crisp/vue-no-mixed-class": "error",
399
399
  "crisp/vue-no-mixed-class-shorthand": "error",
400
+ "crisp/vue-no-multiline-object-shorthand": "error",
400
401
  "crisp/vue-no-name-option": "error",
401
402
  "crisp/vue-no-regex-data": "error",
402
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,40 +20,6 @@ test("all recommended configs reject multiple spaces", () => {
20
20
  }
21
21
  });
22
22
 
23
- test("all recommended configs reject and expand object shorthand", () => {
24
- for (const configName of [
25
- "recommended",
26
- "recommended-vue",
27
- "recommended-ts"
28
- ]) {
29
- const rules = plugin.configs[configName].find(
30
- config => config.rules?.["object-shorthand"]
31
- )?.rules;
32
-
33
- assert.deepEqual(rules?.["object-shorthand"], ["error", "never"]);
34
-
35
- const linter = new Linter();
36
- const config = [{
37
- rules: {
38
- "object-shorthand": rules["object-shorthand"]
39
- }
40
- }];
41
- const input = "const value = 1; const object = { value, method() {} };";
42
- const messages = linter.verify(input, config);
43
-
44
- assert.equal(messages.length, 2);
45
- assert.ok(messages.every(message => message.ruleId === "object-shorthand"));
46
-
47
- const result = linter.verifyAndFix(input, config);
48
-
49
- assert.equal(
50
- result.output,
51
- "const value = 1; const object = { value: value, method: function() {} };"
52
- );
53
- assert.deepEqual(result.messages, []);
54
- }
55
- });
56
-
57
23
  test("recommended config uses standard default parameter spacing", () => {
58
24
  const result = new Linter().verifyAndFix(
59
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
+ });