From 4866bebca724f56f44f77c0b80a3c1994e73fb54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Kwieci=C5=84ski?=
<36954793+mateuszkwiecinski@users.noreply.github.com>
Date: Fri, 28 Jul 2023 16:54:32 +0200
Subject: [PATCH] Replace kotlin public `data class`es with Poko compiler
plugin generated ones (#2136)
* Add poko library
* Repalce public data class with generated classes by Poko compiler
* Re-record new API surface
* Add simple bash script to verify if public API contains data classes
---
.github/workflows/pull-request-with-code.yml | 21 +++
CHANGELOG.md | 1 +
build-logic/build.gradle.kts | 1 +
.../kotlin/ktlint-kotlin-common.gradle.kts | 1 +
gradle/libs.versions.toml | 2 +
.../cli/reporter/baseline/BaselineReporter.kt | 6 +-
.../reporter/checkstyle/CheckStyleReporter.kt | 12 +-
.../api/ktlint-cli-reporter-core.api | 7 -
.../cli/reporter/core/api/KtlintCliError.kt | 14 +-
.../ktlint/cli/reporter/html/HtmlReporter.kt | 6 +-
.../ktlint/cli/reporter/json/JsonReporter.kt | 15 ++-
.../cli/reporter/plain/PlainReporter.kt | 22 ++--
.../api/ktlint-rule-engine-core.api | 33 -----
.../rule/engine/core/api/IndentConfig.kt | 8 +-
.../ktlint/rule/engine/core/api/Rule.kt | 29 +++--
.../core/api/editorconfig/EditorConfig.kt | 4 +-
.../api/editorconfig/EditorConfigProperty.kt | 8 +-
.../core/api/editorconfig/EditorConfigTest.kt | 120 ++++++++++--------
ktlint-rule-engine/api/ktlint-rule-engine.api | 10 --
.../rule/engine/api/EditorConfigDefaults.kt | 4 +-
.../ktlint/rule/engine/api/LintError.kt | 14 +-
ktlint-test/api/ktlint-test.api | 7 +-
.../pinterest/ktlint/test/KtLintAssertThat.kt | 16 ++-
23 files changed, 187 insertions(+), 174 deletions(-)
diff --git a/.github/workflows/pull-request-with-code.yml b/.github/workflows/pull-request-with-code.yml
index a23df1bebd..9dcc8293de 100644
--- a/.github/workflows/pull-request-with-code.yml
+++ b/.github/workflows/pull-request-with-code.yml
@@ -49,3 +49,24 @@ jobs:
run: ./gradlew build ktlintCheck --no-configuration-cache
- name: Build with dev Kotlin version
run: ./gradlew -PkotlinDev build ktlintCheck --no-configuration-cache
+
+ - name: Check `data class`es are not part of public API
+ run: |
+ found=0
+
+ # Loop through all .api files in the current directory and subdirectories
+ for file in $(find . -type f -name "*.api" ! -path "*/build/*"); do
+ # Check if the file contains the 'data class' specific text
+ if grep -q "public static synthetic fun copy$default" "$file"; then
+ echo "public 'data class' found in: $file"
+ found=1
+ fi
+ done
+
+ if [ $found -eq 0 ]; then
+ exit 0
+ else
+ echo "data classes found in one or more .api files. Visit https://github.com/pinterest/ktlint/issues/2133 for more details"
+ exit 1
+ fi
+ shell: bash
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f9e7f4be0..f95177bf92 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Add rule `class-signature`. This rule rewrites the class header to a consistent format. In code style `ktlint_official`, super types are always wrapped to a separate line. In other code styles, super types are only wrapped in classes having multiple super types. Especially for code style `ktlint_official` the class headers are rewritten in a more consistent format. See [examples in documentation](https://pinterest.github.io/ktlint/latest/rules/experimental/#class-signature). `class-signature` [#875](https://github.com/pinterest/ktlint/issues/1349), [#1349](https://github.com/pinterest/ktlint/issues/875)
### Removed
+* As a part of public API stabilization, data classes are no longer used in the public API. As of that, functions like `copy()` or `componentN()` (used for destructuring declarations) are not available anymore. This is a binary incompatible change, breaking backwards compatibility. ([#2133](https://github.com/pinterest/ktlint/issues/2133))
### Fixed
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts
index 193bee34ed..bffd7b7aff 100644
--- a/build-logic/build.gradle.kts
+++ b/build-logic/build.gradle.kts
@@ -17,4 +17,5 @@ dependencies {
}
implementation(kotlinPlugin)
implementation(libs.dokka)
+ implementation(libs.poko)
}
diff --git a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts
index c612c0a9dd..8a6f779a01 100644
--- a/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts
+++ b/build-logic/src/main/kotlin/ktlint-kotlin-common.gradle.kts
@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
+ id("dev.drewhamilton.poko")
}
kotlin {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 74cd687ccf..35b9516aa0 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -18,6 +18,8 @@ ec4j = "org.ec4j.core:ec4j-core:0.3.0"
picocli = "info.picocli:picocli:4.7.4"
logging = "io.github.microutils:kotlin-logging-jvm:3.0.5"
slf4j = "org.slf4j:slf4j-simple:2.0.7"
+# TODO: update to 0.14.0 after upgrade to Kotlin Gradle Plugin 1.9
+poko = "dev.drewhamilton.poko:poko-gradle-plugin:0.13.1"
# Use logback-classic as the logger for kotlin-logging / slf4j as it allow changing the log level at runtime.
logback = "ch.qos.logback:logback-classic:1.3.5"
# Required for logback.xml conditional configuration
diff --git a/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineReporter.kt b/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineReporter.kt
index 11898b3215..fa3252a72f 100644
--- a/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineReporter.kt
+++ b/ktlint-cli-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/cli/reporter/baseline/BaselineReporter.kt
@@ -33,8 +33,10 @@ public class BaselineReporter(
// checking out this repository on a different path, the baseline will still be respected.
val relativeFile = Paths.get(file).relativeLocation()
out.println(""" """)
- for ((line, col, ruleId, _) in errList) {
- out.println(""" """)
+ for (err in errList) {
+ with(err) {
+ out.println(""" """)
+ }
}
out.println(""" """)
}
diff --git a/ktlint-cli-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/cli/reporter/checkstyle/CheckStyleReporter.kt b/ktlint-cli-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/cli/reporter/checkstyle/CheckStyleReporter.kt
index 310cccbd4b..df1430a7c5 100644
--- a/ktlint-cli-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/cli/reporter/checkstyle/CheckStyleReporter.kt
+++ b/ktlint-cli-reporter-checkstyle/src/main/kotlin/com/pinterest/ktlint/cli/reporter/checkstyle/CheckStyleReporter.kt
@@ -26,11 +26,13 @@ public class CheckStyleReporter(
out.println("""""")
for ((file, errList) in acc.entries.sortedBy { it.key }) {
out.println(""" """)
- for ((line, col, ruleId, detail) in errList) {
- val message = detail.escapeXMLAttrValue()
- out.println(
- """ """,
- )
+ for (err in errList) {
+ with(err) {
+ val message = detail.escapeXMLAttrValue()
+ out.println(
+ """ """,
+ )
+ }
}
out.println(""" """)
}
diff --git a/ktlint-cli-reporter-core/api/ktlint-cli-reporter-core.api b/ktlint-cli-reporter-core/api/ktlint-cli-reporter-core.api
index fa8b91c847..5e6faffccc 100644
--- a/ktlint-cli-reporter-core/api/ktlint-cli-reporter-core.api
+++ b/ktlint-cli-reporter-core/api/ktlint-cli-reporter-core.api
@@ -1,12 +1,5 @@
public final class com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError : java/io/Serializable {
public fun (IILjava/lang/String;Ljava/lang/String;Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;)V
- public final fun component1 ()I
- public final fun component2 ()I
- public final fun component3 ()Ljava/lang/String;
- public final fun component4 ()Ljava/lang/String;
- public final fun component5 ()Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;
- public final fun copy (IILjava/lang/String;Ljava/lang/String;Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;)Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError;IILjava/lang/String;Ljava/lang/String;Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError$Status;ILjava/lang/Object;)Lcom/pinterest/ktlint/cli/reporter/core/api/KtlintCliError;
public fun equals (Ljava/lang/Object;)Z
public final fun getCol ()I
public final fun getDetail ()Ljava/lang/String;
diff --git a/ktlint-cli-reporter-core/src/main/kotlin/com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError.kt b/ktlint-cli-reporter-core/src/main/kotlin/com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError.kt
index 484b8111f7..35e565f5f5 100644
--- a/ktlint-cli-reporter-core/src/main/kotlin/com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError.kt
+++ b/ktlint-cli-reporter-core/src/main/kotlin/com/pinterest/ktlint/cli/reporter/core/api/KtlintCliError.kt
@@ -1,5 +1,6 @@
package com.pinterest.ktlint.cli.reporter.core.api
+import dev.drewhamilton.poko.Poko
import java.io.Serializable
/**
@@ -11,12 +12,13 @@ import java.io.Serializable
* [detail]: error message
* [status]: status of error
*/
-public data class KtlintCliError(
- val line: Int,
- val col: Int,
- val ruleId: String,
- val detail: String,
- val status: Status,
+@Poko
+public class KtlintCliError(
+ public val line: Int,
+ public val col: Int,
+ public val ruleId: String,
+ public val detail: String,
+ public val status: Status,
) : Serializable {
public enum class Status {
/**
diff --git a/ktlint-cli-reporter-html/src/main/kotlin/com/pinterest/ktlint/cli/reporter/html/HtmlReporter.kt b/ktlint-cli-reporter-html/src/main/kotlin/com/pinterest/ktlint/cli/reporter/html/HtmlReporter.kt
index acd8a74472..4c7db992ec 100644
--- a/ktlint-cli-reporter-html/src/main/kotlin/com/pinterest/ktlint/cli/reporter/html/HtmlReporter.kt
+++ b/ktlint-cli-reporter-html/src/main/kotlin/com/pinterest/ktlint/cli/reporter/html/HtmlReporter.kt
@@ -78,8 +78,10 @@ public class HtmlReporter(
acc.forEach { (file: String, ktlintCliErrors: MutableList) ->
h3 { text(file) }
ul {
- ktlintCliErrors.forEach { (line, col, ruleId, detail) ->
- item("($line, $col): $detail ($ruleId)")
+ ktlintCliErrors.forEach { err ->
+ with(err) {
+ item("($line, $col): $detail ($ruleId)")
+ }
}
}
}
diff --git a/ktlint-cli-reporter-json/src/main/kotlin/com/pinterest/ktlint/cli/reporter/json/JsonReporter.kt b/ktlint-cli-reporter-json/src/main/kotlin/com/pinterest/ktlint/cli/reporter/json/JsonReporter.kt
index 0ac981dda7..1daa6b6b4a 100644
--- a/ktlint-cli-reporter-json/src/main/kotlin/com/pinterest/ktlint/cli/reporter/json/JsonReporter.kt
+++ b/ktlint-cli-reporter-json/src/main/kotlin/com/pinterest/ktlint/cli/reporter/json/JsonReporter.kt
@@ -31,13 +31,14 @@ public class JsonReporter(
out.println(""" "errors": [""")
val errIndexLast = errList.size - 1
for ((errIndex, err) in errList.withIndex()) {
- val (line, col, ruleId, detail) = err
- out.println(""" {""")
- out.println(""" "line": $line,""")
- out.println(""" "column": $col,""")
- out.println(""" "message": "${detail.escapeJsonValue()}",""")
- out.println(""" "rule": "$ruleId"""")
- out.println(""" }${if (errIndex != errIndexLast) "," else ""}""")
+ with(err) {
+ out.println(""" {""")
+ out.println(""" "line": $line,""")
+ out.println(""" "column": $col,""")
+ out.println(""" "message": "${detail.escapeJsonValue()}",""")
+ out.println(""" "rule": "$ruleId"""")
+ out.println(""" }${if (errIndex != errIndexLast) "," else ""}""")
+ }
}
out.println(""" ]""")
out.println(""" }${if (index != indexLast) "," else ""}""")
diff --git a/ktlint-cli-reporter-plain/src/main/kotlin/com/pinterest/ktlint/cli/reporter/plain/PlainReporter.kt b/ktlint-cli-reporter-plain/src/main/kotlin/com/pinterest/ktlint/cli/reporter/plain/PlainReporter.kt
index f12bbb4e83..3439329dd1 100644
--- a/ktlint-cli-reporter-plain/src/main/kotlin/com/pinterest/ktlint/cli/reporter/plain/PlainReporter.kt
+++ b/ktlint-cli-reporter-plain/src/main/kotlin/com/pinterest/ktlint/cli/reporter/plain/PlainReporter.kt
@@ -52,16 +52,18 @@ public class PlainReporter(
if (groupByFile) {
val errList = acc[file] ?: return
out.println(colorFileName(file))
- for ((line, col, ruleId, detail) in errList) {
- val column =
- if (pad) {
- String.format("%-3s", col)
- } else {
- col
- }
- out.println(
- " $line${":$column".colored()} $detail ${"($ruleId)".colored()}",
- )
+ for (err in errList) {
+ with(err) {
+ val column =
+ if (pad) {
+ String.format("%-3s", col)
+ } else {
+ col
+ }
+ out.println(
+ " $line${":$column".colored()} $detail ${"($ruleId)".colored()}",
+ )
+ }
}
}
}
diff --git a/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api b/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api
index 136b77501e..4b797a0332 100644
--- a/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api
+++ b/ktlint-rule-engine-core/api/ktlint-rule-engine-core.api
@@ -342,11 +342,7 @@ public final class com/pinterest/ktlint/rule/engine/core/api/IndentConfig {
public fun (Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;I)V
public fun (Lorg/ec4j/core/model/PropertyType$IndentStyleValue;I)V
public final fun childIndentOf (Lorg/jetbrains/kotlin/com/intellij/lang/ASTNode;)Ljava/lang/String;
- public final fun component1 ()Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;
- public final fun component2 ()I
public final fun containsUnexpectedIndentChar (Ljava/lang/String;)Z
- public final fun copy (Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;I)Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig;Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig$IndentStyle;IILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/IndentConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun getDisabled ()Z
public final fun getIndent ()Ljava/lang/String;
@@ -394,11 +390,6 @@ public final class com/pinterest/ktlint/rule/engine/core/api/Rule$About {
public fun ()V
public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
- public final fun component1 ()Ljava/lang/String;
- public final fun component2 ()Ljava/lang/String;
- public final fun component3 ()Ljava/lang/String;
- public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/Rule$About;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/Rule$About;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/Rule$About;
public fun equals (Ljava/lang/Object;)Z
public final fun getIssueTrackerUrl ()Ljava/lang/String;
public final fun getMaintainer ()Ljava/lang/String;
@@ -418,10 +409,6 @@ public abstract class com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModi
public final class com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule : com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier {
public fun (Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;)V
- public final fun component1 ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;
- public final fun component2 ()Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
- public final fun copy (Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;)Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule;Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule;
public fun equals (Ljava/lang/Object;)Z
public final fun getMode ()Lcom/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifier$RunAfterRule$Mode;
public final fun getRuleId ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;
@@ -443,9 +430,6 @@ public final class com/pinterest/ktlint/rule/engine/core/api/Rule$VisitorModifie
public final class com/pinterest/ktlint/rule/engine/core/api/RuleId {
public static final field Companion Lcom/pinterest/ktlint/rule/engine/core/api/RuleId$Companion;
public fun (Ljava/lang/String;)V
- public final fun component1 ()Ljava/lang/String;
- public final fun copy (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;Ljava/lang/String;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;
public fun equals (Ljava/lang/Object;)Z
public final fun getRuleSetId ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleSetId;
public final fun getValue ()Ljava/lang/String;
@@ -477,9 +461,6 @@ public final class com/pinterest/ktlint/rule/engine/core/api/RuleProviderKt {
public final class com/pinterest/ktlint/rule/engine/core/api/RuleSetId {
public static final field Companion Lcom/pinterest/ktlint/rule/engine/core/api/RuleSetId$Companion;
public fun (Ljava/lang/String;)V
- public final fun component1 ()Ljava/lang/String;
- public final fun copy (Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/RuleSetId;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/RuleSetId;Ljava/lang/String;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/RuleSetId;
public fun equals (Ljava/lang/Object;)Z
public final fun getValue ()Ljava/lang/String;
public fun hashCode ()I
@@ -510,8 +491,6 @@ public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/Editor
public fun ([Lorg/ec4j/core/model/Property;)V
public final fun addPropertiesWithDefaultValueIfMissing ([Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;
public final fun contains (Ljava/lang/String;)Z
- public final fun copy (Ljava/util/Map;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;Ljava/util/Map;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;
public fun equals (Ljava/lang/Object;)Z
public final fun filterBy (Ljava/util/Set;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig;
public final fun get (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty;)Ljava/lang/Object;
@@ -524,18 +503,6 @@ public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/Editor
public final class com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty {
public fun (Lorg/ec4j/core/model/PropertyType;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun (Lorg/ec4j/core/model/PropertyType;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
- public final fun component1 ()Lorg/ec4j/core/model/PropertyType;
- public final fun component10 ()Ljava/lang/String;
- public final fun component2 ()Ljava/lang/Object;
- public final fun component3 ()Ljava/lang/Object;
- public final fun component4 ()Ljava/lang/Object;
- public final fun component5 ()Ljava/lang/Object;
- public final fun component6 ()Lkotlin/jvm/functions/Function2;
- public final fun component7 ()Lkotlin/jvm/functions/Function1;
- public final fun component8 ()Ljava/lang/String;
- public final fun component9 ()Ljava/lang/String;
- public final fun copy (Lorg/ec4j/core/model/PropertyType;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty;Lorg/ec4j/core/model/PropertyType;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty;
public fun equals (Ljava/lang/Object;)Z
public final fun getAndroidStudioCodeStyleDefaultValue ()Ljava/lang/Object;
public final fun getDefaultValue ()Ljava/lang/Object;
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt
index 48d1c4bee8..6df4dc53d3 100644
--- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt
+++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/IndentConfig.kt
@@ -4,15 +4,17 @@ import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.IndentStyle.SPACE
import com.pinterest.ktlint.rule.engine.core.api.IndentConfig.IndentStyle.TAB
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_SIZE_PROPERTY
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.INDENT_STYLE_PROPERTY
+import dev.drewhamilton.poko.Poko
import org.ec4j.core.model.PropertyType
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
-public data class IndentConfig(
- val indentStyle: IndentStyle,
+@Poko
+public class IndentConfig(
+ public val indentStyle: IndentStyle,
/**
* The number of spaces that is equivalent to one tab
*/
- val tabWidth: Int,
+ public val tabWidth: Int,
) {
/**
* To use the [IndentConfig] in a rule, the following needs to be done:
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt
index d241c26335..2ae8c5c218 100644
--- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt
+++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/Rule.kt
@@ -3,9 +3,11 @@ package com.pinterest.ktlint.rule.engine.core.api
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfig
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty
import com.pinterest.ktlint.rule.engine.core.internal.IdNamingPolicy
+import dev.drewhamilton.poko.Poko
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
-public data class RuleId(
+@Poko
+public class RuleId(
public val value: String,
) {
init {
@@ -28,7 +30,8 @@ public data class RuleId(
}
}
-public data class RuleSetId(
+@Poko
+public class RuleSetId(
public val value: String,
) {
init {
@@ -97,7 +100,8 @@ public open class Rule(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
- ) {}
+ ) {
+ }
/**
* This method is called on a node in AST after all its child nodes have been visited.
@@ -107,7 +111,8 @@ public open class Rule(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
- ) {}
+ ) {
+ }
/**
* This method is called once after the last node in the AST is visited. It can be used for teardown of the state
@@ -179,19 +184,20 @@ public open class Rule(
* API consumers to provide more detailed information about the rule. Please provide all details below, so that users of your rule set
* can easily get up-to-date information about the rule.
*/
- public data class About(
+ @Poko
+ public class About(
/**
* Name of person, organisation or group maintaining the rule.
*/
- val maintainer: String = "Not specified (and not maintained by the Ktlint project)",
+ public val maintainer: String = "Not specified (and not maintained by the Ktlint project)",
/**
* Url to the repository containing the rule.
*/
- val repositoryUrl: String = "Not specified",
+ public val repositoryUrl: String = "Not specified",
/**
* Url to the issue tracker of the project which provides the rule.
*/
- val issueTrackerUrl: String = "Not specified",
+ public val issueTrackerUrl: String = "Not specified",
)
public sealed class VisitorModifier {
@@ -199,16 +205,17 @@ public open class Rule(
* Defines that the [Rule] that declares this [VisitorModifier] will be run after the [Rule] with rule id
* [VisitorModifier.RunAfterRule.ruleId].
*/
- public data class RunAfterRule(
+ @Poko
+ public class RunAfterRule(
/**
* The [RuleId] of the [Rule] which should run before the [Rule] that declares the [VisitorModifier.RunAfterRule].
*/
- val ruleId: RuleId,
+ public val ruleId: RuleId,
/**
* The [Mode] determines whether the [Rule] that declares this [VisitorModifier] can be run in case the [Rule] with rule id
* [VisitorModifier.RunAfterRule.ruleId] is not loaded or enabled.
*/
- val mode: Mode,
+ public val mode: Mode,
) : VisitorModifier() {
public enum class Mode {
/**
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig.kt
index 86e9850800..a859a9274a 100644
--- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig.kt
+++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfig.kt
@@ -2,6 +2,7 @@ package com.pinterest.ktlint.rule.engine.core.api.editorconfig
import com.pinterest.ktlint.logger.api.initKtLintKLogger
import com.pinterest.ktlint.rule.engine.core.api.Rule
+import dev.drewhamilton.poko.Poko
import mu.KotlinLogging
import org.ec4j.core.model.Property
import org.ec4j.core.model.PropertyType
@@ -12,7 +13,8 @@ private val LOGGER = KotlinLogging.logger {}.initKtLintKLogger()
/**
* Loaded [Property]s from `.editorconfig` files.
*/
-public data class EditorConfig(
+@Poko
+public class EditorConfig(
private val properties: Map = emptyMap(),
) {
public constructor(vararg properties: Property) : this(
diff --git a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty.kt b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty.kt
index 80e385108c..866ddb3ce6 100644
--- a/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty.kt
+++ b/ktlint-rule-engine-core/src/main/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigProperty.kt
@@ -1,5 +1,6 @@
package com.pinterest.ktlint.rule.engine.core.api.editorconfig
+import dev.drewhamilton.poko.Poko
import org.ec4j.core.model.Property
import org.ec4j.core.model.PropertyType
@@ -14,7 +15,8 @@ import org.ec4j.core.model.PropertyType
* - Kotlin specific properties defined
* [here](https://github.com/JetBrains/kotlin/blob/master/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java)
*/
-public data class EditorConfigProperty(
+@Poko
+public class EditorConfigProperty(
/**
* Type of property. Could be one of default ones (see [PropertyType.STANDARD_TYPES]) or custom one.
*/
@@ -71,11 +73,11 @@ public data class EditorConfigProperty(
/**
* Optional message to be displayed whenever the value of the property is being retrieved while it has been deprecated.
*/
- val deprecationWarning: String? = null,
+ public val deprecationWarning: String? = null,
/**
* Optional message to be displayed whenever the value of the property is being retrieved while it has been deprecated.
*/
- val deprecationError: String? = null,
+ public val deprecationError: String? = null,
/**
* Name of the property. A property must be named in case multiple properties are defined for the same type.
* Defaults to the name of the type when not set.
diff --git a/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigTest.kt b/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigTest.kt
index 2fea1866db..2fddc66e92 100644
--- a/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigTest.kt
+++ b/ktlint-rule-engine-core/src/test/kotlin/com/pinterest/ktlint/rule/engine/core/api/editorconfig/EditorConfigTest.kt
@@ -6,6 +6,7 @@ import com.pinterest.ktlint.test.KtlintTestFileSystem
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatNoException
import org.assertj.core.api.Assertions.assertThatThrownBy
+import org.ec4j.core.model.Property
import org.ec4j.core.model.PropertyType
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
@@ -16,25 +17,25 @@ class EditorConfigTest {
fun `Given an EditorConfig from which a non existing property is retrieved then an exception is thrown`() {
val editorConfig = EditorConfig()
- assertThatThrownBy { editorConfig[SOME_EDITOR_CONFIG_PROPERTY] }
+ assertThatThrownBy { editorConfig[sampleEditorConfigProperty()] }
.isInstanceOf(IllegalStateException::class.java)
.hasMessageStartingWith("Property '$SOME_PROPERTY_NAME' can not be retrieved from this EditorConfig.")
}
@Test
fun `Given an EditorConfig from which an existing property is retrieved then return the value of that property`() {
- val editorConfig = EditorConfig(SOME_EDITOR_CONFIG_PROPERTY.toPropertyWithValue(SOME_PROPERTY_VALUE))
+ val editorConfig = EditorConfig(sampleEditorConfigProperty().toPropertyWithValue(SOME_PROPERTY_VALUE))
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE)
}
@Test
fun `Given an empty EditorConfig and add a property with default value then the default value can be retrieved for the default code style`() {
- val editorConfig = EditorConfig().addPropertiesWithDefaultValueIfMissing(SOME_EDITOR_CONFIG_PROPERTY)
+ val editorConfig = EditorConfig().addPropertiesWithDefaultValueIfMissing(sampleEditorConfigProperty())
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE_KTLINT_OFFICIAL)
}
@@ -53,9 +54,9 @@ class EditorConfigTest {
) {
val editorConfig =
EditorConfig(CODE_STYLE_PROPERTY.toPropertyWithValue(codeStyleValue.name))
- .addPropertiesWithDefaultValueIfMissing(SOME_EDITOR_CONFIG_PROPERTY)
+ .addPropertiesWithDefaultValueIfMissing(sampleEditorConfigProperty())
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(expectedValue)
}
@@ -63,10 +64,10 @@ class EditorConfigTest {
@Test
fun `Given an EditorConfig containing a certain property with a non-default value and add the same property again with default value then the non-default value is not overwritten`() {
val editorConfig =
- EditorConfig(SOME_EDITOR_CONFIG_PROPERTY.toPropertyWithValue(SOME_PROPERTY_VALUE))
- .addPropertiesWithDefaultValueIfMissing(SOME_EDITOR_CONFIG_PROPERTY)
+ EditorConfig(sampleEditorConfigProperty().toPropertyWithValue(SOME_PROPERTY_VALUE))
+ .addPropertiesWithDefaultValueIfMissing(sampleEditorConfigProperty())
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE)
}
@@ -74,7 +75,7 @@ class EditorConfigTest {
@Test
fun `Given an EditorConfig from which a deprecated -error-level- property is retrieved then thrown an exception`() {
val someDeprecationMessage = "some-deprecation-message"
- val someDeprecatedEditorConfigProperty = SOME_EDITOR_CONFIG_PROPERTY.copy(deprecationError = someDeprecationMessage)
+ val someDeprecatedEditorConfigProperty = sampleEditorConfigProperty(deprecationError = someDeprecationMessage)
val editorConfig = EditorConfig().addPropertiesWithDefaultValueIfMissing(someDeprecatedEditorConfigProperty)
assertThatThrownBy { editorConfig[someDeprecatedEditorConfigProperty] }
@@ -83,19 +84,19 @@ class EditorConfigTest {
@Test
fun `Given an EditorConfig from which a deprecated -warning-level- property is retrieved then do not throw an exception`() {
- val someDeprecatedEditorConfigProperty = SOME_EDITOR_CONFIG_PROPERTY.copy(deprecationWarning = "some-deprecation-message")
+ val someDeprecatedEditorConfigProperty = sampleEditorConfigProperty(deprecationWarning = "some-deprecation-message")
val editorConfig = EditorConfig().addPropertiesWithDefaultValueIfMissing(someDeprecatedEditorConfigProperty)
- editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ editorConfig[sampleEditorConfigProperty()]
assertThatNoException()
}
@Test
fun `Given an EditorConfig containing a property then 'contains' returns true when that property is retrieved`() {
- val editorConfig = EditorConfig(SOME_EDITOR_CONFIG_PROPERTY.toPropertyWithValue(SOME_PROPERTY_VALUE))
+ val editorConfig = EditorConfig(sampleEditorConfigProperty().toPropertyWithValue(SOME_PROPERTY_VALUE))
- val actual = editorConfig.contains(SOME_EDITOR_CONFIG_PROPERTY.name)
+ val actual = editorConfig.contains(sampleEditorConfigProperty().name)
assertThat(actual).isTrue
}
@@ -104,7 +105,7 @@ class EditorConfigTest {
fun `Given an EditorConfig then 'contains' returns false when a non-existent property is retrieved`() {
val editorConfig = EditorConfig()
- val actual = editorConfig.contains(SOME_EDITOR_CONFIG_PROPERTY.name)
+ val actual = editorConfig.contains(sampleEditorConfigProperty().name)
assertThat(actual).isFalse
}
@@ -118,8 +119,8 @@ class EditorConfigTest {
val editorConfig =
EditorConfig()
.addPropertiesWithDefaultValueIfMissing(
- SOME_EDITOR_CONFIG_PROPERTY.copy(name = propertyName1, ktlintOfficialCodeStyleDefaultValue = propertyValue1),
- SOME_EDITOR_CONFIG_PROPERTY.copy(name = propertyName2, ktlintOfficialCodeStyleDefaultValue = propertyValue2),
+ sampleEditorConfigProperty(name = propertyName1, ktlintOfficialCodeStyleDefaultValue = propertyValue1),
+ sampleEditorConfigProperty(name = propertyName2, ktlintOfficialCodeStyleDefaultValue = propertyValue2),
)
val actual = editorConfig.map { property -> property.name.uppercase() to property.sourceValue.uppercase() }
@@ -135,8 +136,8 @@ class EditorConfigTest {
assertThatThrownBy {
EditorConfig()
.addPropertiesWithDefaultValueIfMissing(
- SOME_EDITOR_CONFIG_PROPERTY.copy(defaultValue = SOME_PROPERTY_VALUE_ANDROID_STUDIO),
- SOME_EDITOR_CONFIG_PROPERTY.copy(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
+ sampleEditorConfigProperty(defaultValue = SOME_PROPERTY_VALUE_ANDROID_STUDIO),
+ sampleEditorConfigProperty(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
)
}.isInstanceOf(IllegalArgumentException::class.java)
.hasMessageStartingWith(
@@ -150,8 +151,8 @@ class EditorConfigTest {
EditorConfig()
.filterBy(
setOf(
- SOME_EDITOR_CONFIG_PROPERTY.copy(defaultValue = SOME_PROPERTY_VALUE_ANDROID_STUDIO),
- SOME_EDITOR_CONFIG_PROPERTY.copy(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
+ sampleEditorConfigProperty(defaultValue = SOME_PROPERTY_VALUE_ANDROID_STUDIO),
+ sampleEditorConfigProperty(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
),
)
}.isInstanceOf(IllegalArgumentException::class.java)
@@ -163,12 +164,12 @@ class EditorConfigTest {
@Test
fun `Given an editorconfig containing a property and a filterBy for a property with the same name is given but with different identity then the existing property is not overwritten`() {
val editorConfig =
- EditorConfig(SOME_EDITOR_CONFIG_PROPERTY.toPropertyWithValue(SOME_PROPERTY_VALUE_ANDROID_STUDIO))
+ EditorConfig(sampleEditorConfigProperty().toPropertyWithValue(SOME_PROPERTY_VALUE_ANDROID_STUDIO))
.filterBy(
- setOf(SOME_EDITOR_CONFIG_PROPERTY.copy(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA)),
+ setOf(sampleEditorConfigProperty(defaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA)),
)
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE_ANDROID_STUDIO)
}
@@ -179,15 +180,13 @@ class EditorConfigTest {
val property2 = "property-2"
val editorConfig =
EditorConfig(
- SOME_EDITOR_CONFIG_PROPERTY
- .copy(name = property1)
+ sampleEditorConfigProperty(name = property1)
.toPropertyWithValue(SOME_PROPERTY_VALUE_ANDROID_STUDIO),
- SOME_EDITOR_CONFIG_PROPERTY
- .copy(name = property2)
+ sampleEditorConfigProperty(name = property2)
.toPropertyWithValue(SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
)
- val actual = editorConfig.getEditorConfigValueOrNull(SOME_EDITOR_CONFIG_PROPERTY.type, property2)
+ val actual = editorConfig.getEditorConfigValueOrNull(sampleEditorConfigProperty().type, property2)
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE_INTELLIJ_IDEA)
}
@@ -195,14 +194,13 @@ class EditorConfigTest {
@Test
fun `Given an editorconfig containing a property for which a property mapper is defined then the property mapper is called`() {
val editorConfigPropertyWithPropertyMapper =
- SOME_EDITOR_CONFIG_PROPERTY
- .copy(
- propertyMapper = { _, _ -> SOME_PROPERTY_VALUE_KTLINT_OFFICIAL },
- defaultValue = SOME_PROPERTY_VALUE,
- androidStudioCodeStyleDefaultValue = null,
- intellijIdeaCodeStyleDefaultValue = null,
- ktlintOfficialCodeStyleDefaultValue = null,
- )
+ sampleEditorConfigProperty(
+ propertyMapper = { _, _ -> SOME_PROPERTY_VALUE_KTLINT_OFFICIAL },
+ defaultValue = SOME_PROPERTY_VALUE,
+ androidStudioCodeStyleDefaultValue = null,
+ intellijIdeaCodeStyleDefaultValue = null,
+ ktlintOfficialCodeStyleDefaultValue = null,
+ )
val editorConfig = EditorConfig().addPropertiesWithDefaultValueIfMissing(editorConfigPropertyWithPropertyMapper)
val actual = editorConfig[editorConfigPropertyWithPropertyMapper]
@@ -214,10 +212,10 @@ class EditorConfigTest {
fun `Given an editorconfig containing a property for which the value is unset then return its default value`() {
val editorConfig =
EditorConfig(
- SOME_EDITOR_CONFIG_PROPERTY.toPropertyWithValue("unset"),
+ sampleEditorConfigProperty().toPropertyWithValue("unset"),
)
- val actual = editorConfig[SOME_EDITOR_CONFIG_PROPERTY]
+ val actual = editorConfig[sampleEditorConfigProperty()]
assertThat(actual).isEqualTo(SOME_PROPERTY_VALUE_KTLINT_OFFICIAL)
}
@@ -324,20 +322,32 @@ class EditorConfigTest {
const val SOME_PROPERTY_VALUE_DEFAULT = "some-property-value-default"
const val SOME_PROPERTY_VALUE_INTELLIJ_IDEA = "some-property-value-intellij-idea"
const val SOME_PROPERTY_VALUE_KTLINT_OFFICIAL = "some-property-value-ktlint-official"
- val SOME_EDITOR_CONFIG_PROPERTY =
- EditorConfigProperty(
- name = SOME_PROPERTY_NAME,
- type =
- PropertyType(
- SOME_PROPERTY_NAME,
- "",
- PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER,
- setOf(SOME_PROPERTY_VALUE_ANDROID_STUDIO, SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
- ),
- defaultValue = SOME_PROPERTY_VALUE_DEFAULT,
- androidStudioCodeStyleDefaultValue = SOME_PROPERTY_VALUE_ANDROID_STUDIO,
- ktlintOfficialCodeStyleDefaultValue = SOME_PROPERTY_VALUE_KTLINT_OFFICIAL,
- intellijIdeaCodeStyleDefaultValue = SOME_PROPERTY_VALUE_INTELLIJ_IDEA,
- )
+
+ fun sampleEditorConfigProperty(
+ name: String = SOME_PROPERTY_NAME,
+ defaultValue: String = SOME_PROPERTY_VALUE_DEFAULT,
+ androidStudioCodeStyleDefaultValue: String? = SOME_PROPERTY_VALUE_ANDROID_STUDIO,
+ ktlintOfficialCodeStyleDefaultValue: String? = SOME_PROPERTY_VALUE_KTLINT_OFFICIAL,
+ intellijIdeaCodeStyleDefaultValue: String? = SOME_PROPERTY_VALUE_INTELLIJ_IDEA,
+ deprecationError: String? = null,
+ deprecationWarning: String? = null,
+ propertyMapper: ((Property?, CodeStyleValue) -> String?)? = null,
+ ) = EditorConfigProperty(
+ name = name,
+ type =
+ PropertyType(
+ name,
+ "",
+ PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER,
+ setOf(SOME_PROPERTY_VALUE_ANDROID_STUDIO, SOME_PROPERTY_VALUE_INTELLIJ_IDEA),
+ ),
+ defaultValue = defaultValue,
+ androidStudioCodeStyleDefaultValue = androidStudioCodeStyleDefaultValue,
+ ktlintOfficialCodeStyleDefaultValue = ktlintOfficialCodeStyleDefaultValue,
+ intellijIdeaCodeStyleDefaultValue = intellijIdeaCodeStyleDefaultValue,
+ deprecationError = deprecationError,
+ deprecationWarning = deprecationWarning,
+ propertyMapper = propertyMapper,
+ )
}
}
diff --git a/ktlint-rule-engine/api/ktlint-rule-engine.api b/ktlint-rule-engine/api/ktlint-rule-engine.api
index 45f2da4585..6a6034a669 100644
--- a/ktlint-rule-engine/api/ktlint-rule-engine.api
+++ b/ktlint-rule-engine/api/ktlint-rule-engine.api
@@ -21,9 +21,6 @@ public final class com/pinterest/ktlint/rule/engine/api/Code$Companion {
public final class com/pinterest/ktlint/rule/engine/api/EditorConfigDefaults {
public static final field Companion Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults$Companion;
public fun (Lorg/ec4j/core/model/EditorConfig;)V
- public final fun component1 ()Lorg/ec4j/core/model/EditorConfig;
- public final fun copy (Lorg/ec4j/core/model/EditorConfig;)Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;Lorg/ec4j/core/model/EditorConfig;ILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/api/EditorConfigDefaults;
public fun equals (Ljava/lang/Object;)Z
public final fun getValue ()Lorg/ec4j/core/model/EditorConfig;
public fun hashCode ()I
@@ -90,13 +87,6 @@ public final class com/pinterest/ktlint/rule/engine/api/KtLintRuleException : ja
public final class com/pinterest/ktlint/rule/engine/api/LintError {
public fun (IILcom/pinterest/ktlint/rule/engine/core/api/RuleId;Ljava/lang/String;Z)V
- public final fun component1 ()I
- public final fun component2 ()I
- public final fun component3 ()Lcom/pinterest/ktlint/rule/engine/core/api/RuleId;
- public final fun component4 ()Ljava/lang/String;
- public final fun component5 ()Z
- public final fun copy (IILcom/pinterest/ktlint/rule/engine/core/api/RuleId;Ljava/lang/String;Z)Lcom/pinterest/ktlint/rule/engine/api/LintError;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/rule/engine/api/LintError;IILcom/pinterest/ktlint/rule/engine/core/api/RuleId;Ljava/lang/String;ZILjava/lang/Object;)Lcom/pinterest/ktlint/rule/engine/api/LintError;
public fun equals (Ljava/lang/Object;)Z
public final fun getCanBeAutoCorrected ()Z
public final fun getCol ()I
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/EditorConfigDefaults.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/EditorConfigDefaults.kt
index ae6d2829cd..cb6618179d 100644
--- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/EditorConfigDefaults.kt
+++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/EditorConfigDefaults.kt
@@ -2,6 +2,7 @@ package com.pinterest.ktlint.rule.engine.api
import com.pinterest.ktlint.rule.engine.internal.EditorConfigDefaultsLoader
import com.pinterest.ktlint.rule.engine.internal.EditorConfigLoaderEc4j
+import dev.drewhamilton.poko.Poko
import org.ec4j.core.model.EditorConfig
import org.ec4j.core.model.PropertyType
import java.nio.file.Path
@@ -10,7 +11,8 @@ import java.nio.file.Path
* Wrapper around the ec4j [EditorConfig]. Only to be used to specify the default value of ec4j properties. Those default values will only
* be used whenever a property is retrieved from the ec4j [EditorConfig] and the property has not been defined in the ".editorconfig" file.
*/
-public data class EditorConfigDefaults(
+@Poko
+public class EditorConfigDefaults(
/**
* The ec4j [EditorConfig] containing the default value of the ec4j properties. Those default values will only be used whenever a
* property is retrieved from the ec4j [EditorConfig] and the property has not been defined in the ".editorconfig" file.
diff --git a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/LintError.kt b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/LintError.kt
index 7d02e72e43..08981cb727 100644
--- a/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/LintError.kt
+++ b/ktlint-rule-engine/src/main/kotlin/com/pinterest/ktlint/rule/engine/api/LintError.kt
@@ -1,6 +1,7 @@
package com.pinterest.ktlint.rule.engine.api
import com.pinterest.ktlint.rule.engine.core.api.RuleId
+import dev.drewhamilton.poko.Poko
/**
* Lint error found by the [KtLintRuleEngine].
@@ -11,10 +12,11 @@ import com.pinterest.ktlint.rule.engine.core.api.RuleId
* [detail]: error message
* [canBeAutoCorrected]: flag indicating whether the error can be corrected by the rule if "format" is run
*/
-public data class LintError(
- val line: Int,
- val col: Int,
- val ruleId: RuleId,
- val detail: String,
- val canBeAutoCorrected: Boolean,
+@Poko
+public class LintError(
+ public val line: Int,
+ public val col: Int,
+ public val ruleId: RuleId,
+ public val detail: String,
+ public val canBeAutoCorrected: Boolean,
)
diff --git a/ktlint-test/api/ktlint-test.api b/ktlint-test/api/ktlint-test.api
index 3f80747233..4b3504a0ea 100644
--- a/ktlint-test/api/ktlint-test.api
+++ b/ktlint-test/api/ktlint-test.api
@@ -63,14 +63,9 @@ public final class com/pinterest/ktlint/test/KtlintTestFileSystem {
}
public final class com/pinterest/ktlint/test/LintViolation {
+ public fun (IILjava/lang/String;)V
public fun (IILjava/lang/String;Z)V
public synthetic fun (IILjava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
- public final fun component1 ()I
- public final fun component2 ()I
- public final fun component3 ()Ljava/lang/String;
- public final fun component4 ()Z
- public final fun copy (IILjava/lang/String;Z)Lcom/pinterest/ktlint/test/LintViolation;
- public static synthetic fun copy$default (Lcom/pinterest/ktlint/test/LintViolation;IILjava/lang/String;ZILjava/lang/Object;)Lcom/pinterest/ktlint/test/LintViolation;
public fun equals (Ljava/lang/Object;)Z
public final fun getCanBeAutoCorrected ()Z
public final fun getCol ()I
diff --git a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt
index e2e8ca90ef..021655ab84 100644
--- a/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt
+++ b/ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt
@@ -18,6 +18,7 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution
import com.pinterest.ktlint.rule.engine.core.api.editorconfig.createRuleSetExecutionEditorConfigProperty
import com.pinterest.ktlint.test.KtLintAssertThat.Companion.EOL_CHAR
import com.pinterest.ktlint.test.KtLintAssertThat.Companion.MAX_LINE_LENGTH_MARKER
+import dev.drewhamilton.poko.Poko
import mu.KotlinLogging
import org.assertj.core.api.AbstractAssert
import org.assertj.core.api.Assertions.assertThat
@@ -653,12 +654,15 @@ internal class MissingEolMarker :
* Expectation of the [LintError]. Contrary to the [LintError] it does not contain the ruleId. The ruleId will be derived from the rule for
* which the AssertThat was created.
*/
-public data class LintViolation(
- val line: Int,
- val col: Int,
- val detail: String,
- val canBeAutoCorrected: Boolean = true,
-)
+@Poko
+public class LintViolation
+ @JvmOverloads
+ constructor(
+ public val line: Int,
+ public val col: Int,
+ public val detail: String,
+ public val canBeAutoCorrected: Boolean = true,
+ )
/**
* Enables the rule sets for the given set of [ruleProviders] unless the rule execution of that rule set was already provided.