diff --git a/rules/prefer-array-find.js b/rules/prefer-array-find.js index 5a7376f0f9..191f4dfe03 100644 --- a/rules/prefer-array-find.js +++ b/rules/prefer-array-find.js @@ -113,7 +113,7 @@ const fixDestructuring = (source, node) => { // `AssignmentExpression` always starts with `[` or `(`, so we don't need check ASI const needParenthesize = isAssign && !isParenthesized(node, source) && - assignmentNeedParenthesize(element.type !== 'AssignmentPattern' ? element : element.left); + assignmentNeedParenthesize(element.type === 'AssignmentPattern' ? element.left : element); if (element.type !== 'AssignmentPattern') { return { @@ -141,7 +141,7 @@ const fixDestructuring = (source, node) => { fixer.insertTextAfter(right, ` ${operator} ${defaultValueText}`), needParenthesize && fixer.insertTextAfter(node, ')') ].filter(Boolean); - } + }; return { suggest: [ @@ -152,7 +152,7 @@ const fixDestructuring = (source, node) => { { messageId: MESSAGE_ID_USE_LOGICAL_OR_OPERATOR, fix: fix('||') - }, + } ] }; }; diff --git a/test/prefer-array-find.js b/test/prefer-array-find.js index 7fde3509b5..ef06267ec1 100644 --- a/test/prefer-array-find.js +++ b/test/prefer-array-find.js @@ -134,8 +134,8 @@ ruleTester.run('prefer-array-find', rule, { } ] }); -// `const [foo] =` +// `const [foo] =` ruleTester.run('prefer-array-find', rule, { valid: [ // Test `const [item] = …` @@ -527,18 +527,18 @@ ruleTester.run('prefer-array-find', rule, { ] }); -// Test `const foo = array.filter(); foo[0];` +// `const foo = array.filter(); foo[0];` ruleTester.run('prefer-array-find', rule, { valid: [ - `const foo = array.find(bar), first = foo[0];`, - `const foo = array.filter(bar), first = foo[+0];`, - `const foo = array.filter(bar), first = a[foo][0];`, - `const foo = array.filter(bar), first = foo[-0];`, - `const foo = array.filter(bar), first = foo[1-1];`, - `const foo = array.filter(bar), first = foo["0"];`, - `const foo = array.filter(bar), first = foo.first;`, - `foo = array.filter(bar); const first = foo[+0];`, - `const {foo} = array.filter(bar), first = foo[0];`, + 'const foo = array.find(bar), first = foo[0];', + 'const foo = array.filter(bar), first = foo[+0];', + 'const foo = array.filter(bar), first = a[foo][0];', + 'const foo = array.filter(bar), first = foo[-0];', + 'const foo = array.filter(bar), first = foo[1-1];', + 'const foo = array.filter(bar), first = foo["0"];', + 'const foo = array.filter(bar), first = foo.first;', + 'foo = array.filter(bar); const first = foo[+0];', + 'const {foo} = array.filter(bar), first = foo[0];', outdent` const foo = array.filter(bar); doSomething(foo); @@ -616,7 +616,7 @@ ruleTester.run('prefer-array-find', rule, { } `, errors: [{messageId: MESSAGE_ID_DECLARATION}] - }, + } ] });