Skip to content

Commit

Permalink
Simple code cleanup
Browse files Browse the repository at this point in the history
Reviewed By: cortinico

Differential Revision: D58254727

fbshipit-source-id: e017dacc602ae0999395be27e4bb7d93a671a9d7
  • Loading branch information
Nivaldo Bondança authored and facebook-github-bot committed Jun 7, 2024
1 parent 7d23e59 commit 6cc7efb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
12 changes: 7 additions & 5 deletions core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ data class ParsedArgs(
companion object {

fun processArgs(args: Array<String>): ParseResult {
if (args.size == 1 && args[0].startsWith("@")) {
return parseOptions(File(args[0].substring(1)).readLines(UTF_8).toTypedArray())
} else {
return parseOptions(args)
}
val arguments =
if (args.size == 1 && args[0].startsWith("@")) {
File(args[0].substring(1)).readLines(UTF_8).toTypedArray()
} else {
args
}
return parseOptions(arguments)
}

/** parseOptions parses command-line arguments passed to ktfmt. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class KDocFormattingOptions(
/**
* Limit comment to be at most [maxCommentWidth] characters even if more would fit on the line.
*/
var maxCommentWidth: Int = min(maxLineWidth, 72)
var maxCommentWidth: Int = min(maxLineWidth, 72),
) {
/** Whether to collapse multi-line comments that would fit on a single line into a single line. */
var collapseSingleLine: Boolean = true
Expand Down
5 changes: 2 additions & 3 deletions core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class ParsedArgsTest {
@Test
fun `last style in args wins`() {
val testResult =
ParsedArgs.parseOptions(arrayOf<String>("--google-style", "--dropbox-style", "File.kt"))
ParsedArgs.parseOptions(arrayOf("--google-style", "--dropbox-style", "File.kt"))
assertThat(testResult)
.isEqualTo(
parseResultOk(
Expand All @@ -176,8 +176,7 @@ class ParsedArgsTest {

@Test
fun `error when parsing multiple args and one is unknown`() {
val testResult =
ParsedArgs.parseOptions(arrayOf<String>("@unknown", "--google-style", "File.kt"))
val testResult = ParsedArgs.parseOptions(arrayOf("@unknown", "--google-style", "File.kt"))
assertThat(testResult).isEqualTo(ParseResult.Error("Unexpected option: @unknown"))
}

Expand Down

0 comments on commit 6cc7efb

Please sign in to comment.