Hi @Nicolas,
I understand your reasoning. However, I am also interested in such a rule. My use case is as follows:
A project of about 50K lines consists of several dozens of modules and hundreds of packages. Only a handful of packages actually form an API in the sense of “should and can be consumed by other code bases”. Most public classes use this visibility solely in order to be accessible by other packages of the same project. The project itself lives in one Git repository and is built using a single Maven aggregator build. While Java 9 and its module system could be a solution, there are of course projects on Java <= 8, or projects who cannot move to Java modules. All in all, this means that a large portion of unused code is never detected by any tool.
What’s your take on this scenario? I think that a “unused public class/method” rule which can be activated selectively for folders of “public only inside the application” packages would be of great value in such projects (see Bean Validation should be enabled were a similar approach was taken for S5128). Would you perhaps be willing to specify a rule for this and accept an outside PR implementing it?
Also, could this be implemented (easily) within the current SonarJava architecture?
Note that my company uses SonarCloud and could therefore not install a custom rule.
Best regards,
Jens