Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [prefer-find] Add support for checking ternaries #8379

Closed
4 tasks done
kirkwaiblinger opened this issue Feb 5, 2024 · 1 comment · Fixed by #8421
Closed
4 tasks done

Bug: [prefer-find] Add support for checking ternaries #8379

kirkwaiblinger opened this issue Feb 5, 2024 · 1 comment · Fixed by #8421
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://main--typescript-eslint.netlify.app/rules/prefer-find

Description

This addresses a minor omission when I did the PR for this rule (#8216).

I forgot to add support for checking ternary branches. I've made a quick branch that would add support. See aa43ec6

Fail

(Math.random < 0.5 ? [1, 2, 3].filter(x => x % 2 === 0) : [4, 5, 6].filter(x => x % 2 === 0))[0]

Pass

Math.random < 0.5 ? [1, 2, 3].find(x => x % 2 === 0) : [4, 5, 6].find(x => x % 2 === 0)

Additional Info

No response

@kirkwaiblinger kirkwaiblinger added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 5, 2024
@JoshuaKGoldberg
Copy link
Member

Yeah makes sense, good catch. I'd even consider this a bug - there's no reason why the rule wouldn't also want to catch these.

If we were to consider this a feature, it would maybe arguably be a breaking change. But let's get this in quick as a bug. 😄

@JoshuaKGoldberg JoshuaKGoldberg changed the title Enhancement: [prefer-find] Add support for checking ternaries Bug: [prefer-find] Add support for checking ternaries Feb 8, 2024
@JoshuaKGoldberg JoshuaKGoldberg added bug Something isn't working accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Feb 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants