From 92bab9b595ce73667d7669b81bdf18ddb623e687 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Oct 2020 16:17:43 +0200 Subject: [PATCH] pmd-doc: Add test case for renamed rules Uses the pattern documented in rule deprecation policy. The rule reference should be deprecated to get a deprecation warning, if it is still used. --- pmd-doc/src/test/resources/expected/java.md | 5 +- pmd-doc/src/test/resources/expected/sample.md | 231 +++++++++++++++++- .../resources/rulesets/ruledoctest/sample.xml | 14 +- 3 files changed, 243 insertions(+), 7 deletions(-) diff --git a/pmd-doc/src/test/resources/expected/java.md b/pmd-doc/src/test/resources/expected/java.md index a20c0aa803..0ba141b68c 100644 --- a/pmd-doc/src/test/resources/expected/java.md +++ b/pmd-doc/src/test/resources/expected/java.md @@ -15,7 +15,10 @@ folder: pmd/rules * [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer): Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional. * [MovedRule](pmd_rules_java_sample.html#movedrule): Deprecated The rule has been moved to another ruleset. Use instead [JumbledIncrementer](pmd_rules_java_sample2.html#jumbledincrementer). * [OverrideBothEqualsAndHashcode](pmd_rules_java_sample.html#overridebothequalsandhashcode): Override both 'public boolean Object.equals(Object other)', and 'public int Object.hashCode()', o... -* [RenamedRule](pmd_rules_java_sample.html#renamedrule): Deprecated The rule has been renamed. Use instead [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer). +* [RenamedRule1](pmd_rules_java_sample.html#renamedrule1): Deprecated The rule has been renamed. Use instead [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer). +* [RenamedRule2](pmd_rules_java_sample.html#renamedrule2): Deprecated The rule has been renamed. Use instead [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer). +* [RenamedRule3](pmd_rules_java_sample.html#renamedrule3): Deprecated The rule has been renamed. Use instead [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer). +* [RenamedRule4](pmd_rules_java_sample.html#renamedrule4): Deprecated The rule has been renamed. Use instead [JumbledIncrementer](pmd_rules_java_sample.html#jumbledincrementer). * [XSSInDocumentation](pmd_rules_java_sample.html#xssindocumentation): <script>alert('XSS at the beginning');</script> HTML tags might appear at various places. ... ## Additional rulesets diff --git a/pmd-doc/src/test/resources/expected/sample.md b/pmd-doc/src/test/resources/expected/sample.md index ff3c6fc81d..c1f20199a4 100644 --- a/pmd-doc/src/test/resources/expected/sample.md +++ b/pmd-doc/src/test/resources/expected/sample.md @@ -5,7 +5,7 @@ permalink: pmd_rules_java_sample.html folder: pmd/rules/java sidebaractiveurl: /pmd_rules_java.html editmepath: ../rulesets/ruledoctest/sample.xml -keywords: Sample, XSSInDocumentation, OverrideBothEqualsAndHashcode, JumbledIncrementer, DeprecatedSample, RenamedRule, MovedRule +keywords: Sample, XSSInDocumentation, OverrideBothEqualsAndHashcode, JumbledIncrementer, DeprecatedSample, RenamedRule1, RenamedRule2, RenamedRule3, RenamedRule4, MovedRule language: Java --- @@ -204,7 +204,7 @@ public class Foo { ``` -## RenamedRule +## RenamedRule1 Deprecated @@ -257,12 +257,235 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i **Use this rule with the default properties by just referencing it:** ``` xml - + ``` **Use this rule and customize it:** ``` xml - + + + + + + + + + + + + + +``` + +## RenamedRule2 + +Deprecated + +This rule has been renamed. Use instead: [JumbledIncrementer](#jumbledincrementer) + +**Since:** PMD 1.0 + +**Priority:** Medium (3) + +Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional. + +**This rule is defined by the following XPath expression:** +``` xpath +//ForStatement + [ + ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image + = + ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image + ] +``` + +**Example(s):** + +``` java +{%raw%}public class JumbledIncrementerRule1 { + public void foo() { + for (int i = 0; i < 10; i++) { // only references 'i' + for (int k = 0; k < 20; i++) { // references both 'i' and 'k' + System.out.println("Hello"); + } + } + } +}{%endraw%} +``` + +**This rule has the following properties:** + +|Name|Default Value|Description|Multivalued| +|----|-------------|-----------|-----------| +|sampleAdditionalProperty|the value|This is a additional property for tests|no| +|sampleMultiStringProperty|Value1 \| Value2|Test property with multiple strings|yes. Delimiter is '\|'.| +|sampleDeprecatedProperty|test|Deprecated This is a sample deprecated property for tests|no| +|sampleRegexProperty1|\\/\\\*\\s+(default\|package)\\s+\\\*\\/|The property is of type regex|no| +|sampleRegexProperty2|\[a-z\]\*|The property is of type regex|no| +|sampleRegexProperty3|\\s+|The property is of type regex|no| +|sampleRegexProperty4|\_dd\_|The property is of type regex|no| +|sampleRegexProperty5|\[0-9\]{1,3}|The property is of type regex|no| +|sampleRegexProperty6|\\b|The property is of type regex|no| +|sampleRegexProperty7|\\n|The property is of type regex|no| + +**Use this rule with the default properties by just referencing it:** +``` xml + +``` + +**Use this rule and customize it:** +``` xml + + + + + + + + + + + + + +``` + +## RenamedRule3 + +Deprecated + +This rule has been renamed. Use instead: [JumbledIncrementer](#jumbledincrementer) + +Deprecated + +**Since:** PMD 1.0 + +**Priority:** Medium (3) + +Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional. + +**This rule is defined by the following XPath expression:** +``` xpath +//ForStatement + [ + ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image + = + ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image + ] +``` + +**Example(s):** + +``` java +{%raw%}public class JumbledIncrementerRule1 { + public void foo() { + for (int i = 0; i < 10; i++) { // only references 'i' + for (int k = 0; k < 20; i++) { // references both 'i' and 'k' + System.out.println("Hello"); + } + } + } +}{%endraw%} +``` + +**This rule has the following properties:** + +|Name|Default Value|Description|Multivalued| +|----|-------------|-----------|-----------| +|sampleAdditionalProperty|the value|This is a additional property for tests|no| +|sampleMultiStringProperty|Value1 \| Value2|Test property with multiple strings|yes. Delimiter is '\|'.| +|sampleDeprecatedProperty|test|Deprecated This is a sample deprecated property for tests|no| +|sampleRegexProperty1|\\/\\\*\\s+(default\|package)\\s+\\\*\\/|The property is of type regex|no| +|sampleRegexProperty2|\[a-z\]\*|The property is of type regex|no| +|sampleRegexProperty3|\\s+|The property is of type regex|no| +|sampleRegexProperty4|\_dd\_|The property is of type regex|no| +|sampleRegexProperty5|\[0-9\]{1,3}|The property is of type regex|no| +|sampleRegexProperty6|\\b|The property is of type regex|no| +|sampleRegexProperty7|\\n|The property is of type regex|no| + +**Use this rule with the default properties by just referencing it:** +``` xml + +``` + +**Use this rule and customize it:** +``` xml + + + + + + + + + + + + + +``` + +## RenamedRule4 + +Deprecated + +This rule has been renamed. Use instead: [JumbledIncrementer](#jumbledincrementer) + +Deprecated + +**Since:** PMD 1.0 + +**Priority:** Medium (3) + +Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional. + +**This rule is defined by the following XPath expression:** +``` xpath +//ForStatement + [ + ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image + = + ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image + ] +``` + +**Example(s):** + +``` java +{%raw%}public class JumbledIncrementerRule1 { + public void foo() { + for (int i = 0; i < 10; i++) { // only references 'i' + for (int k = 0; k < 20; i++) { // references both 'i' and 'k' + System.out.println("Hello"); + } + } + } +}{%endraw%} +``` + +**This rule has the following properties:** + +|Name|Default Value|Description|Multivalued| +|----|-------------|-----------|-----------| +|sampleAdditionalProperty|the value|This is a additional property for tests|no| +|sampleMultiStringProperty|Value1 \| Value2|Test property with multiple strings|yes. Delimiter is '\|'.| +|sampleDeprecatedProperty|test|Deprecated This is a sample deprecated property for tests|no| +|sampleRegexProperty1|\\/\\\*\\s+(default\|package)\\s+\\\*\\/|The property is of type regex|no| +|sampleRegexProperty2|\[a-z\]\*|The property is of type regex|no| +|sampleRegexProperty3|\\s+|The property is of type regex|no| +|sampleRegexProperty4|\_dd\_|The property is of type regex|no| +|sampleRegexProperty5|\[0-9\]{1,3}|The property is of type regex|no| +|sampleRegexProperty6|\\b|The property is of type regex|no| +|sampleRegexProperty7|\\n|The property is of type regex|no| + +**Use this rule with the default properties by just referencing it:** +``` xml + +``` + +**Use this rule and customize it:** +``` xml + diff --git a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml index da81d702d1..4037c8ffb8 100644 --- a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml +++ b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml @@ -216,8 +216,18 @@ RuleTag with full category and without quotes: Use {% rule java/sample/RenamedRu - + - + + + + + + + + + +