checkstyle / sonar-checkstyle

Support on Checkstyle in SonarQube. Officially transfered from https://github.com/SonarQubeCommunity/sonar-checkstyle
GNU Lesser General Public License v3.0
171 stars 70 forks source link

Checkstyle Behavior Question #211

Closed tjhanley closed 2 years ago

tjhanley commented 5 years ago

Sonar version: Enterprise EditionVersion 7.3 (build 15553) Checkstyle sonar plugin version: 4.17

Steps to reproduce or description of problem:

My team has a couple of questions about this plugin.

  1. Sonar API currently allows export of check style rules associated to a sonarqube quality profile with something like this
    https://<sonar_server_link>/api/qualityprofiles/export?exporterKey=checkstyle&language=java&qualityProfile=test

This outputs content in xml format giving all the checker and tree walker filters associated. While it is currently possible to download the said check style rules xml based out of the plugin for checkstyle configured with sonar for a given quality profile, we couldn’t find any APIs that could post a modified checkstyle xml file back into the quality profile.

Can there be a solution for this possibly through newer API definitions?


  1. Sonar allows custom checker and tree walker filters configurable using the sonar additional arguments : sonar.checkstyle.filters and sonar.checkstyle.treewalkerfilters. Providing values to these arguments and running a sonar build does take the filters supplied at runtime, creates the result xml from the run but does not show the same results in the UI as code smells/bugs.

Additional info here :

Temp quality profile assigned to Project A with no default rules. We are going to only provide one check style filter by passing it in through -Dsonar.checkstyle.filters through sonar Runner plugin configured with TeamCity

-Dsonar.checkstyle.filters=<module name="FileTabCharacter"><property name="severity" value=“info"/></module>

a. When passing the filter argument with a test string : newline checker, we can see that sonar reads the argument and constructs the xml file internally at runtime under the .sonar/checkstyle.xml

Sensor CheckstyleSensor [checkstyle]
[01:21:50]

[Step 5/9] 01:21:50.421 INFO  - Checkstyle output report: /usr/local/teamcity-agent/work/5298af0a824b8dcc/.sonar/checkstyle-result.xml
[01:21:50]

[Step 5/9] 01:21:50.428 INFO  - Checkstyle configuration: /usr/local/teamcity-agent/work/5298af0a824b8dcc/.sonar/checkstyle.xml

b. Content of .sonar/checkstyle.xml:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"><!-- Generated by Sonar --><module name="Checker"><module name="FileTabCharacter"><property name="severity" value="info"/></module><module name="TreeWalker"><module name="SuppressionCommentFilter" /></module></module>

The check style results file ( .sonar/checkstyle-results.xml) also contains the results of the files where the  check style  errors occurred for the particular rule.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="8.17">
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/app/MainApp.java">
<error line="33" column="1" severity="info" message="File contains tab characters (this is the first instance)." source="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>
</file>
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/configuration/ApplicationConfiguration.java">
<error line="11" column="1" severity="info" message="File contains tab characters (this is the first instance)." source="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>
</file>
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/configuration/ProcessorConfiguration.java">
<error line="15" column="1" severity="info" message="File contains tab characters (this is the first instance)." source="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>
</file>
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/endpoints/ResourceFactory.java">
<error line="25" column="1" severity="info" message="File contains tab characters (this is the first instance)." source="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>
</file>
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/endpoints/ResourceHelpers.java">
<error line="46" column="1" severity="info" message="File contains tab characters (this is the first instance)." source="com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>
</file>
<file name="/usr/local/agent/work/5298af0a824b8dcc/src/main/java/com/home/project/endpoints/external/AccountsResource.java">
<error line="79" column="1" severity="info" message="File contains tab characters (this is the first instance)." source=“com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"/>

d. The same results were not displayed on the project UI which had the rules executed download

e. There are no code smells or any errors reported here

f. NOTE: Above was executed using SonarQube Runner 2.4. The same behavior was also observed when the filter rules were set globally on the external analyzer level on Sonar directly download2

romani commented 5 years ago

we couldn’t find any APIs that could post a modified checkstyle xml file back into the quality profile. Can there be a solution for this possibly through newer API definitions?

plugin do not define any http API. Please ask this question at sonarqube forum. I would like to know answer too :). This is feature of sonarqube web service, not a checkstyle plugin.

creates the result xml from the run but does not show the same results in the UI as code smells/bugs.

interesting, but we need more details and exact steps to make sure we can reproduce this. Can you reproduce this on sonar docker image instance ? This is how we test each commit over sonar in docker - https://github.com/checkstyle/sonar-checkstyle/blob/master/wercker.yml#L19 . Can you do the same and your side over our plugin sources :), (just put tab some where in our code and try to do the same suppression configuration).

rnveach commented 4 years ago

@tjhanley ping Can you provide the requested information or was your issue resolved?

muhlba91 commented 2 years ago

closing this as stale issue. please reopen if you can provide further details and issue still persists.