Skip to content

Commit

Permalink
Make style definitions even more explicit
Browse files Browse the repository at this point in the history
Reviewed By: strulovich

Differential Revision: D58396201

fbshipit-source-id: 3355f52a1ee314923839dad65775b514874dc168
  • Loading branch information
Nivaldo Bondança authored and facebook-github-bot committed Jun 11, 2024
1 parent 96a7b1e commit 520706e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -58,6 +64,7 @@ object Formatter {
FormattingOptions(
blockIndent = 4,
continuationIndent = 4,
manageTrailingCommas = false,
)

private val MINIMUM_KOTLIN_VERSION = KotlinVersion(1, 4)
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 520706e

Please sign in to comment.