checkstyle Misc Rules

checkstyle Nesting

checkstyle GenericWhitespace

checkstyle MethodParamPad

checkstyle NoWhiteSpace

checkstyle ParenPad Script

checkstyle ParenPad
This commit is contained in:
Gary Russell
2016-04-05 14:58:29 -04:00
committed by Artem Bilan
parent 05cc7be644
commit 57f96bb759
87 changed files with 737 additions and 628 deletions

View File

@@ -52,21 +52,21 @@
<!-- Coding -->
<module name="CovariantEquals" />
<module name="EmptyStatement" />
<!-- <module name="EqualsHashCode" /> -->
<module name="EqualsHashCode" />
<!-- <module name="InnerAssignment" /> -->
<!-- <module name="SimplifyBooleanExpression" /> -->
<!-- <module name="SimplifyBooleanReturn" /> -->
<!-- <module name="StringLiteralEquality" /> -->
<!-- <module name="NestedForDepth"> -->
<!-- <property name="max" value="3" /> -->
<!-- </module> -->
<!-- <module name="NestedIfDepth"> -->
<!-- <property name="max" value="3" /> -->
<!-- </module> -->
<!-- <module name="NestedTryDepth"> -->
<!-- <property name="max" value="3" /> -->
<!-- </module> -->
<!-- <module name="MultipleVariableDeclarations" /> -->
<module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
<module name="StringLiteralEquality" />
<module name="NestedForDepth">
<property name="max" value="3" />
</module>
<module name="NestedIfDepth">
<property name="max" value="4" />
</module>
<module name="NestedTryDepth">
<property name="max" value="3" />
</module>
<module name="MultipleVariableDeclarations" />
<module name="RequireThis">
<property name="checkMethods" value="false" />
</module>
@@ -119,10 +119,12 @@
<!-- </module> -->
<!-- Miscellaneous -->
<!-- <module name="CommentsIndentation" /> -->
<!-- <module name="UpperEll" /> -->
<!-- <module name="ArrayTypeStyle" /> -->
<!-- <module name="OuterTypeFilename" /> -->
<module name="CommentsIndentation">
<property name="tokens" value="BLOCK_COMMENT_BEGIN" />
</module>
<module name="UpperEll" />
<module name="ArrayTypeStyle" />
<module name="OuterTypeFilename" />
<!-- Modifiers -->
<module name="RedundantModifier" />
@@ -155,14 +157,14 @@
</module>
<!-- Whitespace -->
<!-- <module name="GenericWhitespace" /> -->
<!-- <module name="MethodParamPad" /> -->
<!-- <module name="NoWhitespaceAfter" > -->
<!-- <property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, ARRAY_DECLARATOR"/> -->
<!-- </module> -->
<!-- <module name="NoWhitespaceBefore" /> -->
<!-- <module name="ParenPad" /> -->
<!-- <module name="TypecastParenPad" /> -->
<module name="GenericWhitespace" />
<module name="MethodParamPad" />
<module name="NoWhitespaceAfter" >
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, ARRAY_DECLARATOR"/>
</module>
<module name="NoWhitespaceBefore" />
<module name="ParenPad" />
<module name="TypecastParenPad" />
<module name="WhitespaceAfter" />
<module name="WhitespaceAround" />

View File

@@ -0,0 +1,63 @@
task fixParenPad << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def thisErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck' ||
error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck') {
thisErrors.add(error)
}
}
if (thisErrors) {
def errorInx = 0
def error = thisErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (error && ln == (error.@line as int)) {
def message = error.@message
def index = (error.@column as int) - 1
def chars = line.toCharArray()
for (int i = 0; i < index; i++) {
if (chars[i] == '\t') { // tabs before code == 8
index -= 7;
}
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
break;
}
}
line = line.substring(0, index) + line.substring(index + 1)
println "Fixed line $line"
while (error && ln == (error.@line as int)) {
error = thisErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}