Honoring @SuppressWarnings with the sonar checkstyle plugin

假装没事ソ 提交于 2020-06-28 02:55:11

问题


Is there any possibility to configure SonarQube 5.1 with Checkstyle plugin to honor the @SuppressWarnings("deprecation") annotation. I do not want to turn off 'Avoid use of deprecated methods' rule, I just want to SonarQube honor the @SuppressWarnings annotation.

I have a Java code in which I need to use deprecated createValidator() method as following:

@SuppressWarnings("deprecation")
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {
    return contextDelegate.createValidator();
}

Java compiler does not warning when compiling code, but unfortunately SonarQube with CheckStyle plugin rise a issue:

squid:CallToDeprecatedMethod
Avoid use of deprecated methods

回答1:


Squid is a different kind of beast. As suggested in the SonarQube docs, you'll have to use a slightly different syntax, e.g.:

@SuppressWarnings("squid:CallToDeprecatedMethod")

The string squid:CallToDeprecatedMethod is the SonarQube rule key.

Unfortunately, this means adding two annotations to effectively suppress the deprecation warning. But afaik, it's the only way short of disabling the rule.




回答2:


Squid is a name or number of Sonar Rule, no relationship to checkstyle, all checkstyle rules are described at http://checkstyle.sourceforge.net/checks.html



来源:https://stackoverflow.com/questions/33379959/honoring-suppresswarnings-with-the-sonar-checkstyle-plugin

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