Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ktlint code linter via Spotless Gradle plugin #26

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/pullpitoK

# Created by https://www.gitignore.io/api/gradle,kotlin,eclipse,intellij,visualstudiocode
# Edit at https://www.gitignore.io/?templates=gradle,kotlin,eclipse,intellij,visualstudiocode

### Eclipse ###
# Created by https://www.toptal.com/developers/gitignore/api/gradle,kotlin,eclipse,intellij+all,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=gradle,kotlin,eclipse,intellij+all,visualstudiocode

### Eclipse ###
.metadata
bin/
tmp/
Expand Down Expand Up @@ -54,26 +55,23 @@ local.properties

# Annotation Processing
.apt_generated/
.apt_generated_test/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project

### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
Expand Down Expand Up @@ -103,9 +101,14 @@ local.properties
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/modules.xml
.idea/*.iml
.idea/modules
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/
Expand Down Expand Up @@ -140,13 +143,18 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint
Expand Down Expand Up @@ -182,14 +190,15 @@ hs_err_pid*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### Gradle ###
.gradle
/build/
build/

# Ignore Gradle GUI config
gradle-app.setting
Expand All @@ -206,7 +215,4 @@ gradle-app.setting
### Gradle Patch ###
**/build/

# End of https://www.gitignore.io/api/gradle,kotlin,eclipse,intellij,visualstudiocode
/.idea/sonarIssues.xml
/pullpitoK
/libsunec.*
# End of https://www.toptal.com/developers/gitignore/api/gradle,kotlin,eclipse,intellij+all,visualstudiocode
5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

16 changes: 0 additions & 16 deletions .idea/compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

25 changes: 0 additions & 25 deletions .idea/jarRepositories.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/vcs.xml

This file was deleted.

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()

}