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

Rule proposal: prefer-consecutive-conditions #2416

Closed
zanminkian opened this issue Jul 31, 2024 · 1 comment
Closed

Rule proposal: prefer-consecutive-conditions #2416

zanminkian opened this issue Jul 31, 2024 · 1 comment
Labels

Comments

@zanminkian
Copy link
Contributor

zanminkian commented Jul 31, 2024

Description

When comparing a variable code below will be easier to understand.

if(0.1<foo<0.5) {
}

But JavasScript and TypeScript can't. The alternative is to write code like:

if(0.1<foo && foo<0.5) {
}

Fail

const flag = foo > 0.1 && foo < 0.5;
const flag = foo > 0.1 && 0.5 > foo;
const flag = 0.1 < foo && 0.5 > foo;

if(foo > 0.1 && foo < 0.5) {}
if(foo > 0.1 && 0.5 > foo) {}
if(0.1 < foo && 0.5 > foo) {}

Pass

const flag = 0.1 < foo && foo < 0.5;
if(0.1 < foo && foo < 0.5){}

Proposed rule name

prefer-consecutive-conditions

Additional Info

No response

@sindresorhus
Copy link
Owner

I'm going to pass on this. In my opinion, this results in less readable code.

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants