insideapp-oss / sonar-flutter

SonarQube plugin for Flutter / Dart
Other
449 stars 82 forks source link

False Positive: "Local variables should not be marked as 'final'" in Dart #229

Closed Uzair-Ghulam closed 2 months ago

Uzair-Ghulam commented 2 months ago

local-variable-should-not-be-marked-as-final local-variable-should-not-be-marked-as-final2 I am encountering a false positive related to the rule "Local variables should not be marked as 'final'" when scanning my Flutter project with the SonarQube Flutter plugin. In Dart, using final for local variables is a common and recommended practice to prevent reassignment, especially in Flutter widget creation. However, the plugin incorrectly flags this as an issue, which does not align with Dart/Flutter best practices.

Expected Behavior: Local variables marked as final in Dart should not be flagged as an issue since it is a valid and encouraged practice for code safety and immutability. Observed Behavior: The plugin reports the issue: "Local variables should not be marked as 'final'" on valid Dart code, where the final keyword is used correctly to prevent reassignment.

The SonarQube Flutter plugin raises an issue for each final local variable, despite these variables being correctly declared.

Environment: SonarQube version: [10.6.0.92116] SonarQube Flutter Plugin version: [0.5.1] Flutter version: [ 3.19.6] Dart version: [3.3.4] Sonar Scanner [sonar-scanner-6.1.0.4477-windows-x64] SonarQube Configuration: sonar-project.properties [ sonar.projectKey=My-Flutter-App sonar.projectName=My Flutter App sonar.projectVersion=1.0
sonar.sources=lib,pubspec.yaml sonar.sourceEncoding=UTF-8 sonar.dart.coverage.reportPaths=coverage/lcov.info sonar.exclusions=analysis_options.yaml.sonar,*/.java ]

zippy1978 commented 2 months ago

Hi, Errors reported by the plugin comme form the Dart Analyzer. Here is the rule: https://dart.dev/tools/linter-rules/unnecessary_final

But if you prefer to use final, you can still disable the rule in your profile.