Skip to content

Commit 4cddacd

Browse files
myyklihaoyi
andauthored
Lint Kotlin examples (com-lihaoyi#3923)
* [x] Needs com-lihaoyi#3919 as this builds on it * [x] Update this to use com-lihaoyi#3961, switching to `KtlintModule` * [x] Needs com-lihaoyi#3966 to disable ktlint for some files Last change I think needed for com-lihaoyi#3829 Overview: * Changes `KtfmtModule` to set the error code when there's changes like is true of the other formatters. * Some simplifications were made to the `example/package.mill` based on similarities with Java/Kotlin. * Files were formatted * CI was updated --------- Co-authored-by: Li Haoyi <[email protected]>
1 parent 122d2e6 commit 4cddacd

File tree

72 files changed

+955
-808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+955
-808
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ insert_final_newline = true
1313
charset = utf-8
1414
indent_style = space
1515
indent_size = 2
16+
17+
[*.{kt,kts}]
18+
ktlint_code_style = intellij_idea
19+
ktlint_standard_no-wildcard-imports = disabled
20+
21+
[example/kotlinlib/linting/**/*]
22+
ktlint = disabled
23+
24+
[kotlinlib/test/resources/contrib/ktfmt/**/*]
25+
ktlint = disabled
26+
27+
[kotlinlib/test/resources/kotlin-js/foo/test/src/foo/**/*]
28+
ktlint = disabled

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@ jobs:
183183
uses: ./.github/workflows/run-mill-action.yml
184184
with:
185185
java-version: '17'
186-
buildcmd: ./mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources && ./mill -i __.mimaReportBinaryIssues && ./mill -i __.fix --check && ./mill -i mill.javalib.palantirformat.PalantirFormatModule/ --check
186+
buildcmd: ./mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources + __.mimaReportBinaryIssues + __.fix --check + mill.javalib.palantirformat.PalantirFormatModule/ --check + mill.kotlinlib.ktlint.KtlintModule/checkFormatAll --check
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package foo
22

3-
import kotlinx.html.h1
4-
import kotlinx.html.stream.createHTML
53
import com.github.ajalt.clikt.core.CliktCommand
64
import com.github.ajalt.clikt.parameters.options.option
75
import com.github.ajalt.clikt.parameters.options.required
6+
import kotlinx.html.h1
7+
import kotlinx.html.stream.createHTML
88

9-
class Foo: CliktCommand() {
10-
val text by option("-t", "--text", help="text to insert").required()
9+
class Foo : CliktCommand() {
10+
val text by option("-t", "--text", help = "text to insert").required()
1111

1212
override fun run() {
1313
echo(generateHtml(text))
1414
}
1515
}
1616

17-
fun generateHtml(text: String): String {
18-
return createHTML(prettyPrint = false).h1 { text(text) }.toString()
19-
}
17+
fun generateHtml(text: String): String = createHTML(prettyPrint = false).h1 { text(text) }.toString()
2018

2119
fun main(args: Array<String>) = Foo().main(args)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package foo
22

3-
import foo.generateHtml
43
import io.kotest.core.spec.style.FunSpec
54
import io.kotest.matchers.shouldBe
65

7-
class FooTest : FunSpec({
8-
test("testSimple") {
9-
generateHtml("hello") shouldBe "<h1>hello</h1>"
10-
}
6+
class FooTest :
7+
FunSpec({
8+
test("testSimple") {
9+
generateHtml("hello") shouldBe "<h1>hello</h1>"
10+
}
1111

12-
test("testEscaping") {
13-
generateHtml("<hello>") shouldBe "<h1>&lt;hello&gt;</h1>"
14-
}
15-
})
12+
test("testEscaping") {
13+
generateHtml("<hello>") shouldBe "<h1>&lt;hello&gt;</h1>"
14+
}
15+
})

example/kotlinlib/basic/2-custom-build-logic/foo/src/foo/Foo.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package foo
22

33
import java.io.IOException
44

5-
fun getLineCount(): String? {
6-
return try {
7-
::main.javaClass.classLoader
8-
.getResourceAsStream("line-count.txt")
9-
.readAllBytes()
10-
.toString(Charsets.UTF_8)
11-
} catch (e: IOException) {
12-
null
13-
}
5+
fun getLineCount(): String? = try {
6+
::main.javaClass.classLoader
7+
.getResourceAsStream("line-count.txt")
8+
.readAllBytes()
9+
.toString(Charsets.UTF_8)
10+
} catch (e: IOException) {
11+
null
1412
}
1513

16-
fun main() = println("Line Count: " + getLineCount())
17-
14+
fun main() {
15+
var msg = "Line Count: " + getLineCount()
16+
println(msg)
17+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package foo
22

3-
import foo.getLineCount
43
import io.kotest.core.spec.style.FunSpec
54
import io.kotest.matchers.shouldBe
65

7-
class FooTests : FunSpec({
6+
class FooTests :
7+
FunSpec({
88

9-
test("testSimple") {
10-
val expectedLineCount = 12
11-
val actualLineCount = getLineCount()?.trim().let { Integer.parseInt(it) }
12-
actualLineCount shouldBe expectedLineCount
13-
}
14-
})
9+
test("testSimple") {
10+
val expectedLineCount = 12
11+
val actualLineCount = getLineCount()?.trim().let { Integer.parseInt(it) }
12+
actualLineCount shouldBe expectedLineCount
13+
}
14+
})

example/kotlinlib/basic/3-multi-module/bar/src/bar/Bar.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package bar
33
import kotlinx.html.h1
44
import kotlinx.html.stream.createHTML
55

6-
fun generateHtml(text: String): String {
7-
return createHTML(prettyPrint = false).h1 { text(text) }.toString()
8-
}
6+
fun generateHtml(text: String): String = createHTML(prettyPrint = false).h1 { text(text) }.toString()
97

108
fun main(args: Array<String>) {
119
println("Bar.value: " + generateHtml(args[0]))
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package bar
22

3-
import bar.generateHtml
43
import io.kotest.core.spec.style.FunSpec
54
import io.kotest.matchers.shouldBe
65

7-
class BarTests : FunSpec({
6+
class BarTests :
7+
FunSpec({
88

9-
test("simple") {
10-
val result = generateHtml("hello")
11-
result shouldBe "<h1>hello</h1>"
12-
}
9+
test("simple") {
10+
val result = generateHtml("hello")
11+
result shouldBe "<h1>hello</h1>"
12+
}
1313

14-
test("escaping") {
15-
val result = generateHtml("<hello>")
16-
result shouldBe "<h1>&lt;hello&gt;</h1>"
17-
}
18-
})
14+
test("escaping") {
15+
val result = generateHtml("<hello>")
16+
result shouldBe "<h1>&lt;hello&gt;</h1>"
17+
}
18+
})

example/kotlinlib/basic/3-multi-module/foo/src/foo/Foo.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.github.ajalt.clikt.parameters.options.required
66

77
const val VALUE: String = "hello"
88

9-
class Foo: CliktCommand() {
9+
class Foo : CliktCommand() {
1010
val fooText by option("--foo-text").required()
1111
val barText by option("--bar-text").required()
1212

@@ -15,7 +15,10 @@ class Foo: CliktCommand() {
1515
}
1616
}
1717

18-
fun mainFunction(fooText: String, barText: String) {
18+
fun mainFunction(
19+
fooText: String,
20+
barText: String,
21+
) {
1922
println("Foo.value: " + VALUE)
2023
println("Bar.value: " + bar.generateHtml(barText))
2124
}

example/kotlinlib/basic/4-compat-modules/foo/src/test/java/foo/FooTests.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package foo
33
import io.kotest.core.spec.style.FunSpec
44
import io.kotest.matchers.shouldBe
55

6-
class FooTests : FunSpec({
7-
test("hello") {
8-
val result = hello()
9-
result shouldBe "Hello World, Earth"
10-
}
11-
})
6+
class FooTests :
7+
FunSpec({
8+
test("hello") {
9+
val result = hello()
10+
result shouldBe "Hello World, Earth"
11+
}
12+
})

0 commit comments

Comments
 (0)