Skip to content

Commit

Permalink
Handle parameter --code-style=android_studio in Ktlint CLI identica…
Browse files Browse the repository at this point in the history
…l to deprecated parameter `--android` (#1990)

Closes #1982
  • Loading branch information
paul-dingemans committed May 5, 2023
1 parent e0f7938 commit f408c88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed
* Store path of file containing a lint violation relative to the location of the baseline file itself ([#1962](https://github.com/pinterest/ktlint/issues/1962))
* Handle parameter `--code-style=android_studio` in Ktlint CLI identical to deprecated parameter `--android` ([#1982](https://github.com/pinterest/ktlint/issues/1982))

### Changed
* Separated Baseline functionality out of `ktlint-cli` into separate `ktlint-baseline` module for API consumers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ internal class KtlintCommandLine {
}.applyIf(disabledRules.isNotBlank()) {
logger.debug { "Add editor config override to disable rules: '$disabledRules'" }
plus(*disabledRulesEditorConfigOverrides())
}.applyIf(android) {
logger.debug { "Add editor config override to set code style to 'android'" }
plus(CODE_STYLE_PROPERTY to CodeStyleValue.android)
}.applyIf(android || codeStyle == CodeStyleValue.android || codeStyle == CodeStyleValue.android_studio) {
logger.debug { "Add editor config override to set code style to 'android_studio'" }
plus(CODE_STYLE_PROPERTY to CodeStyleValue.android_studio)
}.applyIf(stdin) {
logger.debug {
"Add editor config override to disable 'filename' rule which can not be used in combination with reading from " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,39 @@ class SimpleCLITest {
.doesNotContainLineMatching(Regex(".*Needless blank line.*"))
}
}

@Nested
inner class `Issue 1983 - Enable android code style` {
@Test
fun `Enable android code style via parameter --android`(
@TempDir
tempDir: Path,
) {
CommandLineTestRunner(tempDir)
.run(
testProjectName = "too-many-empty-lines",
arguments = listOf("--android"),
) {
assertThat(normalOutput).containsLineMatching(
Regex(".*Add editor config override to set code style to 'android_studio'.*"),
)
}
}

@Test
fun `Enable android code style via parameter --code-style=android_studio`(
@TempDir
tempDir: Path,
) {
CommandLineTestRunner(tempDir)
.run(
testProjectName = "too-many-empty-lines",
arguments = listOf("--code-style=android_studio"),
) {
assertThat(normalOutput).containsLineMatching(
Regex(".*Add editor config override to set code style to 'android_studio'.*"),
)
}
}
}
}

0 comments on commit f408c88

Please sign in to comment.