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

Enhancement: [strict-boolean-expressions] options for operators/positions #8239

Closed
4 tasks done
That-Guy977 opened this issue Jan 12, 2024 · 2 comments
Closed
4 tasks done
Labels
duplicate This issue or pull request already exists enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@That-Guy977
Copy link

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://typescript-eslint.io/rules/strict-boolean-expressions

Description

strict-boolean-expressions should offer granular options for allowing/disallowing non-booleans in certain positions, such as the conditional position of a if statement or ternary, or when using specific boolean operators.

Fail

/* eslint
  "@typescript-eslint/strict-boolean-expressions": ["error", { "!": false }]
*/

!0n;
!{};

/* eslint
  "@typescript-eslint/strict-boolean-expressions": ["error", {
    "!": { "allowNumber": true, "allowString": false }
  }]
*/

!"";
// unspecified operators/options use default
!0n;
0n && true;

Pass

/* eslint
  "@typescript-eslint/strict-boolean-expressions": ["error", { "!": true }]
*/

!0n;
!{};

/* eslint
  "@typescript-eslint/strict-boolean-expressions": ["error", {
    "!": { "allowNumber": true, "allowString": false }
  }]
*/

!0;
// unspecified operators use default
if ("");
0 && "";

Additional Info

This is motivated by a recent inquiry on the TypeScript Community Discord server, wanting A to be linted, in favor of B:

declare const x: number;

// A
<>{x && <SomeElement />}</>;

// B
<>{!!x && <SomeElement />}</>

Currently, with allowNumber: false, the rule will correctly error on A, but will not allow the preferred fix.

I'm not sure what format of options would be ideal for granular control while also being compatible with the current options, so the options in the example are just for demonstration.

@That-Guy977 That-Guy977 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 Jan 12, 2024
@bradzacher
Copy link
Member

Duplicate of #2770

@bradzacher bradzacher marked this as a duplicate of #2770 Jan 12, 2024
@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2024
@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for maintainers to take a look labels Jan 12, 2024
@That-Guy977
Copy link
Author

I might be missing the point of that issue, isn't that more specifically targeting JSX? This is a suggestion for more granularity within the option, just motivated by the same issue

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2024
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 enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants