Skip to content

Commit

Permalink
Fix false positive when .editorconfig property `ij_kotlin_imports_l…
Browse files Browse the repository at this point in the history
…ayout` contains a `|` but no import exists that match any pattern before the first `|`

Closes #1845
  • Loading branch information
paul-dingemans committed Mar 13, 2023
1 parent 7f323be commit aa8bd42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Previously the default value for `.editorconfig` property `max_line_length` was
* Fix false positive when multiple KDOCs exists between a declaration and another annotated declaration `spacing-between-declarations-with-annotations` ([#1802](https://github.com/pinterest/ktlint/issues/1802))
* Fix false positive when a single line statement containing a block having exactly the maximum line length is preceded by a blank line `wrapping` ([#1808](https://github.com/pinterest/ktlint/issues/1808))
* Fix false positive when a single line contains multiple dot qualified expressions and/or safe expressions `indent` ([#1830](https://github.com/pinterest/ktlint/issues/1830))
* When `.editorconfig` property `ij_kotlin_imports_layout` contains a `|` but no import exists that match any pattern before the first `|` then do not report a violation nor insert a blank line `import-ordering` ([#1845](https://github.com/pinterest/ktlint/issues/1845))

### Changed
* Wrap the parameters of a function literal containing a multiline parameter list (only in `ktlint_official` code style) `parameter-list-wrapping` ([#1681](https://github.com/pinterest/ktlint/issues/1681)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class ImportOrderingRule :
break
}
}
if (hasBlankLines) {
if (hasBlankLines && prev != null) {
sortedImportsWithSpaces += PsiWhiteSpaceImpl("\n\n")
}
sortedImportsWithSpaces += current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,24 @@ class ImportOrderingRuleCustomTest {
.withEditorConfigOverride(IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY to "kotlin.io.Closeable.*,kotlin.**,*")
.isFormattedAs(formattedCode)
}

@Test
fun `Issue 1845 - Given a list of pattern entries including a '|' pattern but no import exists that match any pattern before the first '|'`() {
val code =
"""
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Objects
object TestData {
fun loadString(dataset: String): String {
val path = Paths.get(Objects.requireNonNull(TestData::class.java.getResource(dataset)).toURI())
return String(Files.readAllBytes(path))
}
}
""".trimIndent()
importOrderingRuleAssertThat(code)
.withEditorConfigOverride(IJ_KOTLIN_IMPORTS_LAYOUT_PROPERTY to "*, |, javax.**, java.**, |, kotlinx.**, kotlin.**")
.hasNoLintViolations()
}
}

0 comments on commit aa8bd42

Please sign in to comment.