Skip to content

Commit faeb727

Browse files
committed
Add kotlin-dense, and make it play nicely with java.gradle.
1 parent 7687b0c commit faeb727

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/main/resources/spotless/java.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
def license =.proj('license', 'supported: [apache, confidential, lgpl-2.1]')
22
boolean setLicenseHeaderYearsFromGitHistory = 'true'.equals(project.findProperty('spotlessSetLicenseHeaderYearsFromGitHistory'))
33

4+
ext.spotless_java_applied = true
5+
46
apply plugin: 'com.diffplug.spotless'
57
spotless {
68
if (!setLicenseHeaderYearsFromGitHistory) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
def license =.proj('license', 'supported: [apache, confidential, lgpl-2.1]')
2+
boolean setLicenseHeaderYearsFromGitHistory = 'true'.equals(project.findProperty('spotlessSetLicenseHeaderYearsFromGitHistory'))
3+
4+
def spotless_java_applied = hasProperty('spotless_java_applied') && ext.spotless_java_applied
5+
6+
apply plugin: 'com.diffplug.spotless'
7+
spotless {
8+
if (!spotless_java_applied) {
9+
if (!setLicenseHeaderYearsFromGitHistory) {
10+
ratchetFrom 'origin/main'
11+
}
12+
groovyGradle {
13+
clearSteps() // play nicely with java.gradle
14+
target '*.gradle', 'buildSrc/*.gradle'
15+
greclipse()
16+
indentWithSpaces(2)
17+
}
18+
}
19+
if (plugins.hasPlugin('org.jetbrains.kotlin.jvm') || plugins.hasPlugin('org.jetbrains.kotlin.multiplatform')) {
20+
kotlin {
21+
clearSteps() // play nicely with java.gradle
22+
target 'src/**/*.kt'
23+
licenseHeaderFile 干.file("spotless/license-${license}.java")
24+
ktfmt()
25+
if (spotless_java_applied) {
26+
indentWithTabs(2)
27+
}
28+
for (modifier in [
29+
'',
30+
'override ',
31+
'public ',
32+
'protected ',
33+
'private ',
34+
'internal ',
35+
'infix ',
36+
'expected ',
37+
'actual ',
38+
'@JvmStatic '
39+
]) {
40+
for (key in [
41+
'inline',
42+
'fun',
43+
'abstract fun',
44+
'suspend fun',
45+
'val',
46+
'override'
47+
]) {
48+
String toCheck = "$modifier$key"
49+
replaceRegex("dense $toCheck", "\n\n(\\s*)$toCheck ", "\n\$1$toCheck ")
50+
}
51+
}
52+
replaceRegex("dense test order", "@Test(\\s*)@Order\\((\\d+)\\)", "@Test @Order(\$2)")
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)