CodeQL documentation

Futile conditional

ID: cs/useless-if-statement
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - maintainability
   - readability
   - useless-code
Query suites:
   - csharp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds If-statements where the “then” branch is empty and there is no “else” branch. These statements are usually unimplemented skeleton code that should be implemented, or real unused code that should be removed.

Recommendation

There might be missing statements in the then-branch or the If-statement might be able to be removed completely.

Example

class FutileConditional
{
    static void Main(string[] args)
    {
        if (args.Length > 10) ; // BAD
        if (args.Length > 8)
        {
            // BAD
        }
        if (args.Length > 6)
        {
            // GOOD: because of else-branch
        }
        else
        {
            System.Console.WriteLine("hello");
        }
    }
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy