Repository: jeremymailen/kotlinter-gradle
Pull request #352 (2023-11-13 01:54:55)

Update to ktlint 1.0.1
Also adopt ktlint 1.0 to lint the project.


Patch:
diff --git a/.editorconfig b/.editorconfig
index 43deb25..2257e52 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,6 +1,7 @@
 root = true
 
 [*.{kt,kts}]
+ktlint_code_style = intellij_idea
 max_line_length = 140
 indent_size = 4
 insert_final_newline = true
diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml
index 628554d..bd47a5c 100644
--- a/.github/workflows/default.yml
+++ b/.github/workflows/default.yml
@@ -15,7 +15,7 @@ jobs:
         os: [ ubuntu-latest, windows-latest ]
     name: '[${{ matrix.os }}] build plugin'
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Set up Java
         uses: actions/setup-java@v3
@@ -54,7 +54,7 @@ jobs:
 
     name: '[${{ matrix.os }}] Gradle: ${{ matrix.gradle }}, Java: ${{ matrix.java }}'
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         with:
           fetch-depth: 0
 
@@ -74,7 +74,7 @@ jobs:
         run: |
           cd test-project/build/reports/ktlint
           grep 'no-empty-class-body' main-format.txt | grep -q 'EmptyClassBodyClass.kt:3:27'
-          grep 'op-spacing' test-format.txt | grep -q 'OpSpacing.kt:5:15'
+          grep 'op-spacing' test-format.txt | grep -q 'OpSpacing.kt:5:16'
 
       - name: Upload reports
         if: ${{ failure() }}
@@ -112,7 +112,7 @@ jobs:
 
     name: '[android] Gradle: ${{ matrix.gradle }}, Java: ${{ matrix.java }}, AGP: ${{ matrix.agp }}'
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         with:
           fetch-depth: 0
 
@@ -133,7 +133,7 @@ jobs:
           cd test-project-android/build/reports/ktlint
           grep 'no-empty-class-body' main-format.txt | grep -q 'EmptyClassBodyClass.kt:3:27'
           grep 'no-empty-class-body' main-format.txt | grep -q 'EmptyClassBodyInJavaSourcesClass.kt:3:40'
-          grep 'op-spacing' test-format.txt | grep -q 'OpSpacing.kt:5:15'
+          grep 'op-spacing' test-format.txt | grep -q 'OpSpacing.kt:5:16'
 
       - name: Upload reports
         if: ${{ failure() }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index e02c6fa..2ad981a 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -10,7 +10,7 @@ jobs:
     name: Publish plugin
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Set up Java
         uses: actions/setup-java@v3
diff --git a/README.md b/README.md
index 7c9a02b..3c05916 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Available on the Gradle Plugins Portal: https://plugins.gradle.org/plugin/org.jm
 
 ```kotlin
 plugins {
-    id("org.jmailen.kotlinter") version "4.0.0"
+    id("org.jmailen.kotlinter") version "4.0.1"
 }
 ```
 
@@ -31,7 +31,7 @@ plugins {
 
 ```groovy
 plugins {
-    id "org.jmailen.kotlinter" version "4.0.0"
+    id "org.jmailen.kotlinter" version "4.0.1"
 }
 ```
 
@@ -45,7 +45,7 @@ Root `build.gradle.kts`
 
 ```kotlin
 plugins {
-    id("org.jmailen.kotlinter") version "4.0.0" apply false
+    id("org.jmailen.kotlinter") version "4.0.1" apply false
 }
 ```
 
@@ -65,7 +65,7 @@ Root `build.gradle`
 
 ```groovy
 plugins {
-    id 'org.jmailen.kotlinter' version "4.0.0" apply false
+    id 'org.jmailen.kotlinter' version "4.0.1" apply false
 }
 ```
 
diff --git a/build.gradle.kts b/build.gradle.kts
index 3e67736..48401b6 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -2,11 +2,11 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
 plugins {
-    kotlin("jvm") version "1.9.10"
+    kotlin("jvm") version "1.9.20"
     id("com.gradle.plugin-publish") version "1.1.0"
     `java-gradle-plugin`
     `maven-publish`
-    id("org.jmailen.kotlinter") version "3.16.0"
+    id("org.jmailen.kotlinter") version "4.0.0"
     idea
 }
 
@@ -20,14 +20,14 @@ val githubUrl = "https://github.com/jeremymailen/kotlinter-gradle"
 val webUrl = "https://github.com/jeremymailen/kotlinter-gradle"
 val projectDescription = "Lint and formatting for Kotlin using ktlint with configuration-free setup on JVM and Android projects"
 
-version = "4.0.0"
+version = "4.0.1"
 group = "org.jmailen.gradle"
 description = projectDescription
 
 object Versions {
     const val androidTools = "7.3.1"
     const val junit = "5.9.3"
-    const val ktlint = "1.0.0"
+    const val ktlint = "1.0.1"
     const val mockitoKotlin = "4.1.0"
 }
 
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt
index f090051..9fc3f12 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt
@@ -69,19 +69,17 @@ class KotlinterPlugin : Plugin<Project> {
         }
     }
 
-    private fun Project.registerParentLintTask(): TaskProvider<Task> =
-        tasks.register("lintKotlin") {
-            it.group = "formatting"
-            it.description = "Runs lint on the Kotlin source files."
-        }.also { lintKotlin ->
-            tasks.named("check").configure { check -> check.dependsOn(lintKotlin) }
-        }
+    private fun Project.registerParentLintTask(): TaskProvider<Task> = tasks.register("lintKotlin") {
+        it.group = "formatting"
+        it.description = "Runs lint on the Kotlin source files."
+    }.also { lintKotlin ->
+        tasks.named("check").configure { check -> check.dependsOn(lintKotlin) }
+    }
 
-    private fun Project.registerParentFormatTask(): TaskProvider<Task> =
-        tasks.register("formatKotlin") {
-            it.group = "formatting"
-            it.description = "Formats the Kotlin source files."
-        }
+    private fun Project.registerParentFormatTask(): TaskProvider<Task> = tasks.register("formatKotlin") {
+        it.group = "formatting"
+        it.description = "Formats the Kotlin source files."
+    }
 
     private fun Project.registerPrePushHookTask(): TaskProvider<InstallPrePushHookTask> =
         tasks.register("installKotlinterPrePushHook", InstallPrePushHookTask::class.java) {
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/pluginapplier/KotlinSourceSetApplier.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/pluginapplier/KotlinSourceSetApplier.kt
index 99b0089..56cdedd 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/pluginapplier/KotlinSourceSetApplier.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/pluginapplier/KotlinSourceSetApplier.kt
@@ -15,6 +15,5 @@ internal object KotlinSourceSetApplier : SourceSetApplier {
         }
     }
 
-    private fun getSourceSets(project: Project) =
-        project.extensions.getByType(KotlinProjectExtension::class.java).sourceSets
+    private fun getSourceSets(project: Project) = project.extensions.getByType(KotlinProjectExtension::class.java).sourceSets
 }
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt
index 7c869d4..72c718e 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt
@@ -9,10 +9,7 @@ internal val ktlintEngine = KtLintRuleEngine(
     ruleProviders = resolveRuleProviders(defaultRuleSetProviders),
 )
 
