Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkwaiblinger committed Feb 6, 2024
1 parent 1e86670 commit a8d2c21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
11 changes: 5 additions & 6 deletions packages/eslint-plugin/src/rules/prefer-find.ts
Expand Up @@ -153,15 +153,14 @@ export default createRule({
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#parameters
*/
function isTreatedAsZeroByArrayAt(value: unknown): boolean {
let asNumber: number;

try {
asNumber = Number(value);
} catch (e) {
// This will happen if trying to convert a symbol.
// This would cause the number constructor coercion to throw. Other static
// values are safe.
if (typeof value === 'symbol') {
return false;
}

const asNumber = Number(value);

if (isNaN(asNumber)) {
return true;
}
Expand Down
8 changes: 2 additions & 6 deletions packages/eslint-plugin/tests/rules/prefer-find.test.ts
Expand Up @@ -68,12 +68,8 @@ ruleTester.run('prefer-find', rule, {
const s = Symbol.for("Don't throw!");
arr.filter(item => item === 'aha').at(s);
`,
`
[1, 2, 3].filter(x => x)[Symbol('0')];
`,
`
[1, 2, 3].filter(x => x)[Symbol.for('0')];
`,
"[1, 2, 3].filter(x => x)[Symbol('0')];",
"[1, 2, 3].filter(x => x)[Symbol.for('0')];",
],

invalid: [
Expand Down

0 comments on commit a8d2c21

Please sign in to comment.