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
 
Tags
    Impact
      Clean code attribute
        1. "mounted" should be checked before using a "BuildContext " after an async operation

           Bug
        2. "void" variables should not be assigned a value

           Bug
        3. Constant patterns should not be used with type literals

           Bug
        4. "is!" should be used instead of "!is"

           Bug
        5. Getters should not be recursive

           Bug
        6. Nullable type parameter values should not be null checked with `!`

           Bug
        7. Regular expressions should be syntactically valid

           Bug
        8. Color definitions should be valid

           Bug
        9. "const" modifier should not be redundant

           Bug
        10. Setters should not declare return types

           Bug
        11. Inappropriate collection calls should not be made

           Bug
        12. Unnecessary equality checks should not be made

           Bug
        13. The original exception object should be rethrown

           Bug
        14. "==" operator and "hashCode()" should be overridden in pairs

           Bug
        15. Jump statements should not occur in "finally" blocks

           Bug

        "void" variables should not be assigned a value

        intentionality - logical
        reliability
        Bug

          Variables of type void should not be assigned a value.

          Why is this an issue?

          How can I fix it?

          More Info

          Unlike other languages where void is the absence of a type (and related value), void in Dart is a type, which is not compatible with any other type, since it is conceptually a supertype of Object.

          Therefore, in Dart it’s possible to write the following code:

          void x = 3; // A variable of type void can be assigned a value of type int
          void f(void x) => x; // A function that takes a void input argument and returns it as output
          

          The variable x declared above, and the result of f(x) are effectively of type void. However, while void variables can be declared, initialized and even computed, they cannot be used by any function that expects a non-void type, by the very definition of void type.

          print(x); // Error: This expression has type 'void' and can't be used.
          print(f(x)); // Error: This expression has type 'void' and can't be used.
          

          Therefore, assigning a value to a variable of type void is almost certainly a mistake.

          For example, in the cases where the type is not known, the variable should have not been declared as void, but as dynamic:

          • void variables can be assigned values of any type, but cannot be assigned to any non-void variable
          • dynamic variables, like void ones, can be assigned values of any type, and, unlike void variables, can be assigned to any non-dynamic variable

          Notice that, because void is a type, it can be used as a valid type parameter for a generic class, and that can lead to indirect or "hidden" void assignments:

          class Wrapper<T> {
            T value;
            Wrapper(this.value);
          }
          
          void main() {
              Wrapper<void> w = Wrapper(3); // This is a "hidden" assignment to void
              w.value = 3; // This is an explicit assignment to a field of type void
          }
          

          Another example of a "hidden" assignment to void is when assigning generic unconstrained type parameters in generic methods:

          void f<T>(T x, T y) {
            y = x; // This is a "hidden" assignment to void
            T z;
            z = x; // This too, is a "hidden" assignment to void
          }
          

          However, such scenarios are not reported by the rule because for any non-void type T, the assignment is valid. On the other hand, calling the function f with anything other than void parameters will be reported as an issue:

          f(42, 'a string'); // Both 1st and 2nd parameters are non compliant
          
            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