I've started to use Koltin heavily and struggling a bit with code formatting.
Although there is an official coding conventions guide, but I wonder if there is any public available styleguide settings for IntelliJ (such as google codestyle for Java) which you can grab/import and use?
In Kotlin coding conventions, it's recommended to use a single indent in cases where the long continuation indent has been forced before. In practice, quite a bit of code is affected, so this can be considered a major code style update.
Naming. If a source file contains only a single top-level class, the file name should reflect the case-sensitive name plus the . kt extension. Otherwise, if a source file contains multiple top-level declarations, choose a name that describes the contents of the file, apply PascalCase, and append the .
Single-line comments starts with two forward slashes ( // ). Any text between // and the end of the line is ignored by Kotlin (will not be executed).
There's no need to grab/import them they are built into IntelliJ IDEA's Kotlin language support plugin.
You can reformat Kotlin source code just like you would code written in Java or other supported languages.
From IntelliJ IDEA 2016.2 Help :: Reformatting Source Code:
Basics
IntelliJ IDEA lets you reformat source code to meet the requirements of your code style. IntelliJ IDEA will lay out spacing, indents, keywords etc. Reformatting can apply to the selected text, entire file, or entire project.
It is also possible to apply reformatting to the parts of the source code only, using the formatting markers.
Reformatting code
To reformat code for a directory, follow these steps:
- In the Project tool window, select a module or directory you want to apply your reformatting to.
From the main menu, select Code | Reformat Code or press
Ctrl+Alt+L
.Alternatively, in the Project tool window, right-click the directory and from the context menu, select Reformat Code.
- In the Reformat Code dialog box, specify the necessary options and filters for you reformatting and click Run.
Reformatting code for the current file
To reformat code for the current file, follow these steps:
In the editor of the currently opened file, press
Ctrl+Shift+Alt+L
.Note that if you select Code | Reformat Code from the main menu or press
Ctrl+Alt+L
, IntelliJ IDEA will try to reformat the source code automatically without opening the Reformat File dialog.- In the Reformat File dialog, specify options for the reformatting and click Run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With