You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**A command-line tool for formatting Kotlin source code files**, implemented as a wrapper around [ktfmt](https://github.com/facebook/ktfmt/tree/main).
6
+
This project provides:
7
+
-**A command-line tool for formatting Kotlin source code files**, implemented as a wrapper around [ktfmt](https://github.com/facebook/ktfmt/tree/main).
8
+
-**An IntelliJ idea plugin** for formatting Kotlin source code files.
7
9
8
10
It can be used to automate code formatting, ensuring a clean and consistent codebase, while integrating seamlessly into development workflows.
9
11
10
-
The tool can:
12
+
The CLI tool can:
11
13
12
14
-**Format files and directories**: Apply consistent formatting to files, directories, or standard input.
13
15
-**Integrate with Git workflows**:
14
16
-**Pre-commit**: Format staged files before committing.
15
17
-**Pre-push**: Check committed files before pushing.
16
18
17
-
## Usage
19
+
The plugin can format Kotlin files on save, or on the format action.
20
+
21
+
## CLI Usage
18
22
19
23
```bash
20
24
kotlin-format [OPTIONS] [FILES...]
@@ -70,3 +74,21 @@ A fat JAR of the CLI is available on [Maven Central](https://repo1.maven.org/mav
A properties file can be used to configure the plugin for each project. The properties file should be named `kotlin-formatter.properties` and placed in the `.idea` of the project. The following properties are supported:
81
+
82
+
-`kotlin-formatter.enabled`: Enable or disable the plugin, disabled by default.
83
+
-`kotlin-formatter.script-path`: Path to the Kotlin Formatter script. The `kotlin-format` library in this project is used if this is not specified.
84
+
85
+
Example:
86
+
```properties
87
+
kotlin-formatter.enabled=true
88
+
kotlin-formatter.script-path=bin/kotlin-format
89
+
```
90
+
91
+
Changes to these config require an IDE restart to take effect.
92
+
93
+
To enable formatting of files on save, navigate to "Settings" > "Tools" > Actions on Save", activate the "Reformat code" checkbox, and ensure that the "Kotlin" file type is selected.
94
+
Make sure "Optimize imports" is NOT enabled for the "Kotlin" file type.
0 commit comments