-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to disable particular rules via plugin extension.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
- Loading branch information
1 parent
e0756dd
commit d7b8947
Showing
8 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/DisabledRulesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.jlleitschuh.gradle.ktlint | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* Runs [EditorConfigTests] with the current version of Gradle. | ||
*/ | ||
class GradleCurrentCurrentDisabledRulesTest : DisabledRulesTest() | ||
|
||
/** | ||
* Runs [EditorConfigTests] with lowest supported Gradle version. | ||
*/ | ||
@Suppress("ClassName") | ||
class GradleLowestSupportedDisabledRulesTest : DisabledRulesTest() { | ||
override fun gradleRunnerFor(vararg arguments: String): GradleRunner = | ||
super.gradleRunnerFor(*arguments).withGradleVersion(LOWEST_SUPPORTED_GRADLE_VERSION) | ||
} | ||
|
||
abstract class DisabledRulesTest : AbstractPluginTest() { | ||
@BeforeEach | ||
internal fun setUp() { | ||
projectRoot.defaultProjectSetup() | ||
} | ||
|
||
@Test | ||
internal fun `Should lint without errors when "final-newline" is disabled`() { | ||
projectRoot.buildFile().appendText( | ||
""" | ||
ktlint.disabledRules = ["final-newline"] | ||
""".trimIndent() | ||
) | ||
|
||
projectRoot.createSourceFile( | ||
"src/main/kotlin/clean-source.kt", | ||
""" | ||
val foo = "bar" | ||
""".trimIndent() | ||
) | ||
|
||
build(":ktlintCheck").apply { | ||
assertThat(task(":ktlintMainSourceSetCheck")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
|
||
@Test | ||
internal fun `Should lint without errors when "final-newline" and "no-consecutive-blank-lines" are disabled`() { | ||
projectRoot.buildFile().appendText( | ||
""" | ||
ktlint.disabledRules = ["final-newline", "no-consecutive-blank-lines"] | ||
""".trimIndent() | ||
) | ||
|
||
projectRoot.createSourceFile( | ||
"src/main/kotlin/clean-source.kt", | ||
""" | ||
fun some() { | ||
print("Woohoo!") | ||
} | ||
val foo = "bar" | ||
""".trimIndent() | ||
) | ||
|
||
build(":ktlintCheck").apply { | ||
assertThat(task(":ktlintMainSourceSetCheck")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
|
||
@Test | ||
internal fun `Should fail if ktlint version is lower then 0_34_2 and disabled rules configuration is set`() { | ||
projectRoot.buildFile().appendText( | ||
""" | ||
ktlint.version = "0.33.0" | ||
ktlint.disabledRules = ["final-newline"] | ||
""".trimIndent() | ||
) | ||
|
||
projectRoot.withCleanSources() | ||
|
||
buildAndFail(":ktlintCheck").apply { | ||
assertThat(task(":ktlintMainSourceSetCheck")?.outcome).isEqualTo(TaskOutcome.FAILED) | ||
assertThat(output).contains("Rules disabling is supported since 0.34.2 ktlint version.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters