How to exclude a simple getter and setter from a sonar?

There is a way to exclude gatekeepers and setters from a sonar report. Suppose I have 2 "getters":

public int getId(){ return this.id; } public int getComplexId(){ int result = 0; // some complex calculation there return result; } 

Can I exclude getId () and enable getComplexId () at the same time? Can Sonar analyze the simple possibility of returning this.id from complex code?

+2
source share
2 answers

You can use the NOPMD comment to avoid sonar analysis.

 public int getId(){ // NOPMD return this.id; } public int getComplexId(){ int result = 0; // some complex calculation there return result; } 

You can also use // NOSONAR or // CHECKSTYLE: OFF comment. Additional information at http://www.sonarqube.org/sonar-1-12-in-screenshots/

+1
source

@Cherry, out of the box, SonarQube already behaves as expected: the first method is considered to be a getter, not the second, because this method contains some logic.

0
source

Source: https://habr.com/ru/post/1264009/


All Articles