Skip to content

Commit

Permalink
[core] RuleSetFactory - recognize rule reference for same ruleset
Browse files Browse the repository at this point in the history
There are two variants, how a renamed rule can be expressed in the
ruleset via a deprecated rule reference: referencing just the
new rule name or referencing the ruleset+new rule name. The latter
case was not covered yet, it was not detected, that the rule ref
references are rule in the same ruleset.

Fixes pmd#2096
  • Loading branch information
adangel committed Nov 4, 2019
1 parent bfa2d1e commit 007de29
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/pages/release_notes.md
Expand Up @@ -16,6 +16,9 @@ This is a {{ site.pmd.release_type }} release.

### Fixed Issues

* core
* [#2096](https://github.com/pmd/pmd/issues/2096): \[core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat

### API Changes

### External Contributions
Expand Down
Expand Up @@ -639,6 +639,10 @@ private void parseRuleReferenceNode(RuleSetReferenceId ruleSetReferenceId, RuleS
&& containsRule(ruleSetReferenceId, otherRuleSetReferenceId.getRuleName())) {
otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId);
isSameRuleSet = true;
} else if (otherRuleSetReferenceId.isExternal()
&& otherRuleSetReferenceId.getRuleSetFileName().equals(ruleSetReferenceId.getRuleSetFileName())) {
otherRuleSetReferenceId = new RuleSetReferenceId(otherRuleSetReferenceId.getRuleName(), ruleSetReferenceId);
isSameRuleSet = true;
}
// do not ignore deprecated rule references
Rule referencedRule = ruleSetFactory.createRule(otherRuleSetReferenceId, true);
Expand Down
4 changes: 4 additions & 0 deletions pmd-core/src/test/resources/rulesets/dummy/basic.xml
Expand Up @@ -18,7 +18,11 @@ Just for test
</example>
</rule>

<!-- variant 1 of a renamed rule. This is definitively within the same ruleset. -->
<rule deprecated="true" name="OldNameOfDummyBasicMockRule" ref="DummyBasicMockRule"/>
<!-- variant 2 of a renamed and/or moved rule. This could also keep the rule name but
move the rule into a different rule or do any combination of both -->
<rule deprecated="true" name="OldNameOfDummyBasicMockRule2" ref="rulesets/dummy/basic.xml/DummyBasicMockRule"/>

<rule name="SampleXPathRule" language="dummy" since="1.1" message="Test Rule 2" class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/dummy/basic.xml#SampleXPathRule">
Expand Down
Expand Up @@ -40,6 +40,7 @@ private static void assertDefaultExecutionResult(ExecutionResult result) {
result.assertNoError("Exception applying rule");
result.assertNoError("Ruleset not found");
result.assertNoError("Use of deprecated attribute");
result.assertNoError("instead of the deprecated"); // rule deprecations
result.assertNoErrorInReport("Error while processing");
result.assertNoErrorInReport("Error while parsing");
}
Expand Down

0 comments on commit 007de29

Please sign in to comment.