diff --git a/CHANGELOG.md b/CHANGELOG.md index c7acfee1..12caca73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Changed - Preserves blank spaces between when clauses (https://github.com/facebook/ktfmt/issues/342) - Named the default style as `Formatter.META_FORMAT` / `--meta-style` +- `FormattingOptions` constructor parameters order was changed ### Fixed - Compilation issues with online formatter (https://github.com/facebook/ktfmt/commit/8605080cb0aadb7eaba20f3b469d6ddafe32c941) diff --git a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt index a8b3560e..951f1bc5 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt @@ -42,7 +42,13 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset object Formatter { - @JvmField val META_FORMAT = FormattingOptions() + @JvmField + val META_FORMAT = + FormattingOptions( + blockIndent = 2, + continuationIndent = 4, + manageTrailingCommas = false, + ) @JvmField val GOOGLE_FORMAT = @@ -58,6 +64,7 @@ object Formatter { FormattingOptions( blockIndent = 4, continuationIndent = 4, + manageTrailingCommas = false, ) private val MINIMUM_KOTLIN_VERSION = KotlinVersion(1, 4) diff --git a/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt b/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt index 578d3482..aa246d7b 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt @@ -30,7 +30,7 @@ data class FormattingOptions( * } * ``` */ - val blockIndent: Int = 2, + val blockIndent: Int, /** * continuationIndent is the size of the indent used when a line is broken because it's too @@ -42,7 +42,16 @@ data class FormattingOptions( * 1) * ``` */ - val continuationIndent: Int = 4, + val continuationIndent: Int, + + /** + * 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, /** Whether ktfmt should remove imports that are not used. */ val removeUnusedImports: Boolean = true, @@ -52,15 +61,6 @@ data class FormattingOptions( * newline) decisions */ val debuggingPrintOpsAfterFormatting: Boolean = false, - - /** - * 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, ) { companion object { const val DEFAULT_MAX_WIDTH: Int = 100 diff --git a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt index c54b564c..efe54d7c 100644 --- a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt @@ -5384,7 +5384,14 @@ class FormatterTest { |""" .trimMargin() assertThatFormatting(code) - .withOptions(FormattingOptions(maxWidth = 35, blockIndent = 4, continuationIndent = 4)) + .withOptions( + FormattingOptions( + maxWidth = 35, + blockIndent = 4, + continuationIndent = 4, + manageTrailingCommas = false, + ), + ) .isEqualTo(code) }