Hi all,
I would like to be able to suppress some correctly identified but non-addressable warnings; mostly with the Law of Demeter. Certain libraries like Mokito and Guice use chain calls by design:
when(mockedClass.function()).thenReturn(someValue);
and
filter("/").through(AuthenticationFilter.class);
serve("/js/", "/css/*").with(CustomFileServlet.class);
The lines themselves can't be annotated with @SuppressWarning("PMD.LawOfDemeter") and doing so would rapidly make the code less readable. Annotating the method or class means other violations of that type are suppressed and using //NOPMD suppresses all warnings on a line not just the Law of Demeter one.
Currently, setting the "suppressViolationXpath" property within the pmdRules.xml suppresses all violations of that rule if in the entire file if one XPath match is found. As it is already possible to suppress an entire file by annotating the top of the file it would be more useful for "suppressViolationXpath" to only suppress the lines matching the XPath. For example
//BlockStatement//PrimaryPrefix/Name[@Image='filter']
would suppress the above filter example but not the serve.
I believe the issue is with "ParametericRuleViolation.setSuppression()", which checks if any descendent of this node matches the XPath and then suppresses warnings on that node, when in fact it could just check if that node matches rather than the descendent.
If this sounds reasonable, I shall continue to try and work out how to achieve it. Otherwise, we really need another way to ignore these "by design" violations.
Kym
I second this one.
Just started using PMD and wanted to exclude public
equals,hashCodeandtoStringmethods frompublicMethodCommentRequirementonce and for all in a config file.I was astonished to find out that a XPath like
//MethodDeclarator[@Image='toString']removes not only the warning for the matching path.