From 7edeff14c3738427e53427eb6e39675dc30d1d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Tue, 11 Jun 2024 11:33:34 -0700 Subject: [PATCH] Delete FormattingOptions.Style enum Summary: This is not really necessary with `FormattingOptions` being a data class. Reviewed By: cortinico Differential Revision: D58394978 fbshipit-source-id: 00c877a8db3b166c0d6ba834c4079d7fa0897af9 --- CHANGELOG.md | 19 +++++++++++++++++++ CONTRIBUTING.md | 1 + .../com/facebook/ktfmt/format/Formatter.kt | 19 ++++++++++++++----- .../ktfmt/format/FormattingOptions.kt | 9 --------- .../ktfmt/format/KotlinInputAstVisitor.kt | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..27b438fb --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c59ca9f..afd3f568 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 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 c02f51a3..2198d3f4 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt @@ -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 @@ -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) 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 fb82682d..578d3482 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/FormattingOptions.kt @@ -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, @@ -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 - } } diff --git a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt index 608af596..211feaba 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt @@ -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)