cortinico/ktfmt-gradle

googleStyle trailing commas do not work

Rawa opened this issue ยท 1 comments

Rawa commented

๐Ÿ› Describe the bug

Google style trailing comma does not seem to work with the latest version of this plugin. Also there is no way to configure the option manageTrailingCommas in the ktfmt configuration block.

โš ๏ธ Current behavior

I try to format with latest version using googleStyle and trailing commas are not added as expected.

โœ… Expected behavior

Trailing commas to appear

๐Ÿ’ฃ Steps to reproduce

  • Clone this repo
  • Change example to run googleStyle() instead of kotlinLangStyle()
  • Create a long list in example/src/main/java/Sample.kt
  • Format with ./gradlew ktfmtFormat observe how we get google format but trailing commas are not applied.

I've not spent much time debugging but looking at the related commit:
facebook/ktfmt@fa78077
seems like default of GOOGLE_FORMAT is the following:

  @JvmField
  val GOOGLE_FORMAT = FormattingOptions(style = GOOGLE, blockIndent = 2, continuationIndent = 2, manageTrailingCommas = true)

However the default of the value when creating the options are as follows:

    /**
     * Automatically remove and insert trialing commas.
     *
     * Lists that cannot fit on one line will have trailing commas inserted. Lists that span
     * multiple lines will have them removed. Manually inserted trailing commas cannot be used as a
     * hint to force breaking lists to multiple lines.
     */
    val manageTrailingCommas: Boolean = false,

I can imagine if the formatter is not created from the default value and instead directly through the FormattingOptions one might get this issue.

Yup you're right this was missing.
Fix for it is here #272