https://github.com/levelrin/kotlin-stylerin
An alternative formatter for Kotlin code.
https://github.com/levelrin/kotlin-stylerin
formatter kotlin
Last synced: 5 months ago
JSON representation
An alternative formatter for Kotlin code.
- Host: GitHub
- URL: https://github.com/levelrin/kotlin-stylerin
- Owner: levelrin
- License: mit
- Created: 2025-02-27T14:58:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-19T11:51:38.000Z (about 1 year ago)
- Last Synced: 2025-05-19T12:46:20.159Z (about 1 year ago)
- Topics: formatter, kotlin
- Language: Java
- Homepage:
- Size: 254 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/levelrin/kotlin-stylerin/actions/workflows/build.yml?query=branch%3Amain)
[](https://codecov.io/gh/levelrin/kotlin-stylerin)
[](https://github.com/levelrin/kotlin-stylerin)
[](https://github.com/levelrin/kotlin-stylerin/blob/main/LICENSE)
## About
It's a code formatter for [Kotlin](https://kotlinlang.org/).
Yes, we already have a formatter, such as [ktfmt](https://facebook.github.io/ktfmt/), but it's not good enough.
For example, we have the following code:
```kt
fun main() {
val doll = RussianDoll("Rin",RussianDoll("Revomin",RussianDoll("Ian")))
doll.unwrap()
}
class RussianDoll(private val name: String, private val child: RussianDoll? = null) {
fun child(): RussianDoll? {return child}
fun unwrap() {
println(name)
child?.unwrap()
}
}
```
`ktfmt` formats the code like this by default:
```kt
fun main() {
val doll = RussianDoll("Rin", RussianDoll("Revomin", RussianDoll("Ian")))
doll.unwrap()
}
```
Our formatter formats the code like this:
```kt
fun main() {
val doll = RussianDoll(
"Rin",
RussianDoll(
"Revomin",
RussianDoll("Ian")
)
)
doll.unwrap()
}
```
Our format shows the composition better.
## Quick Start
Please install Java 11+ if you haven't already.
1. [Download](https://github.com/levelrin/kotlin-stylerin/releases) the zip file that matches with your Java version and unzip it to get the jar file.
2. Run the command `java -jar kotlin-stylerin-{app-version}-{java-version}.jar path/to/target.kt`
## Command Options
```
usage: java -jar kotlin-stylerin-{app-version}-{java-version}.jar [options]
-h,--help Show help messages.
-q,--quiet Do not print debug logs.
-r,--recursive Format files in the directory recursively.
-v,--version Print the version.
```
## Disclaimer
Not all [grammar rules](https://github.com/antlr/grammars-v4/blob/master/kotlin/kotlin/KotlinParser.g4) are supported yet.
Please always be ready to recover the file and use our formatter at your own risk.
If you find a bug or have a suggestion, please create a new [issue](https://github.com/levelrin/kotlin-stylerin/issues).