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

        Unnecessary use of "toList" with spread operator

        intentionality - efficient
        reliability
        Code Smell
        • performance

        Calling toList on an Iterable used in a list literal with a spread operator is redundant and should be removed.

        Why is this an issue?

        How can I fix it?

        More Info

        The spread operators (... and ...?) are convenient ways to flatten a collection into a collection literal, that work on multiple types of collections supporting literals: List, Map, and Set.

        When a spread operator is used in a List literal, it looks like the following:

        final list = [1, 2, ...anIterable, 3, 4];
        

        which is more concise, readable, and efficient than the equivalent code not using it:

        final list = [1, 2]..addAll(anIterable)..addAll([3, 4]);
        

        In the example above, the spread operator will iterate over the elements of anIterable, building the resulting list.

        There is no need to call toList on the Iterable before spreading it into the list literal, because the spread operator will take care of the iteration.

        final list = [1, 2, ...anIterable.toList(), 3, 4]; // toList not necessary
        

        In general, once the intent of flatting an Iterable into a collection literal has been expressed by using the ... operator, it’s best let the compiler figure out what is the best way to achieve that, based on the type of collection literal (List, Set, Map) and the actual type of provided Iterable.

        What is the potential impact?

        Calling toList unnecessarily is not only redundant and more verbose: it may result in unnecessary memory allocation and performance overhead, since an intermediate List instance would be created, just to be thrown away once it is spread into the list literal.

          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