-internal fun resetEditorconfigCacheIfNeeded(
-    changedEditorconfigFiles: ConfigurableFileCollection,
-    logger: Logger,
-) {
+internal fun resetEditorconfigCacheIfNeeded(changedEditorconfigFiles: ConfigurableFileCollection, logger: Logger) {
     val changedFiles = changedEditorconfigFiles.files
     if (changedFiles.any()) {
         logger.info("Editorconfig changed, resetting KtLint caches")
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/RuleSets.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/RuleSets.kt
index 66877c3..41b0891 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/RuleSets.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/RuleSets.kt
@@ -4,9 +4,7 @@ import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
 import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
 import java.util.ServiceLoader
 
-internal fun resolveRuleProviders(
-    providers: Iterable<RuleSetProviderV3>,
-): Set<RuleProvider> = providers
+internal fun resolveRuleProviders(providers: Iterable<RuleSetProviderV3>): Set<RuleProvider> = providers
     .asSequence()
     .sortedWith(
         compareBy {
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/SortedThreadSafeReporterWrapper.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/SortedThreadSafeReporterWrapper.kt
index c6dbe50..9c8dca7 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/SortedThreadSafeReporterWrapper.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/SortedThreadSafeReporterWrapper.kt
@@ -29,7 +29,7 @@ class SortedThreadSafeReporterWrapper(
     override fun onLintError(file: String, ktlintCliError: KtlintCliError) {
         lintErrorReports.putIfAbsent(
             file,
-            ConcurrentSkipListSet() { o1, o2 ->
+            ConcurrentSkipListSet { o1, o2 ->
                 when (o1.line == o2.line) {
                     true -> o1.col.compareTo(o2.col)
                     false -> o1.line.compareTo(o2.line)
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
index b8ad353..2322baf 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt
@@ -28,18 +28,16 @@ abstract class ConfigurableKtLintTask(
         from(projectLayout.findApplicableEditorConfigFiles().toList())
     }
 
-    protected fun getChangedEditorconfigFiles(inputChanges: InputChanges) =
-        if (inputChanges.isIncremental) {
-            inputChanges.getFileChanges(editorconfigFiles).map(FileChange::getFile)
-        } else {
-            emptyList()
-        }
+    protected fun getChangedEditorconfigFiles(inputChanges: InputChanges) = if (inputChanges.isIncremental) {
+        inputChanges.getFileChanges(editorconfigFiles).map(FileChange::getFile)
+    } else {
+        emptyList()
+    }
 }
 
-internal inline fun <reified T> ObjectFactory.property(default: T? = null): Property<T> =
-    property(T::class.java).apply {
-        set(default)
-    }
+internal inline fun <reified T> ObjectFactory.property(default: T? = null): Property<T> = property(T::class.java).apply {
+    set(default)
+}
 
 internal inline fun <reified T> ObjectFactory.listProperty(default: Iterable<T> = emptyList()): ListProperty<T> =
     listProperty(T::class.java).apply {
diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt
index d729321..f17a071 100644
--- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt
+++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt
@@ -58,13 +58,13 @@ abstract class InstallHookTask(@get:Internal val hookFileName: String) : Default
             logger.info("creating hook file: $hookFile")
             hookFile.writeText(generateHook(gradleCommand, hookContent, addShebang = true))
         } else {
-            val startIndex = hookFileContent.indexOf(startHook)
+            val startIndex = hookFileContent.indexOf(START_HOOK)
             if (startIndex == -1) {
                 logger.info("adding hook to file: $hookFile")
                 hookFile.appendText(generateHook(gradleCommand, hookContent))
             } else {
                 logger.info("replacing hook in file: $hookFile")
-                val endIndex = hookFileContent.indexOf(endHook)
+                val endIndex = hookFileContent.indexOf(END_HOOK)
                 val newHookFileContent = hookFileContent.replaceRange(
                     startIndex,
                     endIndex,
@@ -113,11 +113,11 @@ abstract class InstallHookTask(@get:Internal val hookFileName: String) : Default
     companion object {
         private val version = VersionProperties().version()
 
-        internal const val startHook = "\n##### KOTLINTER HOOK START #####"
+        internal const val START_HOOK = "\n##### KOTLINTER HOOK START #####"
 
         internal val hookVersion = "##### KOTLINTER $version #####"
 
-        internal const val endHook = "##### KOTLINTER HOOK END #####\n"
+        internal const val END_HOOK = "##### KOTLINTER HOOK END #####\n"
 
         internal val shebang =
             """
@@ -135,11 +135,11 @@ abstract class InstallHookTask(@get:Internal val hookFileName: String) : Default
             includeEndHook: Boolean = true,
         ): String = (if (addShebang) shebang else "") +
             """
-                |$startHook
+                |$START_HOOK
                 |$hookVersion
                 |GRADLEW=$gradlew
                 |$hookContent
-                |${if (includeEndHook) endHook else ""}
+                |${if (includeEndHook) END_HOOK else ""}
             """.trimMargin()
     }
 }


Test patch:
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
index 5c6c3a3..8b93fa3 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/EditorConfigTest.kt
@@ -39,7 +39,8 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
     fun `lintTask uses default indentation if editorconfig absent`() {
         projectRoot.resolve("src/main/kotlin/FourSpacesByDefault.kt") {
             writeText(
-                """ |
+                """ |package com.example
+                    |
                     |object FourSpacesByDefault {
                     |    val text: String
                     |}
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/InstallHookTaskTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/InstallHookTaskTest.kt
index 85c8ae6..fd32e06 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/InstallHookTaskTest.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/InstallHookTaskTest.kt
@@ -83,9 +83,9 @@ abstract class InstallHookTaskTest(
         File(testProjectDir, ".git/hooks/$hookFile").apply {
             writeText(
                 """
-                ${InstallHookTask.startHook}
+                ${InstallHookTask.START_HOOK}
                 $placeholder
-                ${InstallHookTask.endHook}
+                ${InstallHookTask.END_HOOK}
                 """.trimIndent(),
             )
         }
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/WithGradleTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/WithGradleTest.kt
index a9c0370..39415ea 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/WithGradleTest.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/WithGradleTest.kt
@@ -58,8 +58,7 @@ abstract class WithGradleTest {
     }
 }
 
-private fun WithGradleTest.defaultRunner(vararg args: String) =
-    GradleRunner.create()
-        .withProjectDir(testProjectDir)
-        .withArguments(args.toList() + listOf("--stacktrace", "--configuration-cache"))
-        .forwardOutput()
+private fun WithGradleTest.defaultRunner(vararg args: String) = GradleRunner.create()
+    .withProjectDir(testProjectDir)
+    .withArguments(args.toList() + listOf("--stacktrace", "--configuration-cache"))
+    .forwardOutput()
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Factories.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Factories.kt
index 3d49629..b940a93 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Factories.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Factories.kt
@@ -1,11 +1,10 @@
 package org.jmailen.gradle.kotlinter.functional.utils
 
 // language=kotlin
-internal fun kotlinClass(className: String) =
-    """
+internal fun kotlinClass(className: String) = """
     object $className
     
-    """.trimIndent()
+""".trimIndent()
 
 // language=groovy
 internal val settingsFile =
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Utilities.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Utilities.kt
index e3c4edc..c3d7297 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Utilities.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/utils/Utilities.kt
@@ -2,8 +2,7 @@ package org.jmailen.gradle.kotlinter.functional.utils
 
 import java.io.File
 
-internal fun File.resolve(path: String, receiver: File.() -> Unit): File =
-    resolve(path).apply {
-        parentFile.mkdirs()
-        receiver()
-    }
+internal fun File.resolve(path: String, receiver: File.() -> Unit): File = resolve(path).apply {
+    parentFile.mkdirs()
+    receiver()
+}
diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/tasks/GenerateHookTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/tasks/GenerateHookTest.kt
index 43f9bff..b2c153c 100644
--- a/src/test/kotlin/org/jmailen/gradle/kotlinter/tasks/GenerateHookTest.kt
+++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/tasks/GenerateHookTest.kt
@@ -17,16 +17,16 @@ internal class GenerateHookTest {
     fun testGenerateHook_HasAllContent() {
         val hook = InstallHookTask.generateHook(gradlew, hookContent, true)
         assertTrue(hook.contains(InstallHookTask.shebang))
-        assertTrue(hook.contains(InstallHookTask.startHook))
+        assertTrue(hook.contains(InstallHookTask.START_HOOK))
         assertTrue(hook.contains("GRADLEW=$gradlew"))
         assertTrue(hook.contains(hookContent))
-        assertTrue(hook.contains(InstallHookTask.endHook))
+        assertTrue(hook.contains(InstallHookTask.END_HOOK))
     }
 
     @Test
     fun testGenerateHook_IncludesStartHook() {
         val hook = InstallHookTask.generateHook(gradlew, hookContent)
-        assertTrue(hook.contains(InstallHookTask.startHook))
+        assertTrue(hook.contains(InstallHookTask.START_HOOK))
     }
 
     @Test
@@ -38,13 +38,13 @@ internal class GenerateHookTest {
     @Test
     fun testGenerateHook_IncludesEndHook() {
         val hook = InstallHookTask.generateHook(gradlew, hookContent)
-        assertTrue(hook.contains(InstallHookTask.endHook))
+        assertTrue(hook.contains(InstallHookTask.END_HOOK))
     }
 
     @Test
     fun testGenerateHook_DoesNotIncludeEndHook() {
         val hook = InstallHookTask.generateHook(gradlew, hookContent, includeEndHook = false)
-        assertFalse(hook.contains(InstallHookTask.endHook))
+        assertFalse(hook.contains(InstallHookTask.END_HOOK))
     }
 
     @Test