Merge branch 'pr-1714'
This commit is contained in:
@ -29,13 +29,15 @@ public interface StatisticalRule extends Rule {
|
||||
|
||||
/** @deprecated Not useful, will not be replaced. */
|
||||
@Deprecated
|
||||
DoubleProperty SIGMA_DESCRIPTOR = new DoubleProperty("sigma", "Sigma value", -10000000d, 1000000d, null, 1.0f);
|
||||
DoubleProperty SIGMA_DESCRIPTOR = new DoubleProperty("sigma", "deprecated! Sigma value", -10000000d, 1000000d, null,
|
||||
1.0f);
|
||||
// TODO we should have one such property descriptor pro rule, and *not* share it, to allow setting specific defaults
|
||||
DoubleProperty MINIMUM_DESCRIPTOR = new DoubleProperty("minimum", "Minimum reporting threshold", -10000000d, 1000000000d, null,
|
||||
2.0f);
|
||||
/** @deprecated Not useful, will not be replaced. */
|
||||
@Deprecated
|
||||
IntegerProperty TOP_SCORE_DESCRIPTOR = new IntegerProperty("topscore", "Top score value", 1, 100, null, 3.0f);
|
||||
IntegerProperty TOP_SCORE_DESCRIPTOR = new IntegerProperty("topscore", "deprecated! Top score value", 1, 100,
|
||||
null, 3.0f);
|
||||
|
||||
void addDataPoint(DataPoint point);
|
||||
|
||||
|
@ -442,29 +442,12 @@ public class RuleDocGenerator {
|
||||
lines.add("|----|-------------|-----------|-----------|");
|
||||
for (PropertyDescriptor<?> propertyDescriptor : properties) {
|
||||
String description = propertyDescriptor.description();
|
||||
boolean isDeprecated = false;
|
||||
if (description != null && description.toLowerCase(Locale.ROOT)
|
||||
.startsWith(DEPRECATED_RULE_PROPERTY_MARKER)) {
|
||||
isDeprecated = true;
|
||||
final boolean isDeprecated = isDeprecated(propertyDescriptor);
|
||||
if (isDeprecated) {
|
||||
description = description.substring(DEPRECATED_RULE_PROPERTY_MARKER.length());
|
||||
}
|
||||
|
||||
String defaultValue = "";
|
||||
if (propertyDescriptor.defaultValue() != null) {
|
||||
if (propertyDescriptor.isMultiValue()) {
|
||||
@SuppressWarnings("unchecked") // multi valued properties are using a List
|
||||
MultiValuePropertyDescriptor<List<?>> multiPropertyDescriptor = (MultiValuePropertyDescriptor<List<?>>) propertyDescriptor;
|
||||
defaultValue = multiPropertyDescriptor.asDelimitedString(multiPropertyDescriptor.defaultValue());
|
||||
|
||||
// surround the delimiter with spaces, so that the browser can wrap
|
||||
// the value nicely
|
||||
defaultValue = defaultValue.replaceAll(Pattern.quote(
|
||||
String.valueOf(multiPropertyDescriptor.multiValueDelimiter())),
|
||||
" " + multiPropertyDescriptor.multiValueDelimiter() + " ");
|
||||
} else {
|
||||
defaultValue = String.valueOf(propertyDescriptor.defaultValue());
|
||||
}
|
||||
}
|
||||
String defaultValue = determineDefaultValueAsString(propertyDescriptor, rule, true);
|
||||
|
||||
String multiValued = "no";
|
||||
if (propertyDescriptor.isMultiValue()) {
|
||||
@ -483,11 +466,33 @@ public class RuleDocGenerator {
|
||||
lines.add("");
|
||||
}
|
||||
|
||||
lines.add("**Use this rule by referencing it:**");
|
||||
if (properties.isEmpty()) {
|
||||
lines.add("**Use this rule by referencing it:**");
|
||||
} else {
|
||||
lines.add("**Use this rule with the default properties by just referencing it:**");
|
||||
}
|
||||
lines.add("``` xml");
|
||||
lines.add("<rule ref=\"category/" + languageTersename + "/" + rulesetFilename + ".xml/" + rule.getName() + "\" />");
|
||||
lines.add("```");
|
||||
lines.add("");
|
||||
|
||||
if (properties.stream().anyMatch(it -> !isDeprecated(it))) {
|
||||
lines.add("**Use this rule and customize it:**");
|
||||
lines.add("``` xml");
|
||||
lines.add("<rule ref=\"category/" + languageTersename + "/" + rulesetFilename + ".xml/" + rule.getName() + "\">");
|
||||
lines.add(" <properties>");
|
||||
for (PropertyDescriptor<?> propertyDescriptor : properties) {
|
||||
if (!isDeprecated(propertyDescriptor)) {
|
||||
String defaultValue = determineDefaultValueAsString(propertyDescriptor, rule, false);
|
||||
lines.add(" <property name=\"" + propertyDescriptor.name() + "\" value=\""
|
||||
+ defaultValue + "\" />");
|
||||
}
|
||||
}
|
||||
lines.add(" </properties>");
|
||||
lines.add("</rule>");
|
||||
lines.add("```");
|
||||
lines.add("");
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(path, lines);
|
||||
@ -496,6 +501,34 @@ public class RuleDocGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDeprecated(PropertyDescriptor<?> propertyDescriptor) {
|
||||
return propertyDescriptor.description() != null
|
||||
&& propertyDescriptor.description().toLowerCase(Locale.ROOT).startsWith(DEPRECATED_RULE_PROPERTY_MARKER);
|
||||
}
|
||||
|
||||
private String determineDefaultValueAsString(PropertyDescriptor<?> propertyDescriptor, Rule rule, boolean pad) {
|
||||
String defaultValue = "";
|
||||
Object realDefaultValue = rule.getProperty(propertyDescriptor);
|
||||
@SuppressWarnings("unchecked") // just force it, we know it's the right type
|
||||
PropertyDescriptor<Object> captured = (PropertyDescriptor<Object>) propertyDescriptor;
|
||||
|
||||
if (realDefaultValue != null) {
|
||||
defaultValue = captured.asDelimitedString(realDefaultValue);
|
||||
|
||||
if (pad && propertyDescriptor.isMultiValue()) {
|
||||
@SuppressWarnings("unchecked") // multi valued properties are using a List
|
||||
MultiValuePropertyDescriptor<List<?>> multiPropertyDescriptor = (MultiValuePropertyDescriptor<List<?>>) propertyDescriptor;
|
||||
|
||||
// surround the delimiter with spaces, so that the browser can wrap
|
||||
// the value nicely
|
||||
defaultValue = defaultValue.replaceAll(Pattern.quote(
|
||||
String.valueOf(multiPropertyDescriptor.multiValueDelimiter())),
|
||||
" " + multiPropertyDescriptor.multiValueDelimiter() + " ");
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static String stripIndentation(String description) {
|
||||
if (description == null || description.isEmpty()) {
|
||||
return "";
|
||||
|
@ -76,11 +76,28 @@ public class JumbledIncrementerRule1 {
|
||||
|sampleRegexProperty6|\\b|The property is of type regex|no|
|
||||
|sampleRegexProperty7|\\n|The property is of type regex|no|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
**Use this rule with the default properties by just referencing it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/JumbledIncrementer" />
|
||||
```
|
||||
|
||||
**Use this rule and customize it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/JumbledIncrementer">
|
||||
<properties>
|
||||
<property name="sampleAdditionalProperty" value="the value" />
|
||||
<property name="sampleMultiStringProperty" value="Value1|Value2" />
|
||||
<property name="sampleRegexProperty1" value="\/\*\s+(default|package)\s+\*\/" />
|
||||
<property name="sampleRegexProperty2" value="[a-z]*" />
|
||||
<property name="sampleRegexProperty3" value="\s+" />
|
||||
<property name="sampleRegexProperty4" value="_dd_" />
|
||||
<property name="sampleRegexProperty5" value="[0-9]{1,3}" />
|
||||
<property name="sampleRegexProperty6" value="\b" />
|
||||
<property name="sampleRegexProperty7" value="\n" />
|
||||
</properties>
|
||||
</rule>
|
||||
```
|
||||
|
||||
## MovedRule
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>
|
||||
@ -223,11 +240,28 @@ public class JumbledIncrementerRule1 {
|
||||
|sampleRegexProperty6|\\b|The property is of type regex|no|
|
||||
|sampleRegexProperty7|\\n|The property is of type regex|no|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
**Use this rule with the default properties by just referencing it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/RenamedRule" />
|
||||
```
|
||||
|
||||
**Use this rule and customize it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/RenamedRule">
|
||||
<properties>
|
||||
<property name="sampleAdditionalProperty" value="the value" />
|
||||
<property name="sampleMultiStringProperty" value="Value1|Value2" />
|
||||
<property name="sampleRegexProperty1" value="\/\*\s+(default|package)\s+\*\/" />
|
||||
<property name="sampleRegexProperty2" value="[a-z]*" />
|
||||
<property name="sampleRegexProperty3" value="\s+" />
|
||||
<property name="sampleRegexProperty4" value="_dd_" />
|
||||
<property name="sampleRegexProperty5" value="[0-9]{1,3}" />
|
||||
<property name="sampleRegexProperty6" value="\b" />
|
||||
<property name="sampleRegexProperty7" value="\n" />
|
||||
</properties>
|
||||
</rule>
|
||||
```
|
||||
|
||||
## XSSInDocumentation
|
||||
|
||||
**Since:** PMD 0.1
|
||||
@ -296,7 +330,18 @@ public class Bar {
|
||||
|XSSpropertyTest <script>alert('XSS');</script>|<script>alert('XSS');</script>|<script>alert('XSS');</script>|no|
|
||||
|escapingNeeded|this is escaped: \||You should be able to use \| in the description|no|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
**Use this rule with the default properties by just referencing it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/XSSInDocumentation" />
|
||||
```
|
||||
|
||||
**Use this rule and customize it:**
|
||||
``` xml
|
||||
<rule ref="category/java/sample.xml/XSSInDocumentation">
|
||||
<properties>
|
||||
<property name="sampleRegexProperty" value="\/\*\s+(default|package)\s+\*\/" />
|
||||
<property name="XSSpropertyTest <script>alert('XSS');</script>" value="<script>alert('XSS');</script>" />
|
||||
<property name="escapingNeeded" value="this is escaped: |" />
|
||||
</properties>
|
||||
</rule>
|
||||
```
|
||||
|
Reference in New Issue
Block a user