<?xml version="1.0"?>

<ruleset name="Sample"
    xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
  <description>
Sample ruleset to test rule doc generation.

Here might be &lt;script&gt;alert('XSS');&lt;/script&gt; as well. And "quotes".

<![CDATA[Inside CDATA <script>alert('XSS');</script>.]]>
  </description>

    <rule name="XSSInDocumentation"
          language="java"
          since="0.1"
          message="Tests that &lt;script&gt;alert('XSS');&lt;/script&gt; is properly escaped"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#xssindocumentation">
       <description>
            &lt;script&gt;alert('XSS at the beginning');&lt;/script&gt; HTML tags might appear at various places.
            Sometimes they should be escaped, sometimes not:

                For example, in a code sample, it should &lt;strong&gt;not&lt;/strong&gt; be escaped.
                This means, &lt;script&gt;alert('XSS');&lt;/script&gt; is no problem here.

            Also in backticks `&lt;script&gt;alert('XSS');&lt;/script&gt;` like here it is no problem.

            The tags are already escaped in the text, e.g. &lt;script&gt;alert('XSS');&lt;/script&gt;.

            A valid case in markdown is a &lt;https://en.wikipedia.org/wiki/Hyperlink&gt;

            <![CDATA[
            If using CDATA you don't need to escape, but this <script>alert('XSS');</script>
            should still not be executed.
            ]]>

            &gt; this is a
            > block quote
            > in markdown

            The paragraph after the quotation.

            <![CDATA[
            > block quote
            > in cdata
            ]]>

            If the description contains a code example, then e.g. "quotes" should not be escaped:

            ```
            if (0 &gt; 1 &amp;&amp; 0 &lt; 1) {
                System.out.println("impossible");
            }
            ```
       </description>
       <priority>3</priority>
       <properties>
           <property name="xpath">
               <value>
<![CDATA[
//ForStatement
]]>
               </value>
           </property>
           <property name="sampleRegexProperty" type="Regex" description="The property is of type regex" value="\/\*\s+(default|package)\s+\*\/" />
           <property name="XSSpropertyTest" type="String" description="&lt;script&gt;alert('XSS');&lt;/script&gt;" value="&lt;script&gt;alert('XSS');&lt;/script&gt;" />
           <property name="escapingNeeded" type="String" description="You should be able to use | in the description" value="this is escaped: |" />
       </properties>
       <example>
<![CDATA[
public class Bar {
    public boolean foo() {
      if (0 < 1) { // less-than should not be escaped in markdown
          String s = "abc"; // the quotes should not be escaped in markdown.
      }
    }
    // <script>alert('XSS');</script>
}
]]>
        </example>
    </rule>

    <rule name="OverrideBothEqualsAndHashcode"
          language="java"
          since="0.4"
          message="Ensure you override both equals() and hashCode()"
          class="net.sourceforge.pmd.lang.java.rule.errorprone.OverrideBothEqualsAndHashcodeRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#overridebothequalsandhashcode"
          minimumLanguageVersion="1.5"
          maximumLanguageVersion="11">
      <description>
            Override both `public boolean Object.equals(Object other)`, and `public int Object.hashCode()`, or override neither.
            Even if you are inheriting a `hashCode()` from a parent class, consider implementing hashCode and explicitly
            delegating to your superclass.

            Second paragraph.

                Code sample

            Third paragraph.
      </description>
      <priority>3</priority>
      <example>
  <![CDATA[
public class Bar {      // poor, missing a hashcode() method
    public boolean equals(Object o) {
      // do some comparison
    }
}

public class Baz {      // poor, missing an equals() method
    public int hashCode() {
      // return some hash value
    }
}

public class Foo {      // perfect, both methods provided
    public boolean equals(Object other) {
      // do some comparison
    }
    public int hashCode() {
      // return some hash value
    }
}

// A sample with double braces (#1898)
public class Foo {
    public List<String> bar() {
        return new ArrayList<String>(){{ addAll("a","b","c"); }};
    }
}
 ]]>
      </example>
    </rule>

    <rule name="JumbledIncrementer"
          language="java"
          since="1.0"
          message="Avoid modifying an outer loop incrementer in an inner loop for update expression"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#jumbledincrementer">
     <description>
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
     </description>
     <priority>3</priority>
     <properties>
         <property name="xpath">
             <value>
 <![CDATA[
//ForStatement
 [
  ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image
  =
  ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image
 ]
 ]]>
             </value>
         </property>
         <property name="sampleAdditionalProperty" type="String" description="This is a additional property for tests" value="the value" />
         <property name="sampleMultiStringProperty" type="List[String]" description="Test property with multiple strings" value="Value1,Value2" />
         <property name="sampleDeprecatedProperty" type="String" description="Deprecated! This is a sample deprecated property for tests" value="test" />
         <property name="sampleRegexProperty1" type="Regex" description="The property is of type regex" value="\/\*\s+(default|package)\s+\*\/" />
         <property name="sampleRegexProperty2" type="Regex" description="The property is of type regex" value="[a-z]*" />
         <property name="sampleRegexProperty3" type="Regex" description="The property is of type regex" value="\s+" />
         <property name="sampleRegexProperty4" type="Regex" description="The property is of type regex" value="_dd_" />
         <property name="sampleRegexProperty5" type="Regex" description="The property is of type regex" value="[0-9]{1,3}" />
         <property name="sampleRegexProperty6" type="Regex" description="The property is of type regex" value="\b" />
         <property name="sampleRegexProperty7" type="Regex" description="The property is of type regex" value="\n" />
     </properties>
     <example>
 <![CDATA[
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");
            }
        }
    }
}
 ]]>
     </example>
     </rule>

<rule name="DeprecatedSample"
      language="java"
      since="1.0"
      message="Sample rule, which is deprecated"
      class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
      externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#deprecatedsample"
      deprecated="true">
 <description>
Just some description of a deprecated rule.

RuleTag with quotes: Use {% rule "RenamedRule" %} instead.

RuleTag without quotes: Use {% rule RenamedRule %} instead.

RuleTag with full category and quotes: Use {% rule "java/sample/RenamedRule" %} instead.

RuleTag with full category and without quotes: Use {% rule java/sample/RenamedRule %} instead.
 </description>
 <priority>3</priority>
 <properties>
     <property name="xpath">
         <value>
<![CDATA[
//ForStatement
]]>
         </value>
     </property>
 </properties>
 </rule>

    <rule name="RenamedRule1" ref="JumbledIncrementer"/>

    <rule name="RenamedRule2" ref="rulesets/ruledoctest/sample.xml/JumbledIncrementer"/>

    <!-- variant 1 of a renamed rule. This is definitively within the same ruleset. -->
    <rule name="RenamedRule3" ref="JumbledIncrementer" deprecated="true" />

    <!-- see Rule deprecation policy: /docs/pages/pmd/devdocs/rule_deprecation.md -->
    <!-- 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 name="RenamedRule4" ref="rulesets/ruledoctest/sample.xml/JumbledIncrementer" deprecated="true" />

    <rule name="MovedRule" ref="rulesets/ruledoctest/sample2.xml/JumbledIncrementer"/>

</ruleset>
