Skip to content

Commit

Permalink
Solution for ktfmt not processing .kts files
Browse files Browse the repository at this point in the history
Summary:
This solution will enable ktfmt to also process files with .kts extension

This fixes #224

Reviewed By: cgrushko

Differential Revision: D29586045

fbshipit-source-id: 2a7111ef6968d0d90c8a8cbcc0ba227f1afa318d
  • Loading branch information
Ilan Goldenstein authored and facebook-github-bot committed Jul 13, 2021
1 parent 1335001 commit 6ae31dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/com/facebook/ktfmt/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ fun expandArgsToFileNames(args: List<String>): List<File> {
if (arg == "-") {
error("Error: '-', which causes ktfmt to read from stdin, should not be mixed with file name")
}
result.addAll(File(arg).walkTopDown().filter { it.isFile && it.extension == "kt" })
result.addAll(
File(arg).walkTopDown().filter {
it.isFile && (it.extension == "kt" || it.extension == "kts")
})
}
return result
}
21 changes: 21 additions & 0 deletions core/src/test/java/com/facebook/ktfmt/MainKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,25 @@ class MainKtTest {

assertThat(output.toString("UTF-8")).isEqualTo(code)
}

@Test
fun `expandArgsToFileNames - resolves 'kt' and 'kts' filenames only (recursively)`() {
val f1 = root.resolve("1.kt")
val f2 = root.resolve("2.kt")
val f3 = root.resolve("3")
val f4 = root.resolve("4.dummyext")
val f5 = root.resolve("5.kts")

val dir = root.resolve("foo")
dir.mkdirs()
val f6 = root.resolve("foo/1.kt")
val f7 = root.resolve("foo/2.kts")
val f8 = root.resolve("foo/3.dummyext")
val files = listOf(f1, f2, f3, f4, f5, f6, f7, f8)
for (f in files) {
f.createNewFile()
}
assertThat(expandArgsToFileNames(files.map { it.toString() }))
.containsExactly(f1, f2, f5, f6, f7)
}
}

0 comments on commit 6ae31dc

Please sign in to comment.