We’ve recently started integrating a Flutter codebase into SonarQube.
It looks like the dart analyzer is not respecting the linter rules defined in the analysis_options.yaml file that is defined in our project, therefore there is no way to ‘override’ the analyzer linter (without changing the quality profile) and such must adhere to all the active rules defined in Quality Profile - Dart (Sonar way)
This is counter-intuitive, as within the rules of the Dart Quality Profile, in the More Info → Resources section it specifically links out to the dart linter rules, which can be enabled/disabled in every project via the analysis_options.yaml file.
As per the doc’s it would seem this support does not exist yet, is this something that is to come in the future, I could not see on the roadmap anything around this. It would be a fantastic edition.
Would you like to enable only the rules specified in analysis_options.yaml without needing to modify the Quality Profile in SonarQube?
Yes, that is essentially correct, lets have a look at swiftlint for example with Swift, we have a Swift codebase, which we’ve essentially disabled all the rules in the Swift Quality Profile except rules that can not be caught by static analysis, and our swiftlint.yaml file has our defined set of rules, now in this case, we run swiftlint and provide the report to Sonar via sonar.swift.swiftLint.reportPaths=swiftlint.result.json, which then show in SonarQube.
It would be lovely to be able to do something similar with analysis_options.yaml for Dart. Now a static analysis reporting tool is not available for Dart to mimic this exact behaviour as swiftlint, but if the Sonar Dart profile could first check if an analysis_options.yaml file exists, or if there was a sonar property to point to it, then run against the rules defined in that, otherwise run against the default active rules. I’m guessing the profile just runs dart analyze behind the scenes against whatever rules are active currently. It would mean we have parity between static code analysis when developing locally and running via CI.
We are fresh to Dart so I can’t yet give any other recommendations on specific rules that should or should not be activated or deactivated.
We have a CI Pipeline that already produces the analyzer.output file (from an analyzer run with our own analysis_options.yaml). Now we just want to import that report instead of having Sonar run an analysis with different options.