Skip to content

Commit ce539f2

Browse files
authored
Add Ktlint as code formatter (#1405)
* Added ktlint config * Remove detekt
1 parent 0e3cf4a commit ce539f2

File tree

527 files changed

+4008
-2360
lines changed

Some content is hidden

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

527 files changed

+4008
-2360
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Some KtLint rules
2+
[*.{kt,kts}]
3+
indent_size=2
4+
insert_final_newline=true
5+
max_line_length=off

build.gradle

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ buildscript {
2121
// Constants
2222
ankKotlinVersion = '1.3.11'
2323
daggerVersion = '2.21'
24-
detekt_version = '1.0.0-RC12'
2524
dokka_version = '0.9.18'
25+
ktlint_version = '7.3.0'
2626
gradleVersionsPluginVersion = '0.21.0'
2727
jUnitVersion = '4.12'
2828
jUnitVintageVersion = '5.4.0'
@@ -55,7 +55,7 @@ buildscript {
5555
classpath 'org.ajoberstar:gradle-git-publish:2.0.0'
5656
classpath "net.rdrei.android.buildtimetracker:gradle-plugin:0.11.1"
5757
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
58-
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
58+
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_version"
5959
}
6060
}
6161

@@ -86,7 +86,7 @@ subprojects { project ->
8686
apply plugin: 'kotlin'
8787
apply plugin: 'jacoco'
8888
apply plugin: 'org.jetbrains.dokka'
89-
apply plugin: 'io.gitlab.arturbosch.detekt'
89+
apply plugin: "org.jlleitschuh.gradle.ktlint"
9090

9191
archivesBaseName = POM_ARTIFACT_ID
9292

@@ -118,13 +118,6 @@ subprojects { project ->
118118

119119
}
120120

121-
detekt {
122-
toolVersion = detekt_version
123-
input = files("src/main/java", "src/main/kotlin", "src/test/kotlin")
124-
parallel = true
125-
config = files("${rootProject.projectDir}/detekt.yml")
126-
}
127-
128121
task codeCoverageReport(type: JacocoReport) {
129122
reports {
130123
xml.enabled true

detekt.yml

Lines changed: 0 additions & 108 deletions
This file was deleted.

modules/ank/arrow-ank-gradle/src/main/kotlin/arrow/ank/AnkExtension.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import java.io.File
66
data class AnkExtension(
77
var source: File? = null,
88
var target: File? = null,
9-
var classpath: FileCollection? = null)
9+
var classpath: FileCollection? = null
10+
)

modules/ank/arrow-ank-gradle/src/main/kotlin/arrow/ank/AnkPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ class AnkPlugin : Plugin<Project> {
2626
)
2727
}
2828
}
29-
}
29+
}

modules/ank/arrow-ank/src/main/kotlin/arrow/ank/algebra.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ interface AnkOps {
2525
suspend fun generateFile(path: Path, newContent: Sequence<String>): Path
2626

2727
suspend fun printConsole(msg: String): Unit
28-
29-
}
28+
}

modules/ank/arrow-ank/src/main/kotlin/arrow/ank/ank.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fun <F> Fx<F>.ank(source: Path, target: Path, compilerArgs: List<String>, ankOps
4040
}.toList().sequence()
4141
}
4242

43-
4443
val message = "Ank Processed ${paths.size} files"
4544
!effect { printConsole(colored(ANSI_GREEN, message)) }
4645
}
47-
}
46+
}

modules/ank/arrow-ank/src/main/kotlin/arrow/ank/formatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const val ANSI_CYAN = "\u001B[36m"
3232
const val ANSI_WHITE = "\u001B[37m"
3333

3434
fun colored(color: String, message: String) =
35-
"$color$message${ANSI_RESET}"
35+
"$color$message$ANSI_RESET"
3636

3737
val AnkHeader =
3838
"""

modules/ank/arrow-ank/src/main/kotlin/arrow/ank/interpreter.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package arrow.ank
22

3-
import arrow.core.*
3+
import arrow.core.None
4+
import arrow.core.Option
5+
import arrow.core.Some
6+
import arrow.core.Try
7+
import arrow.core.Tuple2
8+
import arrow.core.Tuple3
9+
import arrow.core.some
10+
import arrow.core.toT
411
import arrow.data.extensions.sequence.foldable.foldLeft
512
import java.io.PrintWriter
613
import java.io.StringWriter
@@ -36,7 +43,8 @@ data class CompilationException(
3643
val path: Path,
3744
val snippet: Snippet,
3845
val underlying: Throwable,
39-
val msg: String) : NoStackTrace(msg) {
46+
val msg: String
47+
) : NoStackTrace(msg) {
4048
override fun toString(): String = msg
4149
}
4250

@@ -123,7 +131,7 @@ val interpreter: AnkOps = object : AnkOps {
123131
when (state) {
124132
is SnippetParserState.Searching -> {
125133
val startMatch = fenceRegexStart.matchEntire(line)
126-
if (startMatch != null) { //found a fence start
134+
if (startMatch != null) { // found a fence start
127135
val lang = startMatch.groupValues[1].trim()
128136
val snippet = Snippet(line, lang, "")
129137
Tuple3(SnippetParserState.CollectingCode(snippet), lines + line, snippets)
@@ -133,7 +141,7 @@ val interpreter: AnkOps = object : AnkOps {
133141
val endMatch = fenceRegexEnd.matchEntire(line)
134142
if (endMatch != null) { // found a fence end
135143
Tuple3(SnippetParserState.Searching, lines + line, snippets + state.snippet.copy(fence = state.snippet.fence + "\n" + line))
136-
} else { //accumulating code inside a fence
144+
} else { // accumulating code inside a fence
137145
val modifiedSnippet = state.snippet.copy(
138146
fence = state.snippet.fence + "\n" + line,
139147
code = state.snippet.code + "\n" + line
@@ -233,25 +241,25 @@ val interpreter: AnkOps = object : AnkOps {
233241

234242
private fun getEngineCache(snippets: Sequence<Snippet>, compilerArgs: List<String>): Map<String, ScriptEngine> {
235243
val cache = engineCache[compilerArgs]
236-
return if (cache == null) { //create a new engine
244+
return if (cache == null) { // create a new engine
237245
val classLoader = URLClassLoader(compilerArgs.map { URL(it) }.toTypedArray())
238246
val seManager = ScriptEngineManager(classLoader)
239247
val langs = snippets.map { it.lang }.distinct()
240248
val engines = langs.toList().map {
241249
it to seManager.getEngineByExtension(extensionMappings.getOrDefault(it, "kts"))
242250
}.toMap()
243251
engineCache.putIfAbsent(compilerArgs, engines) ?: engines
244-
} else { //reset an engine. Non thread-safe
252+
} else { // reset an engine. Non thread-safe
245253
cache.forEach { _, engine ->
246254
engine.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE)
247255
}
248256
cache
249257
}
250258
}
251259

252-
//TODO Try by overriding dokka settings for packages so it does not create it's markdown package file, then for regular type classes pages we only check the first result with the comment but remove them all regardless
260+
// TODO Try by overriding dokka settings for packages so it does not create it's markdown package file, then for regular type classes pages we only check the first result with the comment but remove them all regardless
253261
private fun generateMixedHierarchyDiagramCode(classes: List<String>): Sequence<String> {
254-
//careful meta-meta-programming ahead
262+
// careful meta-meta-programming ahead
255263
val hierarchyGraphsJoined =
256264
"listOf(" + classes
257265
.map { "TypeClass($it::class)" }
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package arrow.aql
22

3-
import arrow.core.*
3+
import arrow.core.extensions.monoid
4+
import arrow.core.firstOrNone
5+
import arrow.core.getOrElse
6+
import arrow.core.identity
47
import arrow.data.ForListK
58
import arrow.data.fix
69
import arrow.data.k
7-
import arrow.core.extensions.monoid
810
import arrow.typeclasses.Foldable
911

1012
interface Count<F> {
@@ -13,13 +15,12 @@ interface Count<F> {
1315

1416
fun <A, Z> Query<F, A, Z>.count(): Query<ForListK, Long, Long> =
1517
foldable().run {
16-
Query(
17-
select = ::identity,
18-
from = listOf(from.size(Long.monoid())).k()
19-
)
18+
Query(
19+
select = ::identity,
20+
from = listOf(from.size(Long.monoid())).k()
21+
)
2022
}
2123

2224
fun Query<ForListK, Long, Long>.value(): Long =
2325
this@value.from.fix().firstOrNone().getOrElse { 0L }
24-
25-
}
26+
}

0 commit comments

Comments
 (0)