Skip to content

Commit

Permalink
parseImportsLayout: trim spaces in entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfa committed Jan 10, 2023
1 parent 480dd87 commit f12ab85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed

* Trim spaces in the `.editorconfig` property `ij_kotlin_imports_layout`'s entries ([#1770](https://github.com/pinterest/ktlint/pull/1770))

### Changed

## [0.48.1] - 2023-01-03
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal const val ALIAS_CHAR = "^"
* Adapted from https://github.com/JetBrains/intellij-kotlin/blob/73b5a484198f02518c9ece2fb453d27cead680fb/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinPackageEntryTableAccessor.kt#L27-L43
*/
internal fun parseImportsLayout(importsLayout: String): List<PatternEntry> {
val importsList = importsLayout.split(",").onEach { it.trim() }
val importsList = importsLayout.split(",").map { it.trim() }

if (importsList.first() == BLANK_LINE_CHAR || importsList.last() == BLANK_LINE_CHAR) {
throw IllegalArgumentException("Blank lines are not supported in the beginning or end of import list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ class ImportLayoutParserTest {

assertThat(actual).isEqualTo(expected)
}

@Test
fun `trims spaces in entries`() {
assertThat(parseImportsLayout("android.**,|,org.junit.**,|,^android.**,*,kotlin.io.Closeable.*,^"))
.isEqualTo(parseImportsLayout("android.**, |, org.junit.**, |, ^android.**, *, kotlin.io.Closeable.*, ^"))
}
}

0 comments on commit f12ab85

Please # to comment.