checkstyle MutableException
checkstyle EmptyBlock checkstyle fixRightCurly Script checkstyle EmptyStatement checkstyle RightCurly checkstyle TailingWhite checkstyle NeedBraces Fix the line separator in the `fixRightCurly.gradle`
This commit is contained in:
committed by
Artem Bilan
parent
c0b19e61b5
commit
842aded9a4
@@ -31,27 +31,27 @@
|
||||
<!-- </module> -->
|
||||
|
||||
<!-- Block Checks -->
|
||||
<!-- <module name="EmptyBlock"> -->
|
||||
<!-- <property name="option" value="text" /> -->
|
||||
<!-- </module> -->
|
||||
<!-- <module name="LeftCurly" /> -->
|
||||
<!-- <module name="RightCurly"> -->
|
||||
<!-- <property name="option" value="alone" /> -->
|
||||
<!-- </module> -->
|
||||
<!-- <module name="NeedBraces" /> -->
|
||||
<!-- <module name="AvoidNestedBlocks" /> -->
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="text" />
|
||||
</module>
|
||||
<module name="LeftCurly" />
|
||||
<module name="RightCurly">
|
||||
<property name="option" value="alone" />
|
||||
</module>
|
||||
<module name="NeedBraces" />
|
||||
<module name="AvoidNestedBlocks" />
|
||||
|
||||
<!-- Class Design -->
|
||||
<module name="FinalClass" />
|
||||
<module name="InterfaceIsType" />
|
||||
<module name="HideUtilityClassConstructor" />
|
||||
<!-- <module name="MutableException" /> -->
|
||||
<module name="MutableException" />
|
||||
<module name="InnerTypeLast" />
|
||||
<module name="OneTopLevelClass" />
|
||||
|
||||
<!-- Coding -->
|
||||
<module name="CovariantEquals" />
|
||||
<!-- <module name="EmptyStatement" /> -->
|
||||
<module name="EmptyStatement" />
|
||||
<!-- <module name="EqualsHashCode" /> -->
|
||||
<!-- <module name="InnerAssignment" /> -->
|
||||
<!-- <module name="SimplifyBooleanExpression" /> -->
|
||||
@@ -148,11 +148,11 @@
|
||||
<!-- value="Please use AssertJ imports." /> -->
|
||||
<!-- <property name="ignoreComments" value="true" /> -->
|
||||
<!-- </module> -->
|
||||
<!-- <module name="Regexp"> -->
|
||||
<!-- <property name="format" value="[ \t]+$" /> -->
|
||||
<!-- <property name="illegalPattern" value="true" /> -->
|
||||
<!-- <property name="message" value="Trailing whitespace" /> -->
|
||||
<!-- </module> -->
|
||||
<module name="Regexp">
|
||||
<property name="format" value="[ \t]+$" />
|
||||
<property name="illegalPattern" value="true" />
|
||||
<property name="message" value="Trailing whitespace" />
|
||||
</module>
|
||||
|
||||
<!-- Whitespace -->
|
||||
<!-- <module name="GenericWhitespace" /> -->
|
||||
|
||||
63
src/checkstyle/fixRightCurly.gradle
Normal file
63
src/checkstyle/fixRightCurly.gradle
Normal file
@@ -0,0 +1,63 @@
|
||||
task fixRightCurly << {
|
||||
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.blocks.RightCurlyCheck') {
|
||||
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 index = (error.@column as int) + 1
|
||||
def chars = line.toCharArray()
|
||||
def nextLine = System.lineSeparator()
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (chars[i] == '\t') { // tabs before code == 8
|
||||
index -= 7;
|
||||
nextLine += '\t'
|
||||
}
|
||||
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
line = line.substring(0, index-1) + nextLine + 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