eslint-plugin-crisp 1.7.17 → 1.7.19

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
@@ -94,7 +94,7 @@ Each item has emojis denoting:
94
94
  | [no-implicit-coercion](https://eslint.org/docs/latest/rules/no-implicit-coercion) | Disallows short notations for type conversion | | 🟢 | 🟣 |
95
95
  | [no-magic-numbers](https://eslint.org/docs/latest/rules/no-magic-numbers) | Disallows magic numbers (except the ones in the context of array indexes and in default value assignments) | 🟠 |
96
96
  | [no-multi-str](https://eslint.org/docs/latest/rules/no-multi-str) | Disallows multiline strings | 🟠 | 🟢 | 🟣 |
97
- | [no-multi-spaces](https://eslint.org/docs/latest/rules/no-multi-spaces) | Disallows multiple consecutive spaces except for indentation | 🟠 | | |
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
100
  | [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) | Enforces `switch` `case`'s content to be enclosed in braces | | 🟢 | 🟣 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.7.17",
3
+ "version": "1.7.19",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
package/recommended.js CHANGED
@@ -73,7 +73,7 @@ export default function configRecommended(pluginCrisp) {
73
73
  "CallExpression": {
74
74
  "arguments": "off"
75
75
  },
76
- "VariableDeclarator": "first",
76
+ "VariableDeclarator": 1,
77
77
  "outerIIFEBody": 0,
78
78
  "ArrayExpression": "first",
79
79
  "ObjectExpression": "first",
@@ -83,7 +83,6 @@ export default function configRecommended(pluginCrisp) {
83
83
  "BinaryExpression",
84
84
  "ConditionalExpression",
85
85
  "IfStatement *",
86
- "VariableDeclarator",
87
86
  "VariableDeclarator > CallExpression",
88
87
  "CallExpression > ArrayExpression"
89
88
  ]
@@ -18,9 +18,10 @@ export default {
18
18
 
19
19
  const patterns = [
20
20
  // Search for `foo && foo.` or `foo && foo[`
21
- // Notice: do not match `foo && foo.bar !==` or `foo && foo[bar] !==`, \
22
- // as the version with optional chaining would be unsafe
23
- /\b(\w\S+)\s&&\s+\1\b[\[\.](?!\w\S+\s\!\=\=)/g,
21
+ // Notice: do not match when the accessed value is compared, as the \
22
+ // version with optional chaining could change the result for falsy \
23
+ // non-nullish values
24
+ /\b(\w\S+)\s&&\s+\1\b[\[\.](?!\S+\s*(?:[=!]==?|[<>]=?))/g,
24
25
 
25
26
  // Search for patterns like `foo || {}).bar`, `foo || {})[`, \
26
27
  // `foo || []).bar` or `foo || [])[`
@@ -0,0 +1,58 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { Linter } from "eslint";
4
+
5
+ import plugin from "../index.js";
6
+
7
+ const recommendedRules = plugin.configs.recommended.find(
8
+ config => config.rules?.["no-multi-spaces"]
9
+ ).rules;
10
+
11
+ test("all recommended configs reject multiple spaces", () => {
12
+ for (const configName of [
13
+ "recommended",
14
+ "recommended-vue",
15
+ "recommended-ts"
16
+ ]) {
17
+ assert.ok(plugin.configs[configName].some(
18
+ config => config.rules?.["no-multi-spaces"] === "error"
19
+ ));
20
+ }
21
+ });
22
+
23
+ test("recommended config removes legacy assignment alignment", () => {
24
+ const input = `class Example {
25
+ constructor() {
26
+ this.a = 1;
27
+ this.long = 2;
28
+ }
29
+ }
30
+
31
+ const first = 1,
32
+ second = 2;
33
+
34
+ const alpha = require("alpha"),
35
+ beta = require("beta");
36
+ `;
37
+ const expected = `class Example {
38
+ constructor() {
39
+ this.a = 1;
40
+ this.long = 2;
41
+ }
42
+ }
43
+
44
+ const first = 1,
45
+ second = 2;
46
+
47
+ const alpha = require("alpha"),
48
+ beta = require("beta");
49
+ `;
50
+ const result = new Linter().verifyAndFix(input, [{
51
+ rules: {
52
+ indent: recommendedRules.indent,
53
+ "no-multi-spaces": recommendedRules["no-multi-spaces"]
54
+ }
55
+ }]);
56
+
57
+ assert.equal(result.output, expected);
58
+ });
@@ -7,6 +7,9 @@ ruleTester.run("enforce-optional", rule, {
7
7
  valid: [
8
8
  "const result = foo?.bar;",
9
9
  "const result = foo && foo.bar !== null;",
10
+ "const result = foo && foo.bar <= maximum;",
11
+ "const result = foo && foo[bar] === value;",
12
+ "if (_header_value && _header_value.length <= ORIGINAL_HEADER_MAX_LENGTH) {}",
10
13
  "const keys = Object.keys(foo || {});",
11
14
  "const filtered = (foo || []).filter(Boolean);"
12
15
  ],