Skip to content

Commit

Permalink
Deleted Dropbox style
Browse files Browse the repository at this point in the history
Summary:
This one is the same as KotlinLang and is not currently being used.

Also addresses this here:
#172

Reviewed By: strulovich

Differential Revision: D58395587

fbshipit-source-id: 1b64bdd0822ae1aebfd5c6808e2da825c6c98a2a
  • Loading branch information
Nivaldo Bondança authored and facebook-github-bot committed Jun 11, 2024
1 parent 88c4961 commit 4a393bb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ $ brew install ktfmt
and run it with:

```
java -jar /path/to/ktfmt-<VERSION>-jar-with-dependencies.jar [--dropbox-style] [files...]
java -jar /path/to/ktfmt-<VERSION>-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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/facebook/ktfmt/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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=<name>] [--do-not-remove-unused-imports] File1.kt File2.kt ...
Usage: ktfmt [--google-style | --kotlinlang-style] [--dry-run] [--set-exit-if-changed] [--stdin-name=<name>] [--do-not-remove-unused-imports] File1.kt File2.kt ...
Or: ktfmt @file
"""
.trimIndent()
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/com/facebook/ktfmt/format/Formatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/**
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/com/facebook/ktfmt/cli/ParsedArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down

0 comments on commit 4a393bb

Please sign in to comment.