Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Drop 'indentSize' #245

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ Options are configured in the `kotlinter` extension. Defaults shown (you may omi
```kotlin
kotlinter {
ignoreFailures = false
indentSize = 4
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
disabledRules = emptyArray()
Expand All @@ -167,7 +166,6 @@ kotlinter {
```groovy
kotlinter {
ignoreFailures = false
indentSize = 4
reporters = ['checkstyle', 'plain']
experimentalRules = false
disabledRules = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ open class KotlinterExtension {

var ignoreFailures = DEFAULT_IGNORE_FAILURES

var indentSize: Int? = null

var reporters = arrayOf(DEFAULT_REPORTER)

var experimentalRules = DEFAULT_EXPERIMENTAL_RULES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class KotlinterPlugin : Plugin<Project> {
}
}
)
lintTask.indentSize.set(provider { kotlinterExtension.indentSize })
lintTask.experimentalRules.set(provider { kotlinterExtension.experimentalRules })
lintTask.disabledRules.set(provider { kotlinterExtension.disabledRules.toList() })
}
Expand All @@ -58,7 +57,6 @@ class KotlinterPlugin : Plugin<Project> {
val formatKotlinPerSourceSet = tasks.register("formatKotlin${id.capitalize()}", FormatTask::class.java) { formatTask ->
formatTask.source(resolvedSources)
formatTask.report.set(reportFile("$id-format.txt"))
formatTask.indentSize.set(provider { kotlinterExtension.indentSize })
formatTask.experimentalRules.set(provider { kotlinterExtension.experimentalRules })
formatTask.disabledRules.set(provider { kotlinterExtension.disabledRules.toList() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.jmailen.gradle.kotlinter.support
import java.io.Serializable

data class KtLintParams(
val indentSize: Int?,
val experimentalRules: Boolean,
val disabledRules: List<String>
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package org.jmailen.gradle.kotlinter.support
fun userData(ktLintParams: KtLintParams): Map<String, String> {
val userData = mutableMapOf<String, String>()

ktLintParams.indentSize?.let { indentSize ->
userData["indent_size"] = indentSize.toString()
}
ktLintParams.disabledRules.takeIf { it.isNotEmpty() }?.let { rules ->
userData["disabled_rules"] = rules.joinToString(",")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.SourceTask
import org.gradle.internal.exceptions.MultiCauseException
import org.jmailen.gradle.kotlinter.KotlinterExtension.Companion.DEFAULT_DISABLED_RULES
Expand All @@ -15,10 +14,6 @@ import org.jmailen.gradle.kotlinter.support.KtLintParams

abstract class ConfigurableKtLintTask : SourceTask() {

@Input
@Optional
val indentSize: Property<Int> = property()

@Input
val experimentalRules: Property<Boolean> = property(default = DEFAULT_EXPERIMENTAL_RULES)

Expand All @@ -27,7 +22,6 @@ abstract class ConfigurableKtLintTask : SourceTask() {

@Internal
protected fun getKtLintParams(): KtLintParams = KtLintParams(
indentSize = indentSize.orNull,
experimentalRules = experimentalRules.get(),
disabledRules = disabledRules.get()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class CustomTaskTest : WithGradleTest.Kotlin() {
val validClass =
"""
class CustomClass {
private fun go() {
println("go")
}
private fun go() {
println("go")
}
}
""".trimIndent()
writeText(validClass)
Expand All @@ -64,7 +64,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() {
task ktLint(type: LintTask) {
source files('src')
reports = ['plain': file('build/lint-report.txt')]
indentSize = 5
experimentalRules = true
disabledRules = ["final-newline"]
}
Expand Down Expand Up @@ -113,7 +112,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() {
task customizedLintTask(type: LintTask) {
source files('src')
reports = ['plain': file('build/lint-report.txt')]
indentSize = 123
experimentalRules = true
disabledRules = ["final-newline"]
ignoreFailures = true
Expand Down Expand Up @@ -141,7 +139,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() {

task customizedFormatTask(type: FormatTask) {
source files('src')
indentSize = 123
experimentalRules = true
disabledRules = ["final-newline"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,6 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
}
}

@Test
fun `plugin respects indentSize set in editorconfig`() {
projectRoot.resolve(".editorconfig") {
appendText(
"""
[*.{kt,kts}]
indent_size = 2
""".trimIndent()
)
}
projectRoot.resolve("src/main/kotlin/TwoSpaces.kt") {
writeText(
""" |
|object TwoSpaces {
| val text: String
|}
|
""".trimMargin()
)
}

build("lintKotlin").apply {
assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome)
}
}

@Test
fun `plugin respects disabled_rules set in editorconfig`() {
projectRoot.resolve(".editorconfig") {
Expand All @@ -97,24 +71,12 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {
}

@Test
fun `plugin extension properties take precedence over editorconfig values`() {
fun `plugin respects 'indent_size' set in editorconfig`() {
projectRoot.resolve(".editorconfig") {
appendText(
"""
[*.{kt,kts}]
disabled_rules=filename
indent_size = 2
""".trimIndent()
)
}
projectRoot.resolve("build.gradle") {
appendText(
"""
kotlinter {
disabledRules = ['paren-spacing']
indentSize = 6
}

indent_size = 6
""".trimIndent()
)
}
Expand All @@ -134,7 +96,6 @@ internal class EditorConfigTest : WithGradleTest.Kotlin() {

buildAndFail("lintKotlin").apply {
assertEquals(TaskOutcome.FAILED, task(":lintKotlinMain")?.outcome)
assertTrue(output.contains("[filename] class WrongFileName should be declared in a file named WrongFileName.kt"))
assertTrue(output.contains("[indent] Unexpected indentation (2) (should be 6)"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,6 @@ internal class ExtensionTest : WithGradleTest.Kotlin() {
}
}

@Test
fun `extension configures indentSize`() {
projectRoot.resolve("build.gradle") {
// language=groovy
val script =
"""
kotlinter {
indentSize = 2
}
""".trimIndent()
appendText(script)
}
projectRoot.resolve("src/main/kotlin/TwoSpaces.kt") {
writeText(
""" |
|object TwoSpaces {
| val text: String
|}
|
""".trimMargin()
)
}

build("lintKotlin").apply {
assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome)
}
}

@Test
fun `extension configures reporters`() {
projectRoot.resolve("build.gradle") {
Expand Down Expand Up @@ -156,47 +128,4 @@ internal class ExtensionTest : WithGradleTest.Kotlin() {
assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome)
}
}

@Test
fun `user customized values take precedence over extension values`() {
projectRoot.resolve("src/main/kotlin/FileName.kt") {
// language=kotlin
val kotlinClass =
"""
class Precedence {
fun hi() = Unit
}
""".trimIndent()
writeText(kotlinClass)
}
projectRoot.resolve("build.gradle") {
// language=groovy
val script =
"""
kotlinter {
disabledRules = ['filename']
}

lintKotlinMain {
disabledRules = ['final-newline']
}

""".trimIndent()
appendText(script)
}
// https://github.com/pinterest/ktlint/issues/997
projectRoot.resolve(".editorconfig") {
val config =
"""
[*.{kt,kts}]
indent_size = 4
""".trimIndent()
appendText(config)
}

buildAndFail("lintKotlin").apply {
assertEquals(TaskOutcome.FAILED, task(":lintKotlinMain")?.outcome)
assertTrue(output.contains("[filename] class Precedence should be declared in a file named Precedence.kt"))
}
}
}