Skip to content

Commit fd32312

Browse files
committed
fix: #26 never try to replace indexOf/lastIndexOf with eachother.
Also add the new type flag for the rules
1 parent aa7e11c commit fd32312

File tree

10 files changed

+754
-1404
lines changed

10 files changed

+754
-1404
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,20 @@ const characterArray = Array.from("string");
163163
Avoid reversing the array and running a method on it if there is an equivalent
164164
of the method operating on the array from the other end.
165165

166-
There are two operations with such equivalents: `indexOf` with `lastIndexOf` and
167-
`reduce` with `reduceRight`.
166+
There are two operations with such equivalents: `reduce` with `reduceRight`.
168167

169168
This rule is auto fixable.
170169

171170
#### Examples
172171
Code that triggers this rule:
173172
```js
174-
const lastIndex = array.reverse().indexOf(1);
175-
176-
const firstIndex = array.reverse().lastIndexOf(1);
177-
178173
const sum = array.reverse().reduce((p, c) => p + c, 0);
179174

180175
const reverseSum = array.reverse().reduceRight((p, c) => p + c, 0);
181176
```
182177

183178
Code that doesn't trigger this rule:
184179
```js
185-
const lastIndex = array.lastIndexOf(1);
186-
187-
const firstIndex = array.indexOf(1);
188-
189180
const sum = array.reduce((p, c) => p + c, 0);
190181

191182
const reverseSum = array.reduceRight((p, c) => p + c, 0);

0 commit comments

Comments
 (0)