I'm tring to find a way to remove some correctly identitifed but non-addressable warnings, mostly with the Law of Demeter. Certain libraries like Mokito and Guice use chain calls by design:
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 violations in other places are suppressed and //NOPMD suppresses all warnings on a line not just the Law of Demeter one.
Is there no way to make suppressViolationXpath match only the scope of the element identified. For example
//BlockStatement//PrimaryPrefix/Name[@Image='filter' or @Image='serve']
should capture just the offending line, not the whole class.
(Also as a foot note: from the documentation it's really not obvious that suppressViolationXpath affects the whole class if any lines are matched)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem is with ParametericRuleViolation.setSuppression()
if (!suppressed) { // XPath
String xpath = rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR);
if (xpath != null) {
suppressed = node.hasDescendantMatchingXPath(xpath);
}
}
should surely be
if (!suppressed) { // XPath
String xpath = rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR);
if (xpath != null) {
suppressed = node.matchesXPath(xpath);
}
}
but I'm currently unable to get the git project to build due to all sorts of project and dependency errors in Ecplise so I haven't been able to constrct Node.matchesXPath().
Last edit: Kym Eden-Jones 2016-08-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I'm tring to find a way to remove some correctly identitifed but non-addressable warnings, mostly with the Law of Demeter. Certain libraries like Mokito and Guice use chain calls by design:
and
for example.
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 violations in other places are suppressed and //NOPMD suppresses all warnings on a line not just the Law of Demeter one.
Is there no way to make suppressViolationXpath match only the scope of the element identified. For example
should capture just the offending line, not the whole class.
(Also as a foot note: from the documentation it's really not obvious that suppressViolationXpath affects the whole class if any lines are matched)
The problem is with ParametericRuleViolation.setSuppression()
should surely be
but I'm currently unable to get the git project to build due to all sorts of project and dependency errors in Ecplise so I haven't been able to constrct Node.matchesXPath().
Last edit: Kym Eden-Jones 2016-08-18