Skip to content

Commit

Permalink
Do not check LogicalExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Dec 24, 2020
1 parent 705ada0 commit 8d3e7fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/rules/prefer-array-some.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ if (array.find(element => element === '🦄')) {
const foo = array.find(element => element === '🦄') ? bar : baz;
```

```js
const foo = array.find(element => element === '🦄') || bar;
```

## Pass

```js
if (array.some(element => element === '🦄')) {
//
}
```

```js
const foo = array.find(element => element === '🦄') || bar;
```
2 changes: 1 addition & 1 deletion rules/prefer-array-some.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const arrayFindCallSelector = methodSelector({
const create = context => {
return {
[arrayFindCallSelector](node) {
if (isBooleanNode(node) || node.parent.type === 'LogicalExpression') {
if (isBooleanNode(node)) {
node = node.callee.property;
context.report({
node,
Expand Down
7 changes: 4 additions & 3 deletions test/prefer-array-some.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test({
valid: [
// Not `boolean`
'const bar = foo.find(fn)',
'const bar = foo.find(fn) || baz',

// Not matched `CallExpression`
...[
Expand Down Expand Up @@ -65,10 +66,10 @@ test({
suggestionOutput: 'console.log(foo /* comment 1 */ . /* comment 2 */ some /* comment 3 */ (fn) ? a : b)'
}),
// This should not be reported, but `jQuery.find()` is always `truly`,
// It should not use in a LogicalExpression
// It should not use as a boolean
invalidCase({
code: 'const el = anotherElement || jQuery.find(".outer > div");',
suggestionOutput: 'const el = anotherElement || jQuery.some(".outer > div");'
code: 'if (jQuery.find(".outer > div")) {}',
suggestionOutput: 'if (jQuery.some(".outer > div")) {}'
}),
// Actual messages
{
Expand Down

0 comments on commit 8d3e7fb

Please sign in to comment.