eslint-plugin-crisp 1.7.20 → 1.7.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/README.md CHANGED
@@ -105,6 +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
109
  | [padded-blocks](https://eslint.org/docs/latest/rules/padded-blocks) | Disallows empty lines at the beginning and ending of blocks | 🟠 | 🟢 | 🟣 |
109
110
  | [padding-line-between-statements](https://eslint.org/docs/latest/rules/padding-line-between-statements) | Requires padding lines between various statements | 🟠 | 🟢 | 🟣 |
110
111
  | [prefer-arrow-callback](https://eslint.org/docs/latest/rules/prefer-arrow-callback) | Requires using arrow functions for callbacks | | 🟢 | 🟣 |
@@ -116,7 +117,7 @@ Each item has emojis denoting:
116
117
  | [semi-spacing](https://eslint.org/docs/latest/rules/semi-spacing) | Disallows space before semicolons, enforces spaces after | | 🟢 | 🟣 |
117
118
  | [space-before-blocks](https://eslint.org/docs/latest/rules/space-before-blocks) | Enforces consistent spacing before blocks | 🟠 | 🟢 | 🟣 |
118
119
  | [space-in-parens](https://eslint.org/docs/latest/rules/space-in-parens) | Enforces zero spaces inside of parentheses | 🟠 | 🟢 | 🟣 |
119
- | [space-infix-ops](https://eslint.org/docs/latest/rules/space-infix-ops) | Enforces spaces around infix operators | | 🟢 | 🟣 |
120
+ | [space-infix-ops](https://eslint.org/docs/latest/rules/space-infix-ops) | Enforces spaces around infix operators | 🟠 | 🟢 | 🟣 |
120
121
 
121
122
  #### Crisp JS rules
122
123
 
@@ -141,7 +142,6 @@ Each item has emojis denoting:
141
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 | 🟠 | 🟢 | 🟣 |
142
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 | 🟠 | 🟢 | 🟣 |
143
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 | 🟠 | 🟢 | 🟣 |
144
- | [crisp/no-space-in-default-parameters](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-space-in-default-parameters.js) | Disallows space before or after `=` in default parameters | 🟠 |
145
145
  | [crisp/no-snake-case](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-snake-case.js) | Disallows snake_case | | 🟢 | 🟣 |
146
146
  | [crisp/no-useless-template-literals](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-useless-template-literals.js) | Disallows unnecessary use of template literals | | 🟢 | 🟣 |
147
147
  | [crisp/no-var-in-blocks](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-var-in-blocks.js) | Disallows `var` declarations inside function, method, or class block | 🟠 | 🟢 | 🟣 |
package/index.js CHANGED
@@ -29,7 +29,6 @@ import ruleNewlineAfterSwitchCase from "./rules/newline-after-switch-case.js";
29
29
  import ruleNoAsync from "./rules/no-async.js";
30
30
  import ruleNoExtraLineWithinFunction from "./rules/no-extra-line-within-function.js";
31
31
  import ruleNoInlineFunctionInTernary from "./rules/no-inline-function-in-ternary.js";
32
- import ruleNoSpaceInDefaultParameters from "./rules/no-space-in-default-parameters.js";
33
32
  import ruleNoUselessTemplateLiterals from "./rules/no-useless-template-literals.js";
34
33
  import ruleNoVarInBlocks from "./rules/no-var-in-blocks.js";
35
34
  import ruleNoShortParameters from "./rules/no-short-parameters.js";
@@ -107,7 +106,6 @@ const plugin = {
107
106
  "no-async": ruleNoAsync,
108
107
  "no-extra-line-within-function": ruleNoExtraLineWithinFunction,
109
108
  "no-inline-function-in-ternary": ruleNoInlineFunctionInTernary,
110
- "no-space-in-default-parameters": ruleNoSpaceInDefaultParameters,
111
109
  "no-var-in-blocks": ruleNoVarInBlocks,
112
110
  "no-useless-template-literals": ruleNoUselessTemplateLiterals,
113
111
  "no-short-parameters": ruleNoShortParameters,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.7.20",
3
+ "version": "1.7.22",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
package/recommended-ts.js CHANGED
@@ -119,6 +119,7 @@ export default function configRecommendedTS(pluginCrisp) {
119
119
  }
120
120
  ],
121
121
  "object-curly-spacing": ["error", "always"],
122
+ "object-shorthand": ["error", "never"],
122
123
  "padded-blocks": ["error", "never"],
123
124
  "padding-line-between-statements": [
124
125
  "error",
@@ -126,6 +126,7 @@ export default function configRecommendedVue(pluginCrisp) {
126
126
  }
127
127
  ],
128
128
  "object-curly-spacing": ["error", "always"],
129
+ "object-shorthand": ["error", "never"],
129
130
  "padded-blocks": ["error", "never"],
130
131
  "padding-line-between-statements": [
131
132
  "error",
package/recommended.js CHANGED
@@ -123,6 +123,7 @@ export default function configRecommended(pluginCrisp) {
123
123
  }
124
124
  ],
125
125
  "object-curly-spacing": ["error", "always"],
126
+ "object-shorthand": ["error", "never"],
126
127
  "padded-blocks": ["error", "never"],
127
128
  "padding-line-between-statements": [
128
129
  "error",
@@ -153,6 +154,7 @@ export default function configRecommended(pluginCrisp) {
153
154
  "semi-style": ["error", "last"],
154
155
  "space-before-blocks": "error",
155
156
  "space-in-parens": ["error", "never"],
157
+ "space-infix-ops": "error",
156
158
 
157
159
  // Crisp JS rules
158
160
  "crisp/align-comments": "error",
@@ -179,7 +181,6 @@ export default function configRecommended(pluginCrisp) {
179
181
  "exceptions": ["_", "$"]
180
182
  }
181
183
  ],
182
- "crisp/no-space-in-default-parameters": "error",
183
184
  "crisp/one-space-after-operator": [
184
185
  "error",
185
186
 
@@ -20,6 +20,53 @@ 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
+ test("recommended config uses standard default parameter spacing", () => {
58
+ const result = new Linter().verifyAndFix(
59
+ "function greet(name=\"World\") {}",
60
+ [{
61
+ rules: {
62
+ "space-infix-ops": recommendedRules["space-infix-ops"]
63
+ }
64
+ }]
65
+ );
66
+
67
+ assert.equal(result.output, "function greet(name = \"World\") {}");
68
+ });
69
+
23
70
  test("recommended config removes legacy assignment alignment", () => {
24
71
  const input = `class Example {
25
72
  constructor() {
@@ -1,24 +0,0 @@
1
- export default {
2
- create: function(context) {
3
- return {
4
- "FunctionDeclaration, FunctionExpression, ArrowFunctionExpression, MethodDefinition": function(node) {
5
- (node.params || []).forEach(param => {
6
- if (param.type === "AssignmentPattern") {
7
- const sourceCode = context.sourceCode;
8
- const operatorToken = sourceCode.getFirstTokenBetween(param.left, param.right, token => token.value === "=");
9
-
10
- if (
11
- sourceCode.getTokenBefore(operatorToken).range[1] !== operatorToken.range[0] ||
12
- sourceCode.getTokenAfter(operatorToken).range[0] !== operatorToken.range[1]
13
- ) {
14
- context.report({
15
- node,
16
- message: "There should be no space before or after = in default parameters"
17
- });
18
- }
19
- }
20
- });
21
- }
22
- };
23
- }
24
- };
@@ -1,40 +0,0 @@
1
- import rule from "../../rules/no-space-in-default-parameters.js";
2
- import createRuleTester from "../rule-tester.js";
3
-
4
- const ruleTester = createRuleTester();
5
-
6
- ruleTester.run("no-space-in-default-parameters", rule, {
7
- valid: [
8
- "function greet(name=\"World\") {}",
9
- "const greet = (name=\"World\") => name;",
10
- "const object = { greet(name=\"World\") {} };",
11
- "function required(name) {}"
12
- ],
13
-
14
- invalid: [
15
- {
16
- code: "function greet(name =\"World\") {}",
17
- errors: [
18
- {
19
- message: "There should be no space before or after = in default parameters"
20
- }
21
- ]
22
- },
23
- {
24
- code: "const greet = (name= \"World\") => name;",
25
- errors: [
26
- {
27
- message: "There should be no space before or after = in default parameters"
28
- }
29
- ]
30
- },
31
- {
32
- code: "class Greeter { greet(name = \"World\") {} }",
33
- errors: [
34
- {
35
- message: "There should be no space before or after = in default parameters"
36
- }
37
- ]
38
- }
39
- ]
40
- });