sonar-flutter icon indicating copy to clipboard operation
sonar-flutter copied to clipboard

Improvements

Open kuhnroyal opened this issue 4 years ago • 20 comments

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

kuhnroyal avatar Apr 28 '21 09:04 kuhnroyal

Nice @kuhnroyal ! I'm gonna review it and test it soon.

zippy1978 avatar Apr 28 '21 11:04 zippy1978

@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.

zippy1978 avatar Apr 28 '21 11:04 zippy1978

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);

kuhnroyal avatar Apr 28 '21 12:04 kuhnroyal

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.

kuhnroyal avatar Apr 28 '21 15:04 kuhnroyal

The column/length handling should be fixed.

kuhnroyal avatar Apr 28 '21 15:04 kuhnroyal

Good finding ! I have done some tests and everything works fine now

zippy1978 avatar Apr 28 '21 19:04 zippy1978

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.

kuhnroyal avatar Apr 29 '21 09:04 kuhnroyal

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?

kuhnroyal avatar Apr 29 '21 15:04 kuhnroyal

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

kuhnroyal avatar Apr 29 '21 16:04 kuhnroyal

Hi @kuhnroyal ,

I created sqale-model.xml by hand :) Because remediation effort must be evaluated for each issue...

zippy1978 avatar May 05 '21 19:05 zippy1978

I never faced removed rules issues... Maybe legacy rules should be kept in a legacy profile for sometime ?

zippy1978 avatar May 05 '21 19:05 zippy1978

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.

kuhnroyal avatar May 06 '21 08:05 kuhnroyal

So it seems that nobody from SonarSource is gonna answer my question because my company license doesn't include support.

kuhnroyal avatar May 12 '21 08:05 kuhnroyal

Hi @kuhnroyal, I'm back :)

For the deleted rules problem, I think we have 2 possibilities:

  1. we can modify the rule generation scripts to merge new rules with legacy ones
  2. 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 ?

zippy1978 avatar Aug 08 '21 21:08 zippy1978

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

zippy1978 avatar Aug 08 '21 22:08 zippy1978

Hey, thanks! I was afraid the plugin was dead :) I am willing to pitch in here and there and help maintain it.

  1. 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.xml update in your PR, we will need to update it.

Yes, I didn't touch this yet. There is a lot of new rules.

kuhnroyal avatar Aug 09 '21 09:08 kuhnroyal

@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.

kuhnroyal avatar Sep 02 '21 16:09 kuhnroyal

is there any chance to close and release this year?

pawlichap avatar Dec 17 '21 08:12 pawlichap

is this PR dead?

ogezue avatar Jun 16 '22 06:06 ogezue

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.

kuhnroyal avatar Jun 21 '22 11:06 kuhnroyal