How exclude simple getter and setter from sonar?

2019-07-17 06:03发布

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?

2条回答
祖国的老花朵
2楼-- · 2019-07-17 06:55

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/

查看更多
别忘想泡老子
3楼-- · 2019-07-17 06:55

@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.

查看更多
登录 后发表回答