In our company we developed a set of custom Checkstyle rules, with a custom Maven Checkstyle configuration. They appear in the report as a normal error, but by some reason in SonarCloud analysis I don’t see it. Is there anything that I can do to make it possible to display a custom error?
Yes, sure, and the issues in the report are appearing in sonar, all of them except my custom one. The custom one is also in checkstyle.xml report, but not in SonarCloud report
Hi Dmitrii, I think the issue might have something to do with the format of the file’s portion generated by your rule. If not confidential, could you share the report file that is causing you this issue? It would be great to have a file that has at least 1 issue reported correctly by Sonarcloud and at least 1 issue that instead is missing, to check the differences
I think I’m hitting the same issue so I wonder if there has ever been some progress on this outside of this discussion.
I’ve written a custom Checkstyle check that is listed both in checkstyle-result.xml and also site/checkstyle.html. To verify that checkstyle is actually picked up by Sonar, I’ve also added an empty catch block and ran another scan. The empty catch block is reported in SonarCloud but the custom checks are missing.
Following is a snippet of checkstyle-results.xml. SonarCloud reports on the first and the last finding but not the custom ones in between.
Another potential solution could be to have a “catch-all” mechanism, so you will see the issue on the right location and with the right error message. I’ve created a ticket for it:
Correct me if I’m wrong but i thought SonarCloud doesn’t support custom rules/plugins. That’s at least the feedback I got from SonarSource back in 2018. I cannot find any information on this, has this changed meanwhile?
In the past we used self-written Sonar plugins back when we hosted SonarQube ourselves so this would also have been my first choice if it would be available. But since neither custom plugins nor rule templates (e.g. something like track use of disallowed [classes|constructors|methods]) are available in the cloud offering, I thought I make use of other tools like Checkstyle and let the Sonar scanner import those findings.
It’s a shame that this isn’t supported as it leaves me a bit lost at the moment. I appreciate that you opened a ticket for this internally but seeing that it has a low priority I don’t expect this feature to become available any time soon. Of course I can enforce custom rules locally by breaking the build to get the dev’s attention but I’d prefer to have a uniform approach which - for us at least - is to rely on SonarCloud and whether the quality gate is met.
Anyways thank you for your help and I’ll keep an eye on the ticket to track the progress.
Thanks for your feedback, indeed you’re right that in SonarCloud you can’t use it at the moment, I missed you’re using SC. I bumped the priority of the ticket and I will share your feedback with our Product managers, we’ll see what we can do for such cases.
Technically you will need to generate a report with your custom rules in this format and pass it to the property. Then Sonar will be able to pick the rules and report.
Thanks for the link, I didn’t know about the generic import format. I had a brief look at custom Checkstyle reports to get a compliant format but I believe it’s unnecessarily complex to get this done within Checkstyle and I don’t want to set up tasks outside the build system.
Meanwhile I found New checkstyle rules doesn't show on Sonar issues list which also addresses this issue. The post suggests to use the Checkstyle package name as prefix to work around the filter condition. I just gave it a try and it works so I’ll take this route until SONARJAVA-4916 fixes the general issue.