Formats code with KtLint after IntelliJ IDEA formatting or on save of file.
Ktlint is an anti bikeshedding linter/formatter for Kotlin code based on the Kotlin Coding Conventions, Androids Kotlin Style guide, and other best practices.
Ktlint is configured in the .editorconfig
file (see KtLint configuration). Next to this, the plugin itself has a few configuration options. The plugin can run in distinct modes.
In the recommended 'distract free' mode, lint violations are automatically corrected when possible. Combined with formatting on save, ktlint enhances your developer experience greatly. Violations that can not be autocorrected are displayed as error.
In the 'manual' mode, ktlint format is not run automatically. Format can still be invoked manually for the entire file (via the refactor menu). If autocorrect for an individual violation is supported by the rule, the autocorrect option is also shown as Quick Fix. All violations found by ktlint are displayed as warning.
This plugin was formerly known as the "Ktlint (unofficial)" plugin, developed by Nick Badal. In collaboration with KtLint maintainer Paul Dingemans, the plugin has now been reworked and rebranded as (official) "KtLint" Plugin. The plugin now puts more focus on the automatic formatting of Kotlin code. This results in more consistent code, better performance in IntelliJ IDEA, and developers spending less time on fixing errors which can be autocorrected. Finally, the plugin will be updated in same release cycle as KtLint itself.
The plugin currently runs with ktlint version 1.4.1
by default (see ktlint preferences to alter the ruleset version). K2 mode is supported starting from Intellij IDEA version 2024.2.1.
Enable and configure in Preferences
> Tools
> KtLint
.