Skip to content

Commit 520706e

Browse files
Nivaldo Bondançafacebook-github-bot
Nivaldo Bondança
authored andcommitted
Make style definitions even more explicit
Reviewed By: strulovich Differential Revision: D58396201 fbshipit-source-id: 3355f52a1ee314923839dad65775b514874dc168
1 parent 96a7b1e commit 520706e

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1212
### Changed
1313
- Preserves blank spaces between when clauses (https://github.com/facebook/ktfmt/issues/342)
1414
- Named the default style as `Formatter.META_FORMAT` / `--meta-style`
15+
- `FormattingOptions` constructor parameters order was changed
1516

1617
### Fixed
1718
- Compilation issues with online formatter (https://github.com/facebook/ktfmt/commit/8605080cb0aadb7eaba20f3b469d6ddafe32c941)

core/src/main/java/com/facebook/ktfmt/format/Formatter.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
4242

4343
object Formatter {
4444

45-
@JvmField val META_FORMAT = FormattingOptions()
45+
@JvmField
46+
val META_FORMAT =
47+
FormattingOptions(
48+
blockIndent = 2,
49+
continuationIndent = 4,
50+
manageTrailingCommas = false,
51+
)
4652

4753
@JvmField
4854
val GOOGLE_FORMAT =
@@ -58,6 +64,7 @@ object Formatter {
5864
FormattingOptions(
5965
blockIndent = 4,
6066
continuationIndent = 4,
67+
manageTrailingCommas = false,
6168
)
6269

6370
private val MINIMUM_KOTLIN_VERSION = KotlinVersion(1, 4)

core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data class FormattingOptions(
3030
* }
3131
* ```
3232
*/
33-
val blockIndent: Int = 2,
33+
val blockIndent: Int,
3434

3535
/**
3636
* continuationIndent is the size of the indent used when a line is broken because it's too
@@ -42,7 +42,16 @@ data class FormattingOptions(
4242
* 1)
4343
* ```
4444
*/
45-
val continuationIndent: Int = 4,
45+
val continuationIndent: Int,
46+
47+
/**
48+
* Automatically remove and insert trialing commas.
49+
*
50+
* Lists that cannot fit on one line will have trailing commas inserted. Lists that span
51+
* multiple lines will have them removed. Manually inserted trailing commas cannot be used as a
52+
* hint to force breaking lists to multiple lines.
53+
*/
54+
val manageTrailingCommas: Boolean,
4655

4756
/** Whether ktfmt should remove imports that are not used. */
4857
val removeUnusedImports: Boolean = true,
@@ -52,15 +61,6 @@ data class FormattingOptions(
5261
* newline) decisions
5362
*/
5463
val debuggingPrintOpsAfterFormatting: Boolean = false,
55-
56-
/**
57-
* Automatically remove and insert trialing commas.
58-
*
59-
* Lists that cannot fit on one line will have trailing commas inserted. Lists that span
60-
* multiple lines will have them removed. Manually inserted trailing commas cannot be used as a
61-
* hint to force breaking lists to multiple lines.
62-
*/
63-
val manageTrailingCommas: Boolean = false,
6464
) {
6565
companion object {
6666
const val DEFAULT_MAX_WIDTH: Int = 100

core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -5384,7 +5384,14 @@ class FormatterTest {
53845384
|"""
53855385
.trimMargin()
53865386
assertThatFormatting(code)
5387-
.withOptions(FormattingOptions(maxWidth = 35, blockIndent = 4, continuationIndent = 4))
5387+
.withOptions(
5388+
FormattingOptions(
5389+
maxWidth = 35,
5390+
blockIndent = 4,
5391+
continuationIndent = 4,
5392+
manageTrailingCommas = false,
5393+
),
5394+
)
53885395
.isEqualTo(code)
53895396
}
53905397

0 commit comments

Comments
 (0)