{"id":33234386,"url":"https://facebook.github.io/ktfmt/","last_synced_at":"2025-11-21T12:02:14.404Z","repository":{"id":37850070,"uuid":"218383922","full_name":"facebook/ktfmt","owner":"facebook","description":"A program that reformats Kotlin source code to comply with the common community standard for Kotlin code conventions.","archived":false,"fork":false,"pushed_at":"2025-10-17T22:50:03.000Z","size":6878,"stargazers_count":1079,"open_issues_count":45,"forks_count":88,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-10-30T00:45:26.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://facebook.github.io/ktfmt/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facebook.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-29T21:07:40.000Z","updated_at":"2025-10-27T12:31:17.000Z","dependencies_parsed_at":"2024-04-02T17:26:54.794Z","dependency_job_id":"40f257fd-a5e5-457d-a6a8-c3b3c5116d7e","html_url":"https://github.com/facebook/ktfmt","commit_stats":{"total_commits":573,"total_committers":67,"mean_commits":8.552238805970148,"dds":0.6945898778359512,"last_synced_commit":"9830466327b72879808b0d6266d2cc69ef0197b2"},"previous_names":["facebookincubator/ktfmt"],"tags_count":50,"template":false,"template_full_name":null,"purl":"pkg:github/facebook/ktfmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fktfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fktfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fktfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fktfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebook","download_url":"https://codeload.github.com/facebook/ktfmt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fktfmt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285611836,"owners_count":27201484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-21T02:00:06.175Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-16T18:00:29.930Z","updated_at":"2025-11-21T12:02:14.398Z","avatar_url":"https://github.com/facebook.png","language":"Kotlin","funding_links":[],"categories":["Programming Languages"],"sub_categories":[],"readme":"# ktfmt [![GitHub release](https://img.shields.io/github/release/facebook/ktfmt?sort=semver)](https://github.com/facebook/ktfmt/releases/)   [![Maven Central Version](https://img.shields.io/maven-central/v/com.facebook/ktfmt)](https://central.sonatype.com/artifact/com.facebook/ktfmt)   [![](https://github.com/facebook/ktfmt/workflows/Build%20and%20Test/badge.svg)](https://github.com/facebook/ktfmt/actions/workflows/build_and_test.yml \"GitHub Actions workflow status\")   [![slack](https://img.shields.io/badge/Slack-ktfmt-purple.svg?logo=slack)](https://slack-chats.kotlinlang.org/c/ktfmt)   [![invite](https://img.shields.io/badge/Request%20a%20Slack%20invite-8A2BE2)](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up)   [![issues - ktfmt](https://img.shields.io/github/issues/facebook/ktfmt)](https://github.com/facebook/ktfmt/issues)\n\n`ktfmt` is a program that pretty-prints (formats) Kotlin code, based on\n[google-java-format](https://github.com/google/google-java-format).\n\nThe minimum supported runtime version is JDK 11, released September 2018.\n\n## Demo\n\n|Before Formatting| Formatted by `ktfmt`|\n| ---- | ---- |\n| ![Original](docs/images/before.png) | ![ktfmt](docs/images/ktfmt.png) |\n\nFor comparison, the same code formatted by [`ktlint`](https://github.com/pinterest/ktlint) and\nIntelliJ:\n\n| Formatted by `ktlint`|Formatted by IntelliJ|\n| ------ | --------|\n| ![ktlint](docs/images/ktlint.png) | ![IntelliJ](docs/images/intellij.png) |\n\n## Playground\n\nWe have a [live playground](https://facebook.github.io/ktfmt/) where you can easily see how ktfmt\nwould format your code.\nGive it a try! https://facebook.github.io/ktfmt/\n\n## Using the formatter\n\n### IntelliJ, Android Studio, and other JetBrains IDEs\n\nA [ktfmt IntelliJ plugin](https://plugins.jetbrains.com/plugin/14912-ktfmt) is available from the\nplugin repository.\nTo install it:\n1. Go to your IDE's settings\n2. Select the `Plugins` category\n3. Go to the `Marketplace` tab\n4. Search for the `ktfmt` plugin\n5. Install it\n\nThe plugin will be disabled by default. To enable it in the current project, go to\n`File → Settings... → ktfmt Settings` (or `IntelliJ IDEA → Preferences... → Editor → ktfmt Settings`\non macOS) and check the `Enable ktfmt` checkbox.\nA notification will be presented when you first open a project offering to do this for you.\n\nTo enable it by default in new projects, use\n`File → New Project Settings → Preferences for new Projects → Editor → ktfmt Settings`.\n\nWhen enabled, it will replace the normal `Reformat Code` action, which can be triggered from the\n`Code` menu or with the Ctrl-Alt-L (by default) keyboard shortcut.\n\nTo configure IntelliJ to approximate ktfmt's formatting rules during code editing, you can edit your\nproject's\n[`.editorconfig` file](https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig)\nto include the Kotlin section from one of the files inside [`docs/editorconfig`](docs/editorconfig).\n\n#### Share IntelliJ ktfmt settings\nIn order to share the settings, make sure to commit the file `.idea/ktfmt.xml` into your codebase.\n\n### Installation\n\n#### Homebrew\n\nIf you're a [Homebrew](https://brew.sh) user, you can install\n[ktfmt](https://formulae.brew.sh/formula/ktfmt) via:\n\n```\n$ brew install ktfmt\n```\n\n### from the command-line\n\n[Download the formatter](https://github.com/facebook/ktfmt/releases) and run it with:\n\n```\n$ java -jar /path/to/ktfmt-\u003cVERSION\u003e-with-dependencies.jar [--kotlinlang-style | --google-style] [files...]\n```\n\n`--kotlinlang-style` makes `ktfmt` use a block indent of 4 spaces instead of 2.\nSee below for details.\n\n***Note:***\n*There is no configurability as to the formatter's algorithm for formatting (apart from the\ndifferent styles). This is a deliberate design decision to unify our code formatting on a single\nformat.*\n\n### using Gradle\n\nA [Gradle plugin (ktfmt-gradle)](https://github.com/cortinico/ktfmt-gradle) is available on the\nGradle Plugin Portal. To set it up, just follow the instructions in the\n[How-to-use section](https://github.com/cortinico/ktfmt-gradle#how-to-use-).\n\nAlternatively, you can use [Spotless](https://github.com/diffplug/spotless) with the\n[ktfmt Gradle plugin](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ktfmt).\n\n### using Maven\n\nConsider using [Spotless](https://github.com/diffplug/spotless) with the\n[ktfmt Maven plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven#ktfmt).\n\n### using pre-commit hooks\n\nA [pre-commit hook](https://pre-commit.com/hooks.html) is implemented in\n[language-formatters-pre-commit-hooks](https://github.com/macisamuele/language-formatters-pre-commit-hooks)\n\n## FAQ\n\n### `ktfmt` vs `ktlint` vs IntelliJ\n\n`ktfmt` uses google-java-format's underlying engine, and as such, many items on\n[google-java-format's FAQ](https://github.com/google/google-java-format/wiki/FAQ) apply to `ktfmt`\nas well.\n\nIn particular, here are the principles that we try to adhere to:\n1. `ktfmt` ignores most existing formatting. It respects existing newlines in some places, but in\n  general, its output is deterministic and is independent of the input code.\n2. `ktfmt` exposes no configuration options that govern formatting behavior. See\n  https://github.com/google/google-java-format/wiki/FAQ#i-just-need-to-configure-it-a-bit-differently-how\n  for the rationale.\n   1. For exposed configurations, like `style`, we aim to make sure that those are easily shared\n      across your organization/codebase to avoid\n      [bikeshedding discussions](https://thedecisionlab.com/biases/bikeshedding) about code format.\n\nThese two properties make `ktfmt` a good fit in large Kotlin code bases, where consistency is very\nimportant.\n\nWe created `ktfmt` because at the time `ktlint` and IntelliJ sometimes failed to produce\nnice-looking code that fits in 100 columns, as can be seen in the [Demo](README.md#Demo) section.\n\n### `ktfmt` uses a 2-space indent; why not 4? any way to change that?\n\nTwo reasons -\n1. Many of our projects use a mixture of Kotlin and Java, and we found the back-and-forth in styles\n   to be distracting.\n2. From a pragmatic standpoint, the formatting engine behind google-java-format uses more whitespace\n   and newlines than other formatters. Using an indentation of 4 spaces quickly reaches the maximal\n   column width.\n\nHowever, we do offer an alternative style for projects that absolutely cannot make the move to\n`ktfmt` because of 2-space: the style `--kotlinlang-style` changes block indents to 4-space.\n\n## Developer's Guide\n\n### Setup\n\nOpen the `build.gradle.kts` at the root of the repo in IntelliJ.\nChoose \"Open as a Project\".\n\n### Development\n\n* Currently, we mainly develop by adding tests to `FormatterTest.kt`.\n\n### Building on the Command Line\n\n* Run `./gradlew :ktfmt:shadowJar`\n* Run `java -jar core/build/libs/ktfmt-\u003cVERSION\u003e-with-dependencies.jar`\n\n### Releasing\n\nSee [RELEASING.md](RELEASING.md).\n\n## License\n\nApache License 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/facebook.github.io%2Fktfmt%2F","html_url":"https://awesome.ecosyste.ms/projects/facebook.github.io%2Fktfmt%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/facebook.github.io%2Fktfmt%2F/lists"}