From 0983de2ef1a731a8c8403a9b59ea81f32db949b3 Mon Sep 17 00:00:00 2001 From: Nicolas Kosinski Date: Sun, 3 Nov 2019 11:19:23 +0100 Subject: [PATCH] Use 'spotless' ktlin code linter and formatter https://github.com/diffplug/spotless https://github.com/diffplug/spotless/tree/master/plugin-gradle --- README.md | 4 ++++ build.gradle.kts | 12 ++++++++++++ src/main/kotlin/pullpitok/App.kt | 7 ++++--- src/main/kotlin/pullpitok/github/EventClient.kt | 1 - src/test/kotlin/pullpitok/AppTest.kt | 7 +++---- src/test/kotlin/pullpitok/github/EventClientTest.kt | 3 +-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 20b497a..ea1da8a 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ An executable file named `pullpitoK` should be generated in the current director ## Dev tasks +### Format the code + + ./gradlew spotlessApply + ### Inspect the code Code inspection is configured on the master branch. See the [sonarcloud.io's dashboard](https://sonarcloud.io/dashboard?id=nicokosi_pullpitoK). diff --git a/build.gradle.kts b/build.gradle.kts index 81312e8..acb118d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("com.github.ben-manes.versions") version "0.28.0" id("com.github.johnrengelman.shadow") version "5.2.0" id("com.adarshr.test-logger") version "2.0.0" + id("com.diffplug.gradle.spotless") version "4.5.1" application } @@ -42,3 +43,14 @@ tasks.withType { } } } + +spotless { + kotlin { + ktlint() + } + kotlinGradle { + // same as kotlin, but for .gradle.kts files (defaults to '*.gradle.kts') + target("*.gradle.kts") + ktlint() + } +} diff --git a/src/main/kotlin/pullpitok/App.kt b/src/main/kotlin/pullpitok/App.kt index d0e1718..07750e4 100644 --- a/src/main/kotlin/pullpitok/App.kt +++ b/src/main/kotlin/pullpitok/App.kt @@ -1,10 +1,10 @@ package pullpitok +import kotlin.system.exitProcess import pullpitok.github.Action import pullpitok.github.Event import pullpitok.github.EventClient import pullpitok.github.Type -import kotlin.system.exitProcess fun main(args: Array) { if (invalidArguments(args)) { @@ -44,8 +44,9 @@ private fun perAuthor(events: List): Map> = events .groupBy { it.actor.login } internal fun counters( - eventsPerAuthor: Map>, - predicate: (Event) -> Boolean): String { + eventsPerAuthor: Map>, + predicate: (Event) -> Boolean +): String { eventsPerAuthor.entries var counters = "" for (events in eventsPerAuthor.entries) { diff --git a/src/main/kotlin/pullpitok/github/EventClient.kt b/src/main/kotlin/pullpitok/github/EventClient.kt index 2ccc1eb..8ea21cb 100644 --- a/src/main/kotlin/pullpitok/github/EventClient.kt +++ b/src/main/kotlin/pullpitok/github/EventClient.kt @@ -39,5 +39,4 @@ class EventClient { } private fun fail(message: String): Nothing = throw IllegalArgumentException(message) - } diff --git a/src/test/kotlin/pullpitok/AppTest.kt b/src/test/kotlin/pullpitok/AppTest.kt index 2cefa46..9d85445 100644 --- a/src/test/kotlin/pullpitok/AppTest.kt +++ b/src/test/kotlin/pullpitok/AppTest.kt @@ -1,12 +1,12 @@ package pullpitok +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue import org.junit.Test import pullpitok.github.Actor import pullpitok.github.Event import pullpitok.github.Payload -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue class AppTest { @@ -38,5 +38,4 @@ class AppTest { assertFalse(invalidArguments(arrayOf("org/repo"))) assertFalse(invalidArguments(arrayOf("org/repo", "token"))) } - } diff --git a/src/test/kotlin/pullpitok/github/EventClientTest.kt b/src/test/kotlin/pullpitok/github/EventClientTest.kt index dcf85fd..7aa5d58 100644 --- a/src/test/kotlin/pullpitok/github/EventClientTest.kt +++ b/src/test/kotlin/pullpitok/github/EventClientTest.kt @@ -1,7 +1,7 @@ package pullpitok.github -import org.junit.Test import kotlin.test.assertEquals +import org.junit.Test class EventClientTest { @@ -28,5 +28,4 @@ class EventClientTest { } private fun loadJsonEventFile() = EventClientTest::class.java.getResource("/events.json").readText() - }