Skip to content

Commit

Permalink
add linting for kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderwiederin committed Nov 3, 2023
1 parent d78cab0 commit 3ca2427
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 29 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint-kotlin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run ktlintCheck

on:
pull_request:
types:
- opened

jobs:
lint-kotlin:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Run ktlintCheck on ldk-node-jvm
run: |
cd bindings/kotlin/ldk-node-jvm
./gradlew ktlintCheck
- name: Run ktlintCheck on ldk-node-android
run: |
cd bindings/kotlin/ldk-node-android
./gradlew ktlintCheck
12 changes: 9 additions & 3 deletions bindings/kotlin/ldk-node-android/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.*
import org.gradle.api.tasks.testing.logging.TestLogEvent.*

// library version is defined in gradle.properties
val libraryVersion: String by project

Expand All @@ -10,6 +7,7 @@ plugins {

id("maven-publish")
id("signing")
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
}

repositories {
Expand Down Expand Up @@ -106,3 +104,11 @@ signing {
// useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}

ktlint {
filter {
exclude { entry ->
entry.file.toString().contains("main")
}
}
}
35 changes: 24 additions & 11 deletions bindings/kotlin/ldk-node-jvm/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.*
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT

// library version is defined in gradle.properties
val libraryVersion: String by project
Expand All @@ -12,6 +16,7 @@ plugins {
id("java-library")
id("maven-publish")
id("signing")
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
}

repositories {
Expand All @@ -31,12 +36,12 @@ dependencies {
// Use the JUnit 5 integration.
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.1")

//// This dependency is exported to consumers, that is to say found on their compile classpath.
//api("org.apache.commons:commons-math3:3.6.1")
// // This dependency is exported to consumers, that is to say found on their compile classpath.
// api("org.apache.commons:commons-math3:3.6.1")

//// This dependency is used internally, and not exposed to consumers on their own compile classpath.
//implementation("com.google.guava:guava:31.1-jre")
// Align versions of all Kotlin components
// // This dependency is used internally, and not exposed to consumers on their own compile classpath.
// implementation("com.google.guava:guava:31.1-jre")
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

// Use the Kotlin JDK 8 standard library.
Expand All @@ -49,13 +54,13 @@ tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()

testLogging {
testLogging {
events(PASSED, SKIPPED, FAILED, STANDARD_OUT, STANDARD_ERROR)
exceptionFormat = FULL
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
showStandardStreams = true
}
}

Expand Down Expand Up @@ -88,8 +93,8 @@ afterEvaluate {
developers {
developer {
id.set("tnull")
name.set("Elias Rohrer")
email.set("[email protected]")
name.set("Elias Rohrer")
email.set("[email protected]")
}
}
}
Expand All @@ -111,3 +116,11 @@ signing {
// useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications)
}

ktlint {
filter {
exclude { entry ->
entry.file.toString().contains("main")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/
package org.lightningdevkit.ldknode

import kotlin.UInt
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.io.path.createTempDirectory
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import kotlin.UInt
import kotlin.io.path.createTempDirectory
import kotlin.test.Test
import kotlin.test.assertEquals

fun runCommandAndWait(vararg cmd: String): String {
println("Running command \"${cmd.joinToString(" ")}\"")
Expand All @@ -29,7 +29,7 @@ fun mine(blocks: UInt): String {
val output = runCommandAndWait("bitcoin-cli", "-regtest", "generatetoaddress", blocks.toString(), address)
println("Mining output: $output")
val re = Regex("\n.+\n\\]$")
val lastBlock = re.find(output)!!.value.replace("]","").replace("\"", "").replace("\n","").trim()
val lastBlock = re.find(output)!!.value.replace("]", "").replace("\"", "").replace("\n", "").trim()
println("Last block: $lastBlock")
return lastBlock
}
Expand All @@ -54,32 +54,32 @@ fun setup() {

fun waitForTx(esploraEndpoint: String, txid: String) {
var esploraPickedUpTx = false
val re = Regex("\"txid\":\"$txid\"");
val re = Regex("\"txid\":\"$txid\"")
while (!esploraPickedUpTx) {
val client = HttpClient.newBuilder().build()
val request = HttpRequest.newBuilder()
.uri(URI.create(esploraEndpoint + "/tx/" + txid))
.build();
.build()

val response = client.send(request, HttpResponse.BodyHandlers.ofString());
val response = client.send(request, HttpResponse.BodyHandlers.ofString())

esploraPickedUpTx = re.containsMatchIn(response.body());
esploraPickedUpTx = re.containsMatchIn(response.body())
Thread.sleep(500)
}
}

fun waitForBlock(esploraEndpoint: String, blockHash: String) {
var esploraPickedUpBlock = false
val re = Regex("\"in_best_chain\":true");
val re = Regex("\"in_best_chain\":true")
while (!esploraPickedUpBlock) {
val client = HttpClient.newBuilder().build()
val request = HttpRequest.newBuilder()
.uri(URI.create(esploraEndpoint + "/block/" + blockHash + "/status"))
.build();
.build()

val response = client.send(request, HttpResponse.BodyHandlers.ofString());
val response = client.send(request, HttpResponse.BodyHandlers.ofString())

esploraPickedUpBlock = re.containsMatchIn(response.body());
esploraPickedUpBlock = re.containsMatchIn(response.body())
Thread.sleep(500)
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ class LibraryTest {

val fundingTxid = when (channelPendingEvent1) {
is Event.ChannelPending -> channelPendingEvent1.fundingTxo.txid
else -> return
else -> return
}

waitForTx(esploraEndpoint, fundingTxid)
Expand Down Expand Up @@ -202,7 +202,7 @@ class LibraryTest {

val channelId = when (channelReadyEvent2) {
is Event.ChannelReady -> channelReadyEvent2.channelId
else -> return
else -> return
}

val invoice = node2.receivePayment(2500000u, "asdf", 9217u)
Expand Down
15 changes: 15 additions & 0 deletions scripts/format_kotlin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
LDK_NODE_ANDROID_DIR="bindings/kotlin/ldk-node-android"
LDK_NODE_JVM_DIR="bindings/kotlin/ldk-node-jvm"

# Run ktlintFormat in ldk-node-android
(
cd $LDK_NODE_ANDROID_DIR || exit 1
./gradlew ktlintFormat
)

# Run ktlintFormat in ldk-node-jvm
(
cd $LDK_NODE_JVM_DIR || exit 1
./gradlew ktlintFormat
)

0 comments on commit 3ca2427

Please sign in to comment.