Skip to content

Commit

Permalink
Use 'spotless' ktlin code linter and formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokosi committed Jul 7, 2020
1 parent 5646258 commit 0983de2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -42,3 +43,14 @@ tasks.withType<DependencyUpdatesTask> {
}
}
}

spotless {
kotlin {
ktlint()
}
kotlinGradle {
// same as kotlin, but for .gradle.kts files (defaults to '*.gradle.kts')
target("*.gradle.kts")
ktlint()
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/pullpitok/App.kt
Original file line number Diff line number Diff line change
@@ -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<String>) {
if (invalidArguments(args)) {
Expand Down Expand Up @@ -44,8 +44,9 @@ private fun perAuthor(events: List<Event>): Map<String, List<Event>> = events
.groupBy { it.actor.login }

internal fun counters(
eventsPerAuthor: Map<String, List<Event>>,
predicate: (Event) -> Boolean): String {
eventsPerAuthor: Map<String, List<Event>>,
predicate: (Event) -> Boolean
): String {
eventsPerAuthor.entries
var counters = ""
for (events in eventsPerAuthor.entries) {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/pullpitok/github/EventClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ class EventClient {
}

private fun fail(message: String): Nothing = throw IllegalArgumentException(message)

}
7 changes: 3 additions & 4 deletions src/test/kotlin/pullpitok/AppTest.kt
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -38,5 +38,4 @@ class AppTest {
assertFalse(invalidArguments(arrayOf("org/repo")))
assertFalse(invalidArguments(arrayOf("org/repo", "token")))
}

}
3 changes: 1 addition & 2 deletions src/test/kotlin/pullpitok/github/EventClientTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pullpitok.github

import org.junit.Test
import kotlin.test.assertEquals
import org.junit.Test

class EventClientTest {

Expand All @@ -28,5 +28,4 @@ class EventClientTest {
}

private fun loadJsonEventFile() = EventClientTest::class.java.getResource("/events.json").readText()

}

0 comments on commit 0983de2

Please sign in to comment.