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

[strict-boolean-expressions]: New feature, this rule should additionally check value return by callbacks inside Array.some, Array.every, etc #4766

Closed
iliubinskii opened this issue Mar 30, 2022 · 4 comments
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@iliubinskii
Copy link

Repro

[1, 2].some(x => x); // Fail

[1, 2].some(x => Boolean(x)); // Ok

Expected Result

With new rule ("strict-array-callback-return-type") should complain about non-boolean return type

@iliubinskii iliubinskii added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 30, 2022
@JoshuaKGoldberg
Copy link
Member

This seems like a very specific rule tailored to a very specific use-case. Can you give us a bit more info on why you'd like to see this?

We generally avoid adding rules that target unique situations to typescript-eslint core. You can always write your own rule using the APIs described in https://typescript-eslint.io/docs/development/custom-rules.

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Mar 30, 2022
@iliubinskii
Copy link
Author

Can you give us a bit more info on why you'd like to see this?

Sure, this rule has the same motivation as @typescript-eslint/strict-boolean-expressions rule.

Consider the following example:

interface Obj {
  value?: string;
}

function f(x: Obj): void {
  if (x.value) console.log("True");
}

function g(x: Obj[]): void {
  if (x.some(item => item.value)) console.log("True");
}

In the above example function "f" gets warning from "@typescript-eslint/strict-boolean-expressions":
image

The value returned from calbacks in Array.some, Array.every, etc is also used as condition.
So, it would be good to check it the same way as @typescript-eslint/strict-boolean-expressions checks condition inside "if".
So, what I suggest is that function "g" should get the same warning as function "f" for "item.value".

@iliubinskii iliubinskii changed the title Feature request: new rule "strict-array-callback-return-type" [strict-boolean-expressions]: New feature, this rule should additionally check value return by callbacks inside Array.some, Array.every, etc Mar 31, 2022
@iliubinskii
Copy link
Author

I have changed subject of this issue, because after writing longer description I see that this should not be a new rule, but rather an additional option to @typescript-eslint/strict-boolean-expressions rule.

@bradzacher
Copy link
Member

Duplicate of #1038

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed awaiting response Issues waiting for a reply from the OP or another party labels Mar 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants