Android Studio initial project template for new projects
it makes Intellij IDEA's built-in formatter produce 100% ktlint-compatible code.
(inside project's root directory)
ktlint applyToIDEAProject
# or if you want to be compliant with Android Kotlin Style Guide
ktlint --android applyToIDEAProject
Apply to all IDEA projects:
$ ./ktlint applyToIDEA
Or if you want to use android specific code style:
$ ./ktlint --android applyToIDEA
Go to File -> Settings... -> Editor
- General -> Auto Import
- check
Optimize imports on the fly (for current project)
.
- check
- Code Style -> Kotlin
- Set from... -> Predefined style -> Kotlin style guide (Kotlin plugin 1.2.20+).
- open Code Generation tab
- uncheck
Line comment at first column
; - select
Add a space at comment start
.
- uncheck
- open Imports tab
- select
Use single name import
(all of them); - remove
import java.util.*
fromPackages to Use Import with '*'
.
- select
- open Blank Lines tab
- change
Keep Maximum Blank Lines
/In declarations
&In code
to 1 andBefore '}'
to 0.
- change
- (optional but recommended) open Wrapping and Braces tab
- uncheck
Method declaration parameters
/Align when multiline
.
- uncheck
- (optional but recommended) open Tabs and Indents tab
- change
Continuation indent
to the same value asIndent
(4 by default).
- change
- Inspections
- change
Severity
level ofUnused import directive
andRedundant semicolon
toERROR
.
- change