How exclude simple getter and setter from sonar?

蹲街弑〆低调 提交于 2019-12-11 00:09:36

问题


There is the way to exclude getter and setters from 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;
}

It is possible to exclude getId() and include getComplexId() simultaneously? Can Sonar analyze simple return this.id from complex code?


回答1:


You can use 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;
}

Also you can use //NOSONAR or //CHECKSTYLE:OFF comment. More info in http://www.sonarqube.org/sonar-1-12-in-screenshots/




回答2:


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



来源:https://stackoverflow.com/questions/18587828/how-exclude-simple-getter-and-setter-from-sonar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!