You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/rules/prefer-includes.md
+32-28
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence
1
+
# Prefer `.includes()` over `.indexOf()`, `.lastIndexOf()`, and `Array#some()` when checking for existence or non-existence
2
2
3
3
💼 This rule is enabled in the ✅ `recommended`[config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).
4
4
@@ -7,7 +7,7 @@
7
7
<!-- end auto-generated rule header -->
8
8
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->
9
9
10
-
All built-ins have `.includes()` in addition to `.indexOf()`. Prefer `.includes()` over comparing the value of `.indexOf()`.
10
+
All built-ins have `.includes()` in addition to `.indexOf()` and `.lastIndexOf()`. Prefer `.includes()` over comparing the value of `.indexOf()` and `.lastIndexOf()`.
11
11
12
12
[`Array#some()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) is intended for more complex needs. If you are just looking for the index where the given item is present, the code can be simplified to use [`Array#includes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes). This applies to any search with a literal, a variable, or any expression that doesn't have any explicit side effects. However, if the expression you are looking for relies on an item related to the function (its arguments, the function self, etc.), the case is still valid.
13
13
@@ -16,99 +16,103 @@ This rule is fixable, unless the search expression in `Array#some()` has side ef
|[prefer-includes](docs/rules/prefer-includes.md)| Prefer `.includes()` over `.indexOf()`and `Array#some()` when checking for existence or non-existence.| ✅ | 🔧 | 💡 |
191
+
|[prefer-includes](docs/rules/prefer-includes.md)| Prefer `.includes()` over `.indexOf()`, `.lastIndexOf()`, and `Array#some()` when checking for existence or non-existence. | ✅ | 🔧 | 💡 |
192
192
|[prefer-json-parse-buffer](docs/rules/prefer-json-parse-buffer.md)| Prefer reading a JSON file as a buffer. || 🔧 ||
193
193
|[prefer-keyboard-event-key](docs/rules/prefer-keyboard-event-key.md)| Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`. | ✅ | 🔧 ||
194
194
|[prefer-logical-operator-over-ternary](docs/rules/prefer-logical-operator-over-ternary.md)| Prefer using a logical operator over a ternary. | ✅ || 💡 |
0 commit comments