sonar-flutter
sonar-flutter copied to clipboard
Improvements
Related to #51
- add support for modules
- add support for errors in pubspec
- add support for machine output
- drop support for dartanalyzer call per single file
This is a partial rewrite with several breaking changes but it allows to support the future analyzer machine format of Dart and Flutter. Dartanalyzer is still supported but no longer scans files individually.
Need people willing to test this. @mreichelt @zippy1978
Nice @kuhnroyal ! I'm gonna review it and test it soon.
@kuhnroyal ,
When testing on gallery (https://github.com/flutter/gallery)
I get :
java.lang.IllegalArgumentException: Start pointer [line=14, lineOffset=31] should be before end pointer [line=14, lineOffset=31]
Source is at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.lambda$recordIssues$0(DartAnalyzerSensor.java:100)
You should replace:
int end = start + issue.getLength() - 1; (on line 98)
by
int end = start + issue.getLength() ;
to fix it.
You should replace:
int end = start + issue.getLength() - 1;(on line 98)by
int end = start + issue.getLength() ;to fix it.
Good catch, this is relevant for lints that have a length of 1.
When the lint error is at the end of the of line however, start + issue.getLength() will be too long by 1.
Probably need something like this:
int end = max(start + 1, start + issue.getLength() - 1);
Ok, looked into this a little bit. In the Dart language server columns are 1-based: https://github.com/dart-lang/sdk/blob/4d696edc97971b3ed612393e85ebb6f4bc51109f/pkg/test_runner/lib/src/static_error.dart#L240 In SonarQube only lines are 1-based, columns are 0-based.
The column/length handling should be fixed.
Good finding ! I have done some tests and everything works fine now
So... with NNBD there are new compiler errors. Not sure if they should be represented in Sonar.
ERROR|COMPILE_TIME_ERROR|MISSING_DEFAULT_VALUE_FOR_PARAMETER|/some/path/lib/src/form_definition.dart|23|20|7|The parameter 'element' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
ERROR|COMPILE_TIME_ERROR|MISSING_DEFAULT_VALUE_FOR_PARAMETER|/some/path/lib/src/form_definition.dart|24|20|4|The parameter 'type' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
ERROR|COMPILE_TIME_ERROR|MISSING_DEFAULT_VALUE_FOR_PARAMETER|/some/path/lib/src/form_definition.dart|25|20|8|The parameter 'dataType' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
ERROR|COMPILE_TIME_ERROR|MISSING_DEFAULT_VALUE_FOR_PARAMETER|/some/path/lib/src/form_definition.dart|26|19|13|The parameter 'dataTypeMulti' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
WARNING|STATIC_WARNING|DEAD_NULL_AWARE_EXPRESSION|/some/path/lib/src/form_definition.dart|27|47|8|The left operand can't be null, so the right operand is never executed.
ERROR|COMPILE_TIME_ERROR|NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD|/some/path/lib/src/form_definition.dart|97|3|14|Non-nullable instance field '_modelName' must be initialized.
ERROR|COMPILE_TIME_ERROR|MISSING_DEFAULT_VALUE_FOR_PARAMETER|/some/path/lib/src/form_definition.dart|98|20|7|The parameter 'element' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
INFO|HINT|UNNECESSARY_NULL_COMPARISON|/some/path/lib/src/generator.dart|20|18|7|The operand can't be null, so the condition is always true.
INFO|HINT|UNNECESSARY_NULL_COMPARISON|/some/path/lib/src/generator.dart|21|31|7|The operand can't be null, so the condition is always true.
I added a new way to generate keywords and rules directly from the SKD/analyzer/linter.
How did you create the initial sqale-model.xml?
The removed rules cause Sonar to fail during startup, not sure how to deal with this. I created https://community.sonarsource.com/t/how-to-deal-with-removed-rules-in-a-plugin/42511
Hi @kuhnroyal ,
I created sqale-model.xml by hand :)
Because remediation effort must be evaluated for each issue...
I never faced removed rules issues... Maybe legacy rules should be kept in a legacy profile for sometime ?
Yea I assume something like that, will see if I can spend some time on this over the weekend. So I should probably diff the existing rules against the new rules when running the script, and maybe also against the sqale model and see what is missing.
So it seems that nobody from SonarSource is gonna answer my question because my company license doesn't include support.
Hi @kuhnroyal, I'm back :)
For the deleted rules problem, I think we have 2 possibilities:
- we can modify the rule generation scripts to merge new rules with legacy ones
- we provide a new / versionned profile with each release of the plugin like "dartanalyzer 0.3.3"
Which one do you prefer ?
The first one require more dev effort, but no effort for users...
Also I don't see a sqale-model.xml update in your PR, we will need to update it.
I do that by hand usually by adding each new rule in the file: I can do it. Unless you have a more efficient (automated ?) way to estimate remediation times ?
By the way @kuhnroyal, I gave you maintainer rights to the repo, so that we are both able to validate / merge PRs and contribute to the project (if you are ok with that...). As we cannot send direct messages with Github, feel free to reach me on tweeter: @zippy1978
Hey, thanks! I was afraid the plugin was dead :) I am willing to pitch in here and there and help maintain it.
- we can modify the rule generation scripts to merge new rules with legacy ones
We should definitely go with number 1 - I can update the script to deprecate the old rules. User can then manually remove the deprecated rules from their quality profiles. At least this is what I think.
Also I don't see a
sqale-model.xmlupdate in your PR, we will need to update it.
Yes, I didn't touch this yet. There is a lot of new rules.
@zippy1978 I created a new release with SonarQube 9 compatibility. Now I want to see if I can get started again with stuff. I somehow managed to delete the develop branch and restored it, can you add a branch protection rule please.
is there any chance to close and release this year?
is this PR dead?
Yea, I dropped Sonar tbh. I currently see no way to maintain all the different rules. There are new ones on every Dart/Flutter release.
Additionally SonarSource has native Dart/Flutter support on their Roadmap for this year.