eslint-plugin-remeda 1.4.0 → 1.6.0

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.
@@ -1,4 +1,8 @@
1
- # Collection Method Value
1
+ # remeda/collection-method-value
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using a Remeda collection method, the expression should be used (e.g. assigning to a variable or check in a condition), unless it's a method meant for side effects (e.g. `forEach` or `forOwn`) which should NOT be used.
4
8
 
@@ -1,4 +1,8 @@
1
- # Collection Return Statement
1
+ # remeda/collection-return
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using a Remeda collection method that isn't forEach, the iteratee should return a value, otherwise it could result in either unclear code or unexpected results.
4
8
 
@@ -1,4 +1,8 @@
1
- # Prefer constant
1
+ # remeda/prefer-constant
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When you want a function that always returns the same value, it can be more concise to use `R.constant`.
4
8
 
@@ -9,6 +13,10 @@ This rule takes two arguments:
9
13
  - whether or not to check arrow functions
10
14
  - whether or not to check function declarations (named functions)
11
15
 
16
+ ## Options
17
+
18
+ ## Examples
19
+
12
20
  The following patterns are considered warnings:
13
21
 
14
22
  ```js
@@ -1,4 +1,8 @@
1
- # Prefer noop
1
+ # remeda/prefer-do-nothing
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When defining an empty function (e.g. for callbacks) it can be more readable to use `R.doNothing()` or `R.constant(undefined)` instead. Use `R.doNothing()` if you need to return void, otherwise use `R.constant(undefined)`.
4
8
 
@@ -1,4 +1,8 @@
1
- # Prefer filter
1
+ # remeda/prefer-filter
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using R.forEach with a single `if` statement, you should probably use `R.filter` or `R.some` instead.
4
8
 
@@ -6,6 +10,10 @@ When using R.forEach with a single `if` statement, you should probably use `R.fi
6
10
 
7
11
  This rule takes one argument, maximum path length (default is 3).
8
12
 
13
+ ## Options
14
+
15
+ ## Examples
16
+
9
17
  The following patterns are considered warnings:
10
18
 
