diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b438fb..dc7a079d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,4 +16,5 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). - Compilation issues with online formatter (https://github.com/facebook/ktfmt/commit/8605080cb0aadb7eaba20f3b469d6ddafe32c941) ### Removed +- **Deleted `Formatter.DROPBOX_FORMAT` / `--dropbox-style` (BREAKING CHANGE)** - Deleted `FormattingOptions.Style` enum diff --git a/README.md b/README.md index 264f2de9..d159880a 100644 --- a/README.md +++ b/README.md @@ -70,14 +70,15 @@ $ brew install ktfmt and run it with: ``` -java -jar /path/to/ktfmt--jar-with-dependencies.jar [--dropbox-style] [files...] +java -jar /path/to/ktfmt--jar-with-dependencies.jar [--kotlinlang-style | --google-style] [files...] ``` -`--dropbox-style` makes `ktfmt` use a block indent of 4 spaces instead of 2. See below for details. +`--kotlinlang-style` makes `ktfmt` use a block indent of 4 spaces instead of 2. See below for details. -***Note:*** *There is no configurability as to the formatter's algorithm for -formatting (apart from `--dropbox-style`). This is a deliberate design decision to unify our code -formatting on a single format.* +***Note:*** +*There is no configurability as to the formatter's algorithm for formatting (apart from the +different styles). This is a deliberate design decision to unify our code formatting on a single +format.* ### using Gradle @@ -113,7 +114,7 @@ Two reasons - 1. Many of our projects use a mixture of Kotlin and Java, and we found the back-and-forth in styles to be distracting. 2. From a pragmatic standpoint, the formatting engine behind google-java-format uses more whitespace and newlines than other formatters. Using an indentation of 4 spaces quickly reaches the maximal column width. -However, we do offer an escape-hatch for projects that absolutely cannot make the move to `ktfmt` because of 2-space: the `--dropbox-style` flag changes block indents to 4-space. +However, we do offer an alternative style for projects that absolutely cannot make the move to `ktfmt` because of 2-space: the style `--kotlinlang-style` changes block indents to 4-space. ## Developer's Guide diff --git a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt index 2b8dde1a..c305bf15 100644 --- a/core/src/main/java/com/facebook/ktfmt/cli/Main.kt +++ b/core/src/main/java/com/facebook/ktfmt/cli/Main.kt @@ -37,7 +37,7 @@ private const val EXIT_CODE_SUCCESS = 0 private val USAGE = """ - Usage: ktfmt [--dropbox-style | --google-style | --kotlinlang-style] [--dry-run] [--set-exit-if-changed] [--stdin-name=] [--do-not-remove-unused-imports] File1.kt File2.kt ... + Usage: ktfmt [--google-style | --kotlinlang-style] [--dry-run] [--set-exit-if-changed] [--stdin-name=] [--do-not-remove-unused-imports] File1.kt File2.kt ... Or: ktfmt @file """ .trimIndent() diff --git a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt index b443afea..041cb407 100644 --- a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt +++ b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt @@ -59,7 +59,6 @@ data class ParsedArgs( for (arg in args) { when { - arg == "--dropbox-style" -> formattingOptions = Formatter.DROPBOX_FORMAT arg == "--google-style" -> formattingOptions = Formatter.GOOGLE_FORMAT arg == "--kotlinlang-style" -> formattingOptions = Formatter.KOTLINLANG_FORMAT arg == "--dry-run" || arg == "-n" -> dryRun = true 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 2198d3f4..9f29e0f0 100644 --- a/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt +++ b/core/src/main/java/com/facebook/ktfmt/format/Formatter.kt @@ -58,13 +58,6 @@ object Formatter { continuationIndent = 4, ) - @JvmField - val DROPBOX_FORMAT = - FormattingOptions( - blockIndent = 4, - continuationIndent = 4, - ) - private val MINIMUM_KOTLIN_VERSION = KotlinVersion(1, 4) /** diff --git a/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt b/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt index 33d78cdb..1158b7e8 100644 --- a/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt @@ -225,7 +225,7 @@ class MainTest { } @Test - fun `dropbox-style is passed to formatter (file)`() { + fun `kotlinlang-style is passed to formatter (file)`() { val code = """fun f() { for (child in @@ -241,14 +241,14 @@ class MainTest { emptyInput, PrintStream(out), PrintStream(err), - arrayOf("--dropbox-style", fooBar.toString())) + arrayOf("--kotlinlang-style", fooBar.toString())) .run() assertThat(fooBar.readText()).isEqualTo(code) } @Test - fun `dropbox-style is passed to formatter (stdin)`() { + fun `kotlinlang-style is passed to formatter (stdin)`() { val code = """fun f() { |for (child in @@ -271,7 +271,7 @@ class MainTest { code.byteInputStream(), PrintStream(out), PrintStream(err), - arrayOf("--dropbox-style", "-")) + arrayOf("--kotlinlang-style", "-")) .run() assertThat(out.toString(UTF_8)).isEqualTo(formatted) diff --git a/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt b/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt index ae5461bb..2e27f3f2 100644 --- a/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt @@ -62,8 +62,8 @@ class ParsedArgsTest { @Test fun `parseOptions recognizes --dropbox-style`() { - val parsed = assertSucceeds(ParsedArgs.parseOptions(arrayOf("--dropbox-style", "foo.kt"))) - assertThat(parsed.formattingOptions).isEqualTo(Formatter.DROPBOX_FORMAT) + val parsed = assertSucceeds(ParsedArgs.parseOptions(arrayOf("--kotlinlang-style", "foo.kt"))) + assertThat(parsed.formattingOptions).isEqualTo(Formatter.KOTLINLANG_FORMAT) } @Test @@ -177,12 +177,12 @@ class ParsedArgsTest { @Test fun `last style in args wins`() { val testResult = - ParsedArgs.parseOptions(arrayOf("--google-style", "--dropbox-style", "File.kt")) + ParsedArgs.parseOptions(arrayOf("--google-style", "--kotlinlang-style", "File.kt")) assertThat(testResult) .isEqualTo( parseResultOk( fileNames = listOf("File.kt"), - formattingOptions = Formatter.DROPBOX_FORMAT, + formattingOptions = Formatter.KOTLINLANG_FORMAT, )) } diff --git a/ktfmt_idea_plugin/src/main/java/com/facebook/ktfmt/intellij/UiFormatterStyle.java b/ktfmt_idea_plugin/src/main/java/com/facebook/ktfmt/intellij/UiFormatterStyle.java index 81473972..243aaff5 100644 --- a/ktfmt_idea_plugin/src/main/java/com/facebook/ktfmt/intellij/UiFormatterStyle.java +++ b/ktfmt_idea_plugin/src/main/java/com/facebook/ktfmt/intellij/UiFormatterStyle.java @@ -16,7 +16,6 @@ package com.facebook.ktfmt.intellij; -import static com.facebook.ktfmt.format.Formatter.DROPBOX_FORMAT; import static com.facebook.ktfmt.format.Formatter.GOOGLE_FORMAT; import static com.facebook.ktfmt.format.Formatter.KOTLINLANG_FORMAT; @@ -25,7 +24,6 @@ /** Configuration options for the formatting style. */ enum UiFormatterStyle { DEFAULT("Default", new FormattingOptions()), - DROPBOX("Dropbox", DROPBOX_FORMAT), GOOGLE("Google (internal)", GOOGLE_FORMAT), KOTLINLANG("Kotlinlang", KOTLINLANG_FORMAT);