SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Dart

Dart static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your DART code

  • All rules 126
  • Vulnerability4
  • Bug15
  • Security Hotspot8
  • Code Smell99
Filtered: 2 rules found
pitfall
    Impact
      Clean code attribute
        1. Constant patterns should not be used with type literals

           Bug
        2. Control structures should use curly braces

           Code Smell

        Constant patterns should not be used with type literals

        intentionality - logical
        reliability
        Bug
        • pitfall

        Constant patterns should not be used with type literals.

        Why is this an issue?

        How can I fix it?

        More Info

        Using constant patterns with type literals is most likely a mistake.

        For example, the following code

        bool isANumber(Object? o) {
          if (o case num) { // Checks if `o` is `num`, not if it is a `num`
            return true;
          }
          return false;
        }
        

        will always return false for any input value of type num (as in isANumber(42)), and will returns true only when the input is the type num (as in isANumber(int)).

        This is because a constant pattern compares the value of the provided constant against the value being matched, and not against its type.

        The original intent of checking whether an Object? o is a num or not, should be expressed via a typed variable pattern:

        bool isANumber(Object? o) {
          if (o case num n) { // Checks if `o` is a `num` and assigns the cast value to n
            return true;
          }
          return false;
        }
        

        If the intent of the code is to only check whether the input is a num or not, then the n variable is not necessary, and a value discard can be used:

        bool isANumber(Object? o) {
          if (o case num _) { // Checks if `o` is a `num`, and discards the cast value
            return true;
          }
          return false;
        }
        
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.8

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use