11
19
  ```js
@@ -1,4 +1,8 @@
1
- # Prefer find
1
+ # remeda/prefer-find
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using R.filter and accessing the first or last result, you should probably use `R.find` or `R.findLast`, respectively.
4
8
 
@@ -1,4 +1,8 @@
1
- # Prefer [`R.flatMap`] over consecutive [`R.map`] and [`R.flat`]
1
+ # remeda/prefer-flat-map
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using [`R.map`] and [`R.flat`], it can be more concise to use [`R.flatMap`] instead.
4
8
 
@@ -0,0 +1,89 @@
1
+ # remeda/prefer-has-atleast
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
6
+
7
+ When checking if an array has at least a certain number of elements, it is more expressive to use `R.hasAtLeast` instead of comparing the array's length with a number.
8
+
9
+ Additionally, when checking if an array is not empty, it's better to use `R.hasAtLeast(data, 1)` instead of negated `R.isEmpty(data)` patterns (`!R.isEmpty(data)`) because the TypeScript type narrowing works better with `hasAtLeast`.
10
+
11
+ ## Rule Details
12
+
13
+ The following patterns are considered warnings:
14
+
15
+ ```js
16
+ // Array length comparisons
17
+ if (array.length >= 3) {
18
+ // ...
19
+ }
20
+
21
+ if (array.length > 2) {
22
+ // ...
23
+ }
24
+
25
+ if (3 <= array.length) {
26
+ // ...
27
+ }
28
+
29
+ if (2 < array.length) {
30
+ // ...
31
+ }
32
+
33
+ // Negated isEmpty patterns (problematic for TypeScript type narrowing)
34
+ if (!R.isEmpty(array)) {
35
+ // TypeScript won't narrow the array type here
36
+ }
37
+
38
+ if (R.isEmpty(array) === false) {
39
+ // Same issue with type narrowing
40
+ }
41
+
42
+ if (R.isEmpty(array) !== true) {
43
+ // Same issue with type narrowing
44
+ }
45
+ ```
46
+
47
+ The following patterns are not considered warnings:
48
+
49
+ ```js
50
+ // Using hasAtLeast
51
+ if (R.hasAtLeast(array, 3)) {
52
+ // ...
53
+ }
54
+
55
+ // For non-empty checks, use hasAtLeast with 1
56
+ if (R.hasAtLeast(array, 1)) {
57
+ // TypeScript correctly narrows the type here
58
+ }
59
+
60
+ // Other length comparisons
61
+ if (array.length === 3) {
62
+ // ...
63
+ }
64
+
65
+ if (array.length < 3) {
66
+ // ...
67
+ }
68
+
69
+ if (array.length <= 3) {
70
+ // ...
71
+ }
72
+
73
+ // Regular isEmpty checks are fine
74
+ if (R.isEmpty(array)) {
75
+ // ...
76
+ }
77
+ ```
78
+
79
+ ## Type Safety Improvement
80
+
81
+ From Remeda documentation:
82
+
83
+ > "This guard [isEmpty] doesn't work negated because of typescript limitations! If you need to check that an array is not empty, use R.hasAtLeast(data, 1) and not !R.isEmpty(data). For strings and objects there's no way in typescript to narrow the result to a non-empty type."
84
+
85
+ Using `R.hasAtLeast(array, 1)` instead of `!R.isEmpty(array)` improves type safety because TypeScript can properly narrow the array type to a non-empty array, which helps prevent "possibly undefined" errors when accessing array elements.
86
+
87
+ ## When Not To Use It
88
+
89
+ If you do not want to enforce using `R.hasAtLeast` or prefer the explicit array length comparison, you should not use this rule. However, consider enabling it at least for the negated `isEmpty` patterns to improve type safety.
@@ -1,4 +1,10 @@
1
- # Prefer R.isEmpty
1
+ # remeda/prefer-is-empty
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6
+
7
+ <!-- end auto-generated rule header -->
2
8
 
3
9
  When checking if a collection is empty or no, it is more concise to use R.isEmpty instead.
4
10
 
@@ -1,6 +1,6 @@
1
- # Prefer R.isNil
1
+ # Prefer R.isNullish
2
2
 
3
- When checking that a value is undefined or null (but not false or ''), it is more concise to use R.isNil instead.
3
+ When checking that a value is undefined or null (but not false or ''), it is more concise to use R.isNullish instead.
4
4
 
5
5
  ## Rule Details
6
6
 
@@ -17,11 +17,11 @@ var t = x === undefined || x === null;
17
17
  The following patterns are not considered warnings:
18
18
 
19
19
  ```js
20
- var t = R.isNil(x);
20
+ var t = R.isNullish(x);
21
21
 
22
22
  var t = R.isUndefined(x) || R.isNull(y);
23
23
  ```
24
24
 
25
25
  ## When Not To Use It
26
26
 
27
- If you do not want to enforce using `R.isNil`, and prefer using specific checks instead.
27
+ If you do not want to enforce using `R.isNullish`, and prefer using specific checks instead.
@@ -1,4 +1,8 @@
1
- # Prefer map
1
+ # remeda/prefer-map
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using `R.forEach` that pushes into an array, it could improve readability to use `R.map` instead.
4
8
 
@@ -1,4 +1,10 @@
1
- # Prefer nullish coalescing over checking a ternary with !isNil.
1
+ # remeda/prefer-nullish-coalescing
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6
+
7
+ <!-- end auto-generated rule header -->
2
8
 
3
9
  When checking if a variable is not nil as a test for a ternary equation, it's more coincise to just use the nullish coalescing operator.
4
10
 
@@ -9,13 +15,13 @@ This rule takes no arguments.
9
15
  The following patterns are considered warnings:
10
16
 
11
17
  ```js
12
- const myExpression = !isNil(myVar) ? myVar : myOtherVar;
18
+ const myExpression = !isNullish(myVar) ? myVar : myOtherVar;
13
19
  ```
14
20
 
15
21
  The following patterns are not considered warnings:
16
22
 
17
23
  ```js
18
- const myExpression = !isNil(myVar) ? mySecondVar : myThirdVar;
24
+ const myExpression = !isNullish(myVar) ? mySecondVar : myThirdVar;
19
25
 
20
26
  const myExpression = myVar ?? myOtherVar;
21
27
  ```
@@ -1,4 +1,8 @@
1
- # Prefer Remeda typecheck
1
+ # remeda/prefer-remeda-typecheck
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  Getting the specific type of a variable or expression can be done with `typeof` or `instanceof`. However, it's often more expressive to use the Remeda equivalent function
4
8
 
@@ -1,4 +1,8 @@
1
- # Prefer R.some
1
+ # remeda/prefer-some
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When comparing the index of an item with an `findIndex` method, it can be more expressive to use `R.some`, when only the sole existence of a matching item is taken into account.
4
8
 
@@ -1,4 +1,8 @@
1
- # Prefer R.times
1
+ # remeda/prefer-times
2
+
3
+ 💼 This rule is enabled in the ✅ `recommended` config.
4
+
5
+ <!-- end auto-generated rule header -->
2
6
 
3
7
  When using `R.map` in which the iteratee does not have any arguments, it's better to use `R.times`.
4
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-remeda",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "author": "Andrea Pontrandolfo <andrea.pontra@gmail.com>",
5
5
  "description": "ESLint plugin for Remeda library.",
6
6
  "type": "module",
@@ -16,6 +16,8 @@
16
16
  "attw": "attw --pack .",
17
17
  "qa": "pnpm typecheck && pnpm test && pnpm knip && pnpm publint && attw",
18
18
  "nuke": "rm -rf node_modules pnpm-lock.yaml",
19
+ "update:eslint-docs": "eslint-doc-generator",
20
+ "lint:eslint-docs": "pnpm update:eslint-docs -- --check",
19
21
  "semantic-release": "pnpm build && semantic-release"
20
22
  },
21
23
  "files": [
@@ -26,8 +28,14 @@
26
28
  "exports": {
27
29
  "./package.json": "./package.json",
28
30
  ".": {
29
- "import": "./dist/index.js",
30
- "default": "./dist/index.cjs"
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "require": "./dist/index.cjs"
38
+ }
31
39
  }
32
40
  },
33
41
  "repository": {
@@ -40,23 +48,26 @@
40
48
  "eslint": ">=9.0.0"
41
49
  },
42
50
  "devDependencies": {
43
- "@arethetypeswrong/cli": "^0.15.4",
51
+ "@arethetypeswrong/cli": "^0.17.4",
52
+ "@sherifforg/cli": "^8.2.0",
44
53
  "@types/lodash-es": "^4.17.12",
45
- "@types/node": "^20.14.9",
46
- "@vitest/coverage-v8": "^2.0.3",
47
- "@vitest/ui": "^2.0.3",
48
- "eslint": "9.10.0",
49
- "eslint-config-sheriff": "^21.2.0",
50
- "eslint-define-config": "^2.1.0",
51
- "eslint-plugin-eslint-plugin": "^6.2.0",
52
- "eslint-vitest-rule-tester": "^0.3.3",
53
- "knip": "^5.29.1",
54
+ "@types/node": "^22.14.0",
55
+ "@vitest/coverage-v8": "^3.1.1",
56
+ "@vitest/ui": "^3.1.1",
57
+ "eslint": "9.24.0",
58
+ "eslint-config-sheriff": "^27.0.0",
59
+ "eslint-doc-generator": "^2.1.2",
60
+ "eslint-plugin-eslint-plugin": "^6.4.0",
61
+ "eslint-vitest-rule-tester": "^2.2.0",
62
+ "lodash-es": "^4.17.21",
63
+ "knip": "^5.49.0",
54
64
  "prettier": "^3.3.2",
55
- "publint": "^0.2.10",
65
+ "publint": "^0.3.10",
56
66
  "semantic-release": "^24.0.0",
57
- "tsup": "^8.2.4",
67
+ "tsup": "^8.4.0",
58
68
  "typescript": "^5.5.2",
59
- "vitest": "^2.0.3"
69
+ "@typescript-eslint/utils": "^8.29.0",
70
+ "vitest": "^3.1.1"
60
71
  },
61
72
  "engines": {
62
73
  "node": ">=20"
@@ -75,7 +86,5 @@
75
86
  "fp"
76
87
  ],
77
88
  "license": "MIT",
78
- "dependencies": {
79
- "lodash-es": "^4.17.21"
80
- }
89
+ "sideEffects": false
81
90
  }