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: 5 rules found
performance
    Impact
      Clean code attribute
        1. Literal constructors parameters of @immutable classes should be const

           Code Smell
        2. @immutable classes should only have const constructors

           Code Smell
        3. Unnecessary use of "toList" with spread operator

           Code Smell
        4. For elements should be preferred to Map.fromIterable

           Code Smell
        5. "static final" declarations should be "const" instead

           Code Smell

        For elements should be preferred to Map.fromIterable

        intentionality - efficient
        maintainability
        Code Smell
        • performance

        for elements should be preferred to fromIterable when building a Map from an Iterable.

        Why is this an issue?

        How can I fix it?

        More Info

        While it is possible to build a Map from an Iterable using Map.fromIterable, writing an explicit for loop with for elements should be used instead.

        The main reason to prefer for elements is that it can be optimized by the Dart compiler for performance, depending on the iterable being visited.

        Moreover, for elements are more idiomatic and generally easier to understand than Map.fromIterable, which requires explicit map type upfront, as well as the input iterable and two different lambda functions as parameters.

        Map<String, int>.fromIterable( // Explicit Map<String, int> type required
          inputIterable,
          key: (item) => ...,          // Key generator
          value: (item) => ...,        // Value generator
        );
        

        On the other hand, for elements are more flexible, look like normal for loops, and support better inference of the resulting Map type.

        {
            for (final item in inputIterable)
                'The value is $v': v // Implicit Map<String, int> type inference
        }
        

        Exceptions

        The rule only applies to the fromIterable factory method of Map. It does not apply to other fromIterable methods, such as the one from LinkedHashMap<T, U> in dart:collection.

        Moreover, it only applies when all the arguments of the Map.fromIterable call are provided. If either the key or the value parameter is omitted, the rule does not apply.

        Map<int, int>.fromIterable(l1, key: (item) => ...); // OK
        Map<int, int>.fromIterable(l1, value: (item) => ...); // OK
        

        The rule also does not apply when the key and value parameters are not inline function expressions, but variables defined elesewhere in the code.

        final key = (item) => ...;
        final value = (item) => ...;
        Map<int, int>.fromIterable(l1, key: key, value: value);
        
          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