Redundant boolean CASE WHEN
See original GitHub issueI’m sure you have all seen these as I see them often!
select
case
when n > 0 then true else false end as is_positive
from table_a
I would like to add a rule to prefer
select
n > 0 as is_positive
from table_a
A case when statement is redundant if it uses only one when
which is turned into true
or false
However, to add a “fix” the rule should also take in account the following:
select
case
when n >= 0 then false else true end as is_negative
from table_a
which should be turned into
select
case
not(n >= 0) as is_negative
from table_a
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Is setting a boolean to false redundant? - java - Stack Overflow
It is redundant in most cases. The exception is if it's a local variable, in which case it needs to be initialized before...
Read more >Strange case of "Redundant boolean literal in conditional ...
Hello everyone! Today I was working at a comparison operator when I noticed Resharper highlighting the entire function block content.
Read more >Switch statement and using boolean values as cases - SitePoint
Also the default section of this code is redundant; a boolean can only ever be true or false by definition, and both are...
Read more >Boolean literals should not be redundant C# csharpsquid
My suggestion to remove an example#1 style as not a Noncompliant Code. For csharpsquid : S1125 With title Boolean literals should not be ......
Read more >Consensus Theorem in Digital Logic - GeeksforGeeks
The consensus or resolvent of the terms AB and A'C is BC. It is the conjunction of all the unique literals of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
hey so your code shouldn’t be breaking that rule, this rule should only apply to CASE WHENs that have a true/false return statement
I would say the statement you quoted is actually false ^^, I didn’t write
I wrote
That last piece might be unclear but see the examples in the description of the PR, that’s the cases that this rule aimed to fix.
It seems like a bug with the rule, which should be opened as a separate issue
thanks 😃
@rbetzler it’s not spam! Just go ahead an open the PR ^^, then we can have a discussion there.
You documented + tested the rule so I’d say it’s a 🥇 first go