Skip to content

Commit 75aa799

Browse files
authored
Merge pull request #754 from Kotlin/ktlint-migration
Replacing the linter
2 parents 0896fa5 + 66beb7d commit 75aa799

File tree

804 files changed

+16846
-14105
lines changed

Some content is hidden

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

804 files changed

+16846
-14105
lines changed

.editorconfig

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
[*]
2-
charset=utf-8
3-
end_of_line=lf
4-
insert_final_newline=true
5-
indent_style=space
6-
indent_size=4
7-
max_line_length=120
2+
charset = utf-8
3+
end_of_line = lf
4+
insert_final_newline = true
5+
indent_style = space
6+
indent_size = 4
7+
max_line_length = 120
88

99
[*.json]
10-
indent_size=2
10+
indent_size = 2
1111

1212
[{*.yaml,*.yml}]
13-
indent_size=2
13+
indent_size = 2
1414

1515
[*.ipynb]
16-
insert_final_newline=false
16+
insert_final_newline = false
17+
18+
[*.{kt,kts}]
19+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
20+
21+
# Disable wildcard imports entirely
22+
ij_kotlin_name_count_to_use_star_import = 2147483647
23+
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
24+
ij_kotlin_packages_to_use_import_on_demand = unset
25+
26+
ktlint_code_style = ktlint_official
27+
ktlint_experimental = enabled
28+
ktlint_standard_filename = disabled
29+
ktlint_standard_no-empty-first-line-in-class-body = disabled
30+
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 4
31+
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 4
32+
ktlint_standard_chain-method-continuation = disabled
33+
ktlint_ignore_back_ticked_identifier = true
34+
ktlint_standard_multiline-expression-wrapping = disabled
35+
36+
[{*/build/**/*,**/*keywords*/**,**/*.Generated.kt,**/*$Extensions.kt}]
37+
ktlint = disabled

CONTRIBUTING.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ so do familiarize yourself with the following guidelines.
3333
* PR should be linked with the issue,
3434
excluding minor documentation changes, adding unit tests, and fixing typos.
3535
* If you make any code changes:
36-
* Follow the [Kotlin Coding Conventions](https://kotlinlang.org/docs/reference/coding-conventions.html).
36+
* Follow the [Kotlin Coding Conventions](https://kotlinlang.org/docs/reference/coding-conventions.html).
37+
[Ktlint](https://pinterest.github.io/ktlint/latest/) can help here.
3738
* [Build the project](#building) to ensure it all works and passes the tests.
3839
* If you fix a bug:
3940
* Write the test that reproduces the bug.
@@ -54,15 +55,18 @@ so do familiarize yourself with the following guidelines.
5455
0. The contributor builds the library locally and runs all unit tests via the Gradle task `dataframe:test`
5556
(see the ["Building"](#building) chapter).
5657
1. The contributor submits the PR if the local build is successful and the tests are green.
57-
2. The reviewer put his name in the "Reviewers" section of the proposed PR at the start of the review process.
58-
3. The reviewer leaves the comments or marks the PR with the abbreviation "LGTM" (Looks good to me).
58+
2. The reviewer puts their name in the "Reviewers" section of the proposed PR at the start of the review process.
59+
3. The reviewer leaves comments or marks the PR with the abbreviation "LGTM" (Looks good to me).
5960
4. The contributor answers the comments or fixes the proposed PR.
6061
5. The reviewer marks the PR with the word "LGTM."
61-
6. The maintainer could suggest merging the master branch to the PR branch a few times due to changes in the `master` branch.
62-
7. The maintainer runs TC builds (unit tests and examples as integration tests).
63-
8. TC writes the result (passed or not passed) to the PR checks at the bottom of the proposed PR.
64-
9. If it is possible, maintainers share the details of the failed build with the contributor.
65-
10. Maintainer merges the PR if all checks are successful and there is no conflict with the master branch.
62+
6. The maintainer could suggest merging the `master` branch to the PR branch a few times due to changes in the `master` branch.
63+
7. If the PR influences generated code/samples, a bot will inform about this in the PR comments.
64+
8. The maintainer runs TeamCity builds (unit tests and examples as integration tests).
65+
9. TeamCity writes the result (passed or not passed) to the PR checks at the bottom of the proposed PR.
66+
10. If it is possible, maintainers share the details of the failed build with the contributor.
67+
11. The maintainer merges the PR if all checks are successful and there is no conflict with the `master` branch.
68+
12. The maintainer closes the PR and the issue linked to it.
69+
13. If the PR influences generated code, a bot will auto-commit the newly generated code into the `master` branch.
6670

6771
## How to fix an existing issue
6872

@@ -81,13 +85,22 @@ so do familiarize yourself with the following guidelines.
8185

8286
## Environment requirements
8387

84-
JDK >= 11 referred to by the `JAVA_HOME` environment variable.
88+
* JDK >= 11 referred to by the `JAVA_HOME` environment variable.
89+
90+
* Note, any version above 11 should work in theory, but JDK 11 is the only version we test with,
91+
so it is the recommended version.
92+
93+
* We recommend using [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) as the IDE. This
94+
has the best support for Kotlin, compiler plugins, Gradle, and [Kotlin Notebook](https://kotlinlang.org/docs/kotlin-notebook-overview.html) of course.
95+
96+
* We recommend using the [Ktlint plugin](https://plugins.jetbrains.com/plugin/15057-ktlint) for [IntelliJ IDEA](https://www.jetbrains.com/idea/download/).
97+
It is able to read the `.editorconfig` file and apply the same formatting rules as [Ktlint](https://pinterest.github.io/ktlint/latest/) in the CI.
8598

8699
## Building
87100

88101
This library is built with Gradle.
89102

90-
* Run `./gradlew build` to build. It also runs all the tests.
103+
* Run `./gradlew build` to build. It also runs all the tests and checks the linter.
91104
* Run `./gradlew <module>:test` to test the module you are looking at to speed
92105
things up during development.
93106

build.gradle.kts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.dataframe.io.readJson
1010
import org.jetbrains.kotlinx.publisher.apache2
1111
import org.jetbrains.kotlinx.publisher.developer
1212
import org.jetbrains.kotlinx.publisher.githubRepo
13+
import org.jlleitschuh.gradle.ktlint.KtlintExtension
1314

1415
plugins {
1516
with(libs.plugins) {
@@ -19,7 +20,7 @@ plugins {
1920
alias(jupyter.api) apply false
2021
alias(dokka)
2122
alias(kover)
22-
alias(kotlinter)
23+
alias(ktlint)
2324
alias(korro) apply false
2425
alias(docProcessor) apply false
2526
alias(simpleGit) apply false
@@ -54,7 +55,12 @@ dependencies {
5455
}
5556

5657
enum class Version : Comparable<Version> {
57-
SNAPSHOT, DEV, ALPHA, BETA, RC, STABLE;
58+
SNAPSHOT,
59+
DEV,
60+
ALPHA,
61+
BETA,
62+
RC,
63+
STABLE,
5864
}
5965

6066
fun String.findVersion(): Version {
@@ -73,13 +79,11 @@ fun String.findVersion(): Version {
7379
val dependencyUpdateExclusions = listOf(
7480
// TODO Requires more work to be updated to 1.7.0+, https://github.com/Kotlin/dataframe/issues/594
7581
libs.plugins.kover.get().pluginId,
76-
// TODO Updating requires major changes all across the project, https://github.com/Kotlin/dataframe/issues/364
77-
libs.plugins.kotlinter.get().pluginId,
7882
// TODO 5.8.0 is not possible due to https://github.com/Kotlin/dataframe/issues/595
7983
libs.kotestAssertions.get().name,
8084
// Can't be updated to 7.4.0+ due to Java 8 compatibility
8185
libs.android.gradle.api.get().group,
82-
// TODO 0.1.6 breaks ktlint, https://github.com/Kotlin/dataframe/issues/598
86+
// TODO 0.1.6 broke kotlinter, https://github.com/Kotlin/dataframe/issues/598
8387
libs.plugins.korro.get().pluginId,
8488
// Directly dependent on the Gradle version
8589
"org.gradle.kotlin.kotlin-dsl",
@@ -137,29 +141,15 @@ allprojects {
137141
targetCompatibility = JavaVersion.VERSION_1_8.toString()
138142
}
139143

140-
// Attempts to configure kotlinter for each sub-project that uses the plugin
144+
// Attempts to configure ktlint for each sub-project that uses the plugin
141145
afterEvaluate {
142146
try {
143-
kotlinter {
144-
ignoreFailures = false
145-
reporters = arrayOf("checkstyle", "plain")
146-
experimentalRules = true
147-
disabledRules = arrayOf(
148-
"no-wildcard-imports",
149-
"experimental:spacing-between-declarations-with-annotations",
150-
"experimental:enum-entry-name-case",
151-
"experimental:argument-list-wrapping",
152-
"experimental:annotation",
153-
"max-line-length",
154-
"filename",
155-
"comment-spacing",
156-
"curly-spacing",
157-
"experimental:annotation-spacing",
158-
"no-unused-imports", // broken
159-
)
147+
configure<KtlintExtension> {
148+
version = "1.3.0"
149+
// rules are set up through .editorconfig
160150
}
161151
} catch (_: UnknownDomainObjectException) {
162-
logger.warn("Could not set kotlinter config on :${this.name}")
152+
logger.warn("Could not set ktlint config on :${this.name}")
163153
}
164154

165155
// set the java toolchain version to 11 for all subprojects for CI stability
@@ -223,13 +213,13 @@ kotlinPublications {
223213
sonatypeSettings(
224214
project.findProperty("kds.sonatype.user") as String?,
225215
project.findProperty("kds.sonatype.password") as String?,
226-
"dataframe project, v. ${project.version}"
216+
"dataframe project, v. ${project.version}",
227217
)
228218

229219
signingCredentials(
230220
project.findProperty("kds.sign.key.id") as String?,
231221
project.findProperty("kds.sign.key.private") as String?,
232-
project.findProperty("kds.sign.key.passphrase") as String?
222+
project.findProperty("kds.sign.key.passphrase") as String?,
233223
)
234224

235225
pom {

core/build.gradle.kts

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import nl.jolanrensen.docProcessor.defaultProcessors.ARG_DOC_PROCESSOR_LOG_NOT_F
55
import nl.jolanrensen.docProcessor.gradle.creatingProcessDocTask
66
import org.gradle.jvm.tasks.Jar
77
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
8-
import org.jmailen.gradle.kotlinter.tasks.LintTask
98
import xyz.ronella.gradle.plugin.simple.git.task.GitTask
109

1110
plugins {
@@ -17,7 +16,7 @@ plugins {
1716
alias(korro)
1817
alias(keywordGenerator)
1918
alias(kover)
20-
alias(kotlinter)
19+
alias(ktlint)
2120
alias(docProcessor)
2221
alias(simpleGit)
2322

@@ -103,10 +102,6 @@ tasks.withType<KspTask> {
103102
}
104103
}
105104

106-
tasks.named("lintKotlinSamples") {
107-
onlyIf { false }
108-
}
109-
110105
val clearTestResults by tasks.creating(Delete::class) {
111106
delete(layout.buildDirectory.dir("dataframes"))
112107
delete(layout.buildDirectory.dir("korroOutputLines"))
@@ -190,58 +185,64 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
190185
val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
191186
.filterNot { pathOf("build", "generated") in it.path }
192187

188+
// sourceset of the generated sources as a result of `processKDocsMain`, this will create linter tasks
189+
val generatedSources by kotlin.sourceSets.creating {
190+
kotlin {
191+
setSrcDirs(
192+
listOf(
193+
"build/generated/ksp/main/kotlin/",
194+
"core/build/generatedSrc",
195+
"$generatedSourcesFolderName/src/main/kotlin",
196+
"$generatedSourcesFolderName/src/main/java",
197+
),
198+
)
199+
}
200+
}
201+
193202
// Task to generate the processed documentation
194203
val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
195204
target = file(generatedSourcesFolderName)
196205
arguments += ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
206+
207+
// false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
208+
outputReadOnly = false
209+
197210
exportAsHtml {
198211
dir = file("../docs/StardustDocs/snippets/kdocs")
199212
}
200213
task {
201214
group = "KDocs"
202-
// making sure it always runs, so targets is set
203-
outputs.upToDateWhen { false }
215+
finalizedBy("runKtlintFormatOverGeneratedSourcesSourceSet")
204216
}
205217
}
206218

219+
tasks.named("ktlintGeneratedSourcesSourceSetCheck") {
220+
onlyIf { false }
221+
}
222+
tasks.named("runKtlintCheckOverGeneratedSourcesSourceSet") {
223+
onlyIf { false }
224+
}
225+
207226
// Exclude the generated/processed sources from the IDE
208227
idea {
209228
module {
210229
excludeDirs.add(file(generatedSourcesFolderName))
211230
}
212231
}
213232

214-
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
215-
tasks.withType<Jar> {
216-
mustRunAfter(tasks.generateKeywordsSrc, processKDocsMain)
217-
}
218-
219233
// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
220234
// the target of `processKdocMain`, and they are returned to normal afterward.
221235
// This is usually only done when publishing
222236
val changeJarTask by tasks.creating {
223237
outputs.upToDateWhen { false }
224238
doFirst {
225239
tasks.withType<Jar> {
226-
dependsOn(processKDocsMain)
227240
doFirst {
228-
val targets = processKDocsMain.targets
229-
require(targets.toList().isNotEmpty()) {
230-
logger.error("`processKDocsMain.targets` was empty, did it run before this task?")
241+
require(generatedSources.kotlin.srcDirs.toList().isNotEmpty()) {
242+
logger.error("`processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?")
231243
}
232-
val srcDirs = targets
233-
.filterNot {
234-
pathOf("src", "test", "kotlin") in it.path ||
235-
pathOf("src", "test", "java") in it.path
236-
} // filter out test sources again
237-
.plus(
238-
kotlinMainSources.filter {
239-
pathOf("build", "generated") in it.path
240-
},
241-
) // Include generated sources (which were excluded above)
242-
243244
kotlin.sourceSets.main {
244-
kotlin.setSrcDirs(srcDirs)
245+
kotlin.setSrcDirs(generatedSources.kotlin.srcDirs)
245246
}
246247
logger.lifecycle("$this is run with modified sources: \"$generatedSourcesFolderName\"")
247248
}
@@ -255,6 +256,11 @@ val changeJarTask by tasks.creating {
255256
}
256257
}
257258

259+
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
260+
tasks.withType<Jar> {
261+
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
262+
}
263+
258264
// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
259265
tasks.named { it.startsWith("publish") }.configureEach {
260266
dependsOn(processKDocsMain, changeJarTask)
@@ -316,35 +322,34 @@ tasks.withType<KspTaskJvm> {
316322
dependsOn(tasks.generateKeywordsSrc)
317323
}
318324

319-
tasks.formatKotlinMain {
325+
tasks.runKtlintFormatOverMainSourceSet {
320326
dependsOn(tasks.generateKeywordsSrc)
321327
dependsOn("kspKotlin")
322328
}
323329

324-
tasks.formatKotlinTest {
330+
tasks.runKtlintFormatOverTestSourceSet {
325331
dependsOn(tasks.generateKeywordsSrc)
326332
dependsOn("kspTestKotlin")
327333
}
328334

329-
tasks.lintKotlinMain {
335+
tasks.named("runKtlintFormatOverGeneratedSourcesSourceSet") {
330336
dependsOn(tasks.generateKeywordsSrc)
331337
dependsOn("kspKotlin")
332338
}
333339

334-
tasks.lintKotlinTest {
340+
tasks.runKtlintCheckOverMainSourceSet {
341+
dependsOn(tasks.generateKeywordsSrc)
342+
dependsOn("kspKotlin")
343+
}
344+
345+
tasks.runKtlintCheckOverTestSourceSet {
335346
dependsOn(tasks.generateKeywordsSrc)
336347
dependsOn("kspTestKotlin")
337348
}
338349

339-
tasks.withType<LintTask> {
340-
exclude("**/*keywords*/**")
341-
exclude {
342-
it.name.endsWith(".Generated.kt")
343-
}
344-
exclude {
345-
it.name.endsWith("\$Extensions.kt")
346-
}
347-
enabled = true
350+
tasks.named("runKtlintCheckOverGeneratedSourcesSourceSet") {
351+
dependsOn(tasks.generateKeywordsSrc)
352+
dependsOn("kspKotlin")
348353
}
349354

350355
kotlin {
@@ -369,7 +374,7 @@ tasks.test {
369374
listOf(
370375
"org.jetbrains.kotlinx.dataframe.jupyter.*",
371376
"org.jetbrains.kotlinx.dataframe.jupyter.SampleNotebooksTests",
372-
)
377+
),
373378
)
374379
}
375380
}

0 commit comments

Comments
 (0)