Skip to content

Commit

Permalink
Ignore backticks when ordering imports. Fixes pinterest#1106
Browse files Browse the repository at this point in the history
  • Loading branch information
shashachu committed Jun 29, 2021
1 parent 89db7a7 commit 67fe94e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix false positive with 'by lazy {}' (`indent`) ([#1162](https://github.com/pinterest/ktlint/issues/1162))
- Fix false positive with value argument list has lambda (`indent`) ([#764](https://github.com/pinterest/ktlint/issues/764))
- Fix false positive in lambda in dot qualified expression (`argument-list-wrapping`) ([#1112](https://github.com/pinterest/ktlint/issues/1112))
- Ignore backticks in imports for ordering purposes (`import-ordering`) ([#1106](https://github.com/pinterest/ktlint/issues/1106))
### Changed
- Updated to dokka 1.4.32 ([#1148](https://github.com/pinterest/ktlint/pull/1148))
- Updated Kotlin to 1.5.20 version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ImportSorter(
importPath1,
importPath2,
{ import -> findImportIndex(import) },
{ import -> import.toString() }
{ import -> import.toString().replace("`", "") }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,29 @@ class ImportOrderingRuleAsciiTest {
).isEqualTo(formattedImports)
}

@Test
fun `backticks should be ignored in imports`() {
val imports =
"""
import org.mockito.Mockito.`when`
import org.mockito.Mockito.verify
""".trimIndent()

val formattedImports =
"""
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
""".trimIndent()
val testFile = writeAsciiImportsOrderingConfig()

assertThat(
rule.lint(testFile, imports)
).isEqualTo(expectedErrors())
assertThat(
rule.format(testFile, imports)
).isEqualTo(formattedImports)
}

private fun writeAsciiImportsOrderingConfig() = editorConfigTestRule
.writeToEditorConfig(
mapOf(
Expand Down

0 comments on commit 67fe94e

Please # to comment.