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`

Closes #1982
  • Loading branch information
paul-dingemans committed May 5, 2023
1 parent 8582325 commit c083858
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ 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))
* Print absolute path of file in lint violations when flag "--relative" is not specified in Ktlint CLI ([#1963](https://github.com/pinterest/ktlint/issues/1963))
* Print absolute path of file in lint violations when flag "--relative" is not specified in Ktlint CLI ([#1963](https://github.com/pinterest/ktlint/issues/1963))
* 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 @@ -260,9 +260,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 c083858

Please sign in to comment.