Skip to content

Commit

Permalink
Delete FormattingOptions.Style enum
Browse files Browse the repository at this point in the history
Summary: This is not really necessary with `FormattingOptions` being a data class.

Reviewed By: cortinico

Differential Revision: D58394978

fbshipit-source-id: 00c877a8db3b166c0d6ba834c4079d7fa0897af9
  • Loading branch information
Nivaldo Bondança authored and facebook-github-bot committed Jun 11, 2024
1 parent f9d4d25 commit 7edeff1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to the ktfmt project (starting on v0.51) should be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [Unreleased]

### Added
- Created CHANGELOG.md

### Changed
- Preserves blank spaces between when clauses (https://github.com/facebook/ktfmt/issues/342)

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

### Removed
- Deleted `FormattingOptions.Style` enum
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We actively welcome your pull requests.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
7. If applicable add relevant change information to the changelog

Note that pull requests are imported into Facebook's internal repository and code is
formatted as part of that process (using ktfmt!). It's not necessary for PRs to stick
Expand Down
19 changes: 14 additions & 5 deletions core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.facebook.ktfmt.format

import com.facebook.ktfmt.debughelpers.printOps
import com.facebook.ktfmt.format.FormattingOptions.Style.DROPBOX
import com.facebook.ktfmt.format.FormattingOptions.Style.GOOGLE
import com.facebook.ktfmt.format.RedundantElementManager.addRedundantElements
import com.facebook.ktfmt.format.RedundantElementManager.dropRedundantElements
import com.facebook.ktfmt.format.WhitespaceTombstones.indexOfWhitespaceTombstone
Expand Down Expand Up @@ -47,14 +45,25 @@ object Formatter {
@JvmField
val GOOGLE_FORMAT =
FormattingOptions(
style = GOOGLE, blockIndent = 2, continuationIndent = 2, manageTrailingCommas = true)
blockIndent = 2,
continuationIndent = 2,
manageTrailingCommas = true,
)

/** A format that attempts to reflect https://kotlinlang.org/docs/coding-conventions.html. */
@JvmField
val KOTLINLANG_FORMAT = FormattingOptions(style = GOOGLE, blockIndent = 4, continuationIndent = 4)
val KOTLINLANG_FORMAT =
FormattingOptions(
blockIndent = 4,
continuationIndent = 4,
)

@JvmField
val DROPBOX_FORMAT = FormattingOptions(style = DROPBOX, blockIndent = 4, continuationIndent = 4)
val DROPBOX_FORMAT =
FormattingOptions(
blockIndent = 4,
continuationIndent = 4,
)

private val MINIMUM_KOTLIN_VERSION = KotlinVersion(1, 4)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.facebook.ktfmt.format

data class FormattingOptions(
val style: Style = Style.FACEBOOK,

/** ktfmt breaks lines longer than maxWidth. */
val maxWidth: Int = DEFAULT_MAX_WIDTH,

Expand Down Expand Up @@ -64,14 +62,7 @@ data class FormattingOptions(
*/
val manageTrailingCommas: Boolean = false,
) {

companion object {
const val DEFAULT_MAX_WIDTH: Int = 100
}

enum class Style {
FACEBOOK,
DROPBOX,
GOOGLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class KotlinInputAstVisitor(
private val builder: OpsBuilder
) : KtTreeVisitorVoid() {

private val isGoogleStyle = options.style == FormattingOptions.Style.GOOGLE
private val isGoogleStyle = options.manageTrailingCommas

/** Standard indentation for a block */
private val blockIndent: Indent.Const = Indent.Const.make(options.blockIndent, 1)
Expand Down

0 comments on commit 7edeff1

Please sign in to comment.