CodeQL 文档

无效条件

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

点击查看 CodeQL 代码库中的查询

此规则查找“then”分支为空且没有“else”分支的 If 语句。这些语句通常是未实现的框架代码,应予以实现,或者是应删除的实际未使用代码。

建议

then 分支中可能缺少语句,或者 If 语句可能可以完全删除。

示例

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");
        }
    }
}

参考

  • ©GitHub 公司
  • 条款
  • 隐私