I have a very unique scenario with Sonar Cloud where it does not really function properly.
The repo I have Primitive-Collections basically can not use Sonar Cloud directly.
I am pretty much forced to use a different branch to use it.
The Project is a Library that is generated via code generators that automatically generate the required code on build. That is the reason Github has only the Template files.
Is there a way to have Sonar Cloud work with Code that is generated in runtime?
Or is this service only usable when I am having a separate branch where all the code is uploaded?
If that is the case how can I make the branch a Long living Branch so I can use the Badges from it to be displayed in the main branch Readme?
SonarCloud really isn’t built to deal with generated code – as this code typically can’t actually be modified by developers (so the results are just noise). And, there might be something How is the analysis running today?
Automatic Analysis definitely won’t work. You have a better chance with CI-based analysis (although since the changed files won’t exist as checked into Git, I don’t think you’ll have any luck with PR analysis).
Out of curiosity – what are you actually expecting (result-wise) with analyzing generated code? Do you expect to be able to fix issues that are raised? See metrics?
Well the idea of the automatic code generator is that the SourceCode is generated as the project is being build. So bugs shown in the source files can be easily reflected to the Template files. But SonarCloud is not able to detect files that weren’t present before the script started. I am also guessing that it takes the “gitignore” into account.
Well Automatic Analysis was never on my mind in the first place since it is auto generated code and some custom information would have been provided.
And I attempted CI-based analysis but it never was able to see any files that weren’t in the git repo before the script started.
Well since actual code is Generated and can be compared I wanted to use the service to let its code quality check run over it. Even if the duplication check would scream at me it is still a great resource to find bugs/issues with the code that could be addressed to lead to better code quality in general.
Which would lead to expanding my knowledge, and would allow me to show more transparently how good the code actually is.
While the last one isn’t fulfilled and I wish I could show it at least in some way. I am already happy that making a separate branch already helped fulfill 2 of 3 goals.
The only issue I would have left is that I am not sure how to create a Branch that isn’t viewed as a “Short-Lived” one. If I could get a long lived branch that is the entire generated Source Code I would be happy to use that solution since it would lead to the same result ± a tiny bit more work on my end that I bet could be solved with GithubActions.