Code Style

note

Code Style - 图1

This help topic is in development and will be updated in the future.

Official Code Convention

Ktor as well as other official Kotlin libraries use the official Kotlin Coding Conventions.

You can use the official coding standard by adding kotlin.code.style=official to your gradle.properties file.

With Star Imports

The Official Coding Conventions don’t define what’s the recommended way of using imports. The IntelliJ default is to include star (*) imports after importing at least 5 symbols from a package. But in Ktor and other libraries at JetBrains we use and recommend using star imports always.

The rationale behind it is that usually when you include a class, you will probably want to include all the method and property extension declared for that class. That’s specially convenient for operator extension methods.

You can change the import configuration in Preferences... -> Editor -> Code Style -> Kotlin -> Imports:

code style imports png