Skip to content

Commit

Permalink
fix: #26 never try to replace indexOf/lastIndexOf with eachother.
Browse files Browse the repository at this point in the history
Also add the new type flag for the rules
  • Loading branch information
freaktechnik committed Feb 15, 2019
1 parent aa7e11c commit fd32312
Show file tree
Hide file tree
Showing 10 changed files with 754 additions and 1,404 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,20 @@ const characterArray = Array.from("string");
Avoid reversing the array and running a method on it if there is an equivalent
of the method operating on the array from the other end.

There are two operations with such equivalents: `indexOf` with `lastIndexOf` and
`reduce` with `reduceRight`.
There are two operations with such equivalents: `reduce` with `reduceRight`.

This rule is auto fixable.

#### Examples
Code that triggers this rule:
```js
const lastIndex = array.reverse().indexOf(1);

const firstIndex = array.reverse().lastIndexOf(1);

const sum = array.reverse().reduce((p, c) => p + c, 0);

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

Code that doesn't trigger this rule:
```js
const lastIndex = array.lastIndexOf(1);

const firstIndex = array.indexOf(1);

const sum = array.reduce((p, c) => p + c, 0);

const reverseSum = array.reduceRight((p, c) => p + c, 0);
Expand Down
Loading

0 comments on commit fd32312

Please sign in to comment.