eslint-plugin-typefest 1.0.10 → 1.2.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.
- package/README.md +95 -98
- package/dist/_internal/imported-value-symbols.d.ts.map +1 -1
- package/dist/_internal/imported-value-symbols.js +1 -2
- package/dist/_internal/imported-value-symbols.js.map +1 -1
- package/dist/_internal/rule-catalog.d.ts.map +1 -1
- package/dist/_internal/rule-catalog.js +2 -0
- package/dist/_internal/rule-catalog.js.map +1 -1
- package/dist/_internal/rules-registry.d.ts.map +1 -1
- package/dist/_internal/rules-registry.js +0 -6
- package/dist/_internal/rules-registry.js.map +1 -1
- package/dist/plugin.cjs +69 -208
- package/dist/plugin.cjs.map +3 -3
- package/docs/rules/presets/all.md +0 -3
- package/docs/rules/presets/experimental.md +97 -100
- package/docs/rules/presets/index.md +0 -3
- package/docs/rules/presets/strict.md +0 -1
- package/package.json +67 -67
- package/dist/rules/prefer-ts-extras-array-find-last-index.d.ts +0 -13
- package/dist/rules/prefer-ts-extras-array-find-last-index.d.ts.map +0 -1
- package/dist/rules/prefer-ts-extras-array-find-last-index.js +0 -62
- package/dist/rules/prefer-ts-extras-array-find-last-index.js.map +0 -1
- package/dist/rules/prefer-ts-extras-array-find-last.d.ts +0 -13
- package/dist/rules/prefer-ts-extras-array-find-last.d.ts.map +0 -1
- package/dist/rules/prefer-ts-extras-array-find-last.js +0 -65
- package/dist/rules/prefer-ts-extras-array-find-last.js.map +0 -1
- package/dist/rules/prefer-ts-extras-array-find.d.ts +0 -13
- package/dist/rules/prefer-ts-extras-array-find.d.ts.map +0 -1
- package/dist/rules/prefer-ts-extras-array-find.js +0 -62
- package/dist/rules/prefer-ts-extras-array-find.js.map +0 -1
- package/docs/rules/prefer-ts-extras-array-find-last-index.md +0 -108
- package/docs/rules/prefer-ts-extras-array-find-last.md +0 -108
- package/docs/rules/prefer-ts-extras-array-find.md +0 -108
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# prefer-ts-extras-array-find-last-index
|
|
2
|
-
|
|
3
|
-
Prefer [`arrayFindLastIndex`](https://github.com/sindresorhus/ts-extras/blob/main/source/array-find-last-index.ts) from `ts-extras` over `array.findLastIndex(...)`.
|
|
4
|
-
|
|
5
|
-
`arrayFindLastIndex(...)` improves predicate inference in typed arrays.
|
|
6
|
-
|
|
7
|
-
## Targeted pattern scope
|
|
8
|
-
|
|
9
|
-
This rule focuses on direct `array.findLastIndex(predicate)` calls that can be migrated to `arrayFindLastIndex(array, predicate)` with deterministic fixes.
|
|
10
|
-
|
|
11
|
-
- `array.findLastIndex(predicate)` call sites that can use `arrayFindLastIndex(array, predicate)`.
|
|
12
|
-
|
|
13
|
-
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep `arrayFindLastIndex(array, predicate)` migrations safe.
|
|
14
|
-
|
|
15
|
-
## What this rule reports
|
|
16
|
-
|
|
17
|
-
This rule reports `array.findLastIndex(predicate)` call sites when `arrayFindLastIndex(array, predicate)` is the intended replacement.
|
|
18
|
-
|
|
19
|
-
- `array.findLastIndex(predicate)` call sites that can use `arrayFindLastIndex(array, predicate)`.
|
|
20
|
-
|
|
21
|
-
## Why this rule exists
|
|
22
|
-
|
|
23
|
-
`arrayFindLastIndex` standardizes reverse index lookup and keeps call signatures aligned with other `ts-extras` search helpers.
|
|
24
|
-
|
|
25
|
-
- Reverse index scans are explicit at the call site.
|
|
26
|
-
- Search code avoids mixed native/helper patterns.
|
|
27
|
-
- Index-based follow-up logic stays uniform across modules.
|
|
28
|
-
|
|
29
|
-
## ❌ Incorrect
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const index = monitors.findLastIndex((entry) => entry.id === targetId);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## ✅ Correct
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
const index = arrayFindLastIndex(monitors, (entry) => entry.id === targetId);
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Behavior and migration notes
|
|
42
|
-
|
|
43
|
-
- Runtime behavior matches native `Array.prototype.findLastIndex`.
|
|
44
|
-
- Search still proceeds from right to left.
|
|
45
|
-
- If no element matches, the result is `-1`.
|
|
46
|
-
|
|
47
|
-
## Additional examples
|
|
48
|
-
|
|
49
|
-
### ❌ Incorrect — Additional example
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
const index = logs.findLastIndex((entry) => entry.level === "warn");
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### ✅ Correct — Additional example
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const index = arrayFindLastIndex(logs, (entry) => entry.level === "warn");
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### ✅ Correct — Repository-wide usage
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const retryIndex = arrayFindLastIndex(attempts, (attempt) => !attempt.success);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## ESLint flat config example
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import typefest from "eslint-plugin-typefest";
|
|
71
|
-
|
|
72
|
-
export default [
|
|
73
|
-
{
|
|
74
|
-
plugins: { typefest },
|
|
75
|
-
rules: {
|
|
76
|
-
"typefest/prefer-ts-extras-array-find-last-index": "error",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## When not to use it
|
|
83
|
-
|
|
84
|
-
Disable this rule if your codebase has standardized on native `.findLastIndex()`.
|
|
85
|
-
|
|
86
|
-
## Package documentation
|
|
87
|
-
|
|
88
|
-
ts-extras package documentation:
|
|
89
|
-
|
|
90
|
-
`ts-extras@0.17.x` does not currently expose `arrayFindLastIndex` in its published API, so there is no canonical `source/*.ts` link for this helper yet.
|
|
91
|
-
|
|
92
|
-
Reference links:
|
|
93
|
-
|
|
94
|
-
- [`ts-extras` API list (README)](https://github.com/sindresorhus/ts-extras/blob/main/readme.md#api)
|
|
95
|
-
- [`ts-extras` source directory](https://github.com/sindresorhus/ts-extras/tree/main/source)
|
|
96
|
-
|
|
97
|
-
> **Rule catalog ID:** R005
|
|
98
|
-
|
|
99
|
-
## Further reading
|
|
100
|
-
|
|
101
|
-
- [`ts-extras` README](https://github.com/sindresorhus/ts-extras)
|
|
102
|
-
- [`ts-extras` package reference](https://www.npmjs.com/package/ts-extras)
|
|
103
|
-
- [TypeScript Handbook: Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)
|
|
104
|
-
|
|
105
|
-
## Adoption resources
|
|
106
|
-
|
|
107
|
-
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
108
|
-
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# prefer-ts-extras-array-find-last
|
|
2
|
-
|
|
3
|
-
Prefer [`arrayFindLast`](https://github.com/sindresorhus/ts-extras/blob/main/source/array-find-last.ts) from `ts-extras` over `array.findLast(...)`.
|
|
4
|
-
|
|
5
|
-
`arrayFindLast(...)` improves predicate inference and value narrowing in typed arrays.
|
|
6
|
-
|
|
7
|
-
## Targeted pattern scope
|
|
8
|
-
|
|
9
|
-
This rule focuses on direct `array.findLast(predicate)` calls that can be migrated to `arrayFindLast(array, predicate)` with deterministic fixes.
|
|
10
|
-
|
|
11
|
-
- `array.findLast(predicate)` call sites that can use `arrayFindLast(array, predicate)`.
|
|
12
|
-
|
|
13
|
-
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep `arrayFindLast(array, predicate)` migrations safe.
|
|
14
|
-
|
|
15
|
-
## What this rule reports
|
|
16
|
-
|
|
17
|
-
This rule reports `array.findLast(predicate)` call sites when `arrayFindLast(array, predicate)` is the intended replacement.
|
|
18
|
-
|
|
19
|
-
- `array.findLast(predicate)` call sites that can use `arrayFindLast(array, predicate)`.
|
|
20
|
-
|
|
21
|
-
## Why this rule exists
|
|
22
|
-
|
|
23
|
-
`arrayFindLast` makes reverse-direction predicate lookups explicit and keeps them aligned with the `ts-extras` helper style.
|
|
24
|
-
|
|
25
|
-
- Reverse scans are easier to spot during code review.
|
|
26
|
-
- Call signatures stay consistent with `arrayFind` / `arrayFindLastIndex`.
|
|
27
|
-
- Utility code that depends on "latest match" is easier to audit.
|
|
28
|
-
|
|
29
|
-
## ❌ Incorrect
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const monitor = monitors.findLast((entry) => entry.id === targetId);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## ✅ Correct
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
const monitor = arrayFindLast(monitors, (entry) => entry.id === targetId);
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Behavior and migration notes
|
|
42
|
-
|
|
43
|
-
- Runtime behavior matches native `Array.prototype.findLast`.
|
|
44
|
-
- Search direction remains right-to-left.
|
|
45
|
-
- Result is the matching element, or `undefined` if no match exists.
|
|
46
|
-
|
|
47
|
-
## Additional examples
|
|
48
|
-
|
|
49
|
-
### ❌ Incorrect — Additional example
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
const latest = events.findLast((entry) => entry.type === "login");
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### ✅ Correct — Additional example
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const latest = arrayFindLast(events, (entry) => entry.type === "login");
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### ✅ Correct — Repository-wide usage
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const trailingError = arrayFindLast(logs, (entry) => entry.level === "error");
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## ESLint flat config example
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import typefest from "eslint-plugin-typefest";
|
|
71
|
-
|
|
72
|
-
export default [
|
|
73
|
-
{
|
|
74
|
-
plugins: { typefest },
|
|
75
|
-
rules: {
|
|
76
|
-
"typefest/prefer-ts-extras-array-find-last": "error",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## When not to use it
|
|
83
|
-
|
|
84
|
-
Disable this rule if your team intentionally uses native `.findLast()` everywhere.
|
|
85
|
-
|
|
86
|
-
## Package documentation
|
|
87
|
-
|
|
88
|
-
ts-extras package documentation:
|
|
89
|
-
|
|
90
|
-
`ts-extras@0.17.x` does not currently expose `arrayFindLast` in its published API, so there is no canonical `source/*.ts` link for this helper yet.
|
|
91
|
-
|
|
92
|
-
Reference links:
|
|
93
|
-
|
|
94
|
-
- [`ts-extras` API list (README)](https://github.com/sindresorhus/ts-extras/blob/main/readme.md#api)
|
|
95
|
-
- [`ts-extras` source directory](https://github.com/sindresorhus/ts-extras/tree/main/source)
|
|
96
|
-
|
|
97
|
-
> **Rule catalog ID:** R004
|
|
98
|
-
|
|
99
|
-
## Further reading
|
|
100
|
-
|
|
101
|
-
- [`ts-extras` README](https://github.com/sindresorhus/ts-extras)
|
|
102
|
-
- [`ts-extras` package reference](https://www.npmjs.com/package/ts-extras)
|
|
103
|
-
- [TypeScript Handbook: Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)
|
|
104
|
-
|
|
105
|
-
## Adoption resources
|
|
106
|
-
|
|
107
|
-
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
108
|
-
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# prefer-ts-extras-array-find
|
|
2
|
-
|
|
3
|
-
Prefer [`arrayFind`](https://github.com/sindresorhus/ts-extras/blob/main/source/array-find.ts) from `ts-extras` over `array.find(...)`.
|
|
4
|
-
|
|
5
|
-
`arrayFind(...)` improves predicate inference and value narrowing in typed arrays.
|
|
6
|
-
|
|
7
|
-
## Targeted pattern scope
|
|
8
|
-
|
|
9
|
-
This rule focuses on direct `array.find(predicate)` calls that can be migrated to `arrayFind(array, predicate)` with deterministic fixes.
|
|
10
|
-
|
|
11
|
-
- `array.find(predicate)` call sites that can use `arrayFind(array, predicate)`.
|
|
12
|
-
|
|
13
|
-
Alias indirection, wrapper helpers, and non-canonical call shapes are excluded to keep `arrayFind(array, predicate)` migrations safe.
|
|
14
|
-
|
|
15
|
-
## What this rule reports
|
|
16
|
-
|
|
17
|
-
This rule reports `array.find(predicate)` call sites when `arrayFind(array, predicate)` is the intended replacement.
|
|
18
|
-
|
|
19
|
-
- `array.find(predicate)` call sites that can use `arrayFind(array, predicate)`.
|
|
20
|
-
|
|
21
|
-
## Why this rule exists
|
|
22
|
-
|
|
23
|
-
`arrayFind` keeps predicate-driven lookup aligned with the other `ts-extras` helper APIs and improves inference in generic code.
|
|
24
|
-
|
|
25
|
-
- Predicate call sites are standardized across modules.
|
|
26
|
-
- Result types are easier to follow in utility layers.
|
|
27
|
-
- Local type assertions after `find` calls are reduced.
|
|
28
|
-
|
|
29
|
-
## ❌ Incorrect
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
const monitor = monitors.find((entry) => entry.id === targetId);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## ✅ Correct
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
const monitor = arrayFind(monitors, (entry) => entry.id === targetId);
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Behavior and migration notes
|
|
42
|
-
|
|
43
|
-
- Runtime behavior matches native `Array.prototype.find`.
|
|
44
|
-
- Search still returns the first matching element.
|
|
45
|
-
- If no element matches, the result is `undefined`.
|
|
46
|
-
|
|
47
|
-
## Additional examples
|
|
48
|
-
|
|
49
|
-
### ❌ Incorrect — Additional example
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
const user = users.find((item) => item.id === userId);
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### ✅ Correct — Additional example
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const user = arrayFind(users, (item) => item.id === userId);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### ✅ Correct — Repository-wide usage
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const firstError = arrayFind(logs, (entry) => entry.level === "error");
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## ESLint flat config example
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import typefest from "eslint-plugin-typefest";
|
|
71
|
-
|
|
72
|
-
export default [
|
|
73
|
-
{
|
|
74
|
-
plugins: { typefest },
|
|
75
|
-
rules: {
|
|
76
|
-
"typefest/prefer-ts-extras-array-find": "error",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## When not to use it
|
|
83
|
-
|
|
84
|
-
Disable this rule if your team requires native `.find()` for consistency with existing shared APIs.
|
|
85
|
-
|
|
86
|
-
## Package documentation
|
|
87
|
-
|
|
88
|
-
ts-extras package documentation:
|
|
89
|
-
|
|
90
|
-
`ts-extras@0.17.x` does not currently expose `arrayFind` in its published API, so there is no canonical `source/*.ts` link for this helper yet.
|
|
91
|
-
|
|
92
|
-
Reference links:
|
|
93
|
-
|
|
94
|
-
- [`ts-extras` API list (README)](https://github.com/sindresorhus/ts-extras/blob/main/readme.md#api)
|
|
95
|
-
- [`ts-extras` source directory](https://github.com/sindresorhus/ts-extras/tree/main/source)
|
|
96
|
-
|
|
97
|
-
> **Rule catalog ID:** R003
|
|
98
|
-
|
|
99
|
-
## Further reading
|
|
100
|
-
|
|
101
|
-
- [`ts-extras` README](https://github.com/sindresorhus/ts-extras)
|
|
102
|
-
- [`ts-extras` package reference](https://www.npmjs.com/package/ts-extras)
|
|
103
|
-
- [TypeScript Handbook: Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)
|
|
104
|
-
|
|
105
|
-
## Adoption resources
|
|
106
|
-
|
|
107
|
-
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
108
|
-
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|