checkstyle WhiteAround
WhiteAroundCheck script
This commit is contained in:
@@ -163,8 +163,8 @@
|
||||
<!-- <module name="NoWhitespaceBefore" /> -->
|
||||
<!-- <module name="ParenPad" /> -->
|
||||
<!-- <module name="TypecastParenPad" /> -->
|
||||
<!-- <module name="WhitespaceAfter" /> -->
|
||||
<!-- <module name="WhitespaceAround" /> -->
|
||||
<module name="WhitespaceAfter" />
|
||||
<module name="WhitespaceAround" />
|
||||
|
||||
</module>
|
||||
</module>
|
||||
|
||||
64
src/checkstyle/fixWhiteAround.gradle
Normal file
64
src/checkstyle/fixWhiteAround.gradle
Normal file
@@ -0,0 +1,64 @@
|
||||
task fixWhiteAround << {
|
||||
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.WhitespaceAfterCheck' ||
|
||||
error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck') {
|
||||
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)
|
||||
|
||||
println "Fixed line $line"
|
||||
|
||||
while (error && ln == (error.@line as int)) {
|
||||
error = thisErrors[errorInx++]
|
||||
}
|
||||
}
|
||||
|
||||
outSource += line + System.lineSeparator()
|
||||
}
|
||||
file.write(outSource)
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user