Skip to content

Commit

Permalink
Issue #15053: Made google style guide severity property define-able b…
Browse files Browse the repository at this point in the history
…y system variable
  • Loading branch information
Zopsss authored and rnveach committed Jun 23, 2024
1 parent 1af42ed commit a7462da
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<property name="charset" value="UTF-8"/>

<property name="severity" value="warning"/>
<property name="severity" value="${org.checkstyle.google.severity}" default="warning"/>

<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,45 @@ public void testExistingTargetFileButWithoutReadAccess(
.isEqualTo("");
}

@Test
public void testCustomSeverityVariableForGoogleConfig(@SysOut Capturable systemOut) {
assertMainReturnCode(1, "-c", "/google_checks.xml",
"-p", getPath("InputMainCustomSeverityForGoogleConfig.properties"),
getPath("InputMainCustomSeverityForGoogleConfig.java"));

final String expectedOutputStart = addEndOfLine(auditStartMessage.getMessage())
+ "[ERROR] ";
final String expectedOutputEnd = addEndOfLine(
"InputMainCustomSeverityForGoogleConfig.java:3:1:"
+ " Missing a Javadoc comment. [MissingJavadocType]",
auditFinishMessage.getMessage());
assertWithMessage("Unexpected output log")
.that(systemOut.getCapturedData())
.startsWith(expectedOutputStart);
assertWithMessage("Unexpected output log")
.that(systemOut.getCapturedData())
.endsWith(expectedOutputEnd);
}

@Test
public void testDefaultSeverityVariableForGoogleConfig(@SysOut Capturable systemOut) {
assertMainReturnCode(0, "-c", "/google_checks.xml",
getPath("InputMainCustomSeverityForGoogleConfig.java"));

final String expectedOutputStart = addEndOfLine(auditStartMessage.getMessage())
+ "[WARN] ";
final String expectedOutputEnd = addEndOfLine(
"InputMainCustomSeverityForGoogleConfig.java:3:1:"
+ " Missing a Javadoc comment. [MissingJavadocType]",
auditFinishMessage.getMessage());
assertWithMessage("Unexpected output log")
.that(systemOut.getCapturedData())
.startsWith(expectedOutputStart);
assertWithMessage("Unexpected output log")
.that(systemOut.getCapturedData())
.endsWith(expectedOutputEnd);
}

@Test
public void testNonExistentConfigFile(@SysErr Capturable systemErr,
@SysOut Capturable systemOut) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.puppycrawl.tools.checkstyle.main;

public class InputMainCustomSeverityForGoogleConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.checkstyle.google.severity=error
17 changes: 17 additions & 0 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,23 @@
</table>
</div>
</subsection>
<subsection name="Severity Level" id="Google_Severity_Level">
<p>
To adjust the default severity level for violations using Checkstyle's
Google style configuration, set the following system property:
</p>
<p>
<code>org.checkstyle.google.severity</code>
</p>
<p>
For detailed guidance on severity levels, refer to the
<a href="./property_types.html#SeverityLevel">Severity Level</a>.
To configure this property, see the instructions for the
<a href="./cmdline.html#Command_line_usage">CLI's <code>-p</code> option</a> , or use the
<a href="./anttask.html#Parameters"><code>properties</code> parameter in Ant</a>,
or set the Java system property before running Checkstyle.
</p>
</subsection>
<subsection name="Suppressions" id="Google_Suppressions">
<p>
It is possible to suppress some violations by embeded filters
Expand Down

0 comments on commit a7462da

Please sign in to comment.