KtLint configuration
Plugin setup
KtLint is configured at the project level in build.gradle.kts:1 and applied to all modules:Plugin version
The project uses KtLint plugin version 13.1.0 (gradle/libs.versions.toml:44):KtLint is configured with
ignoreFailures = false, meaning builds will fail if style violations are detected.EditorConfig
The project uses.editorconfig to customize KtLint rules and IDE behavior.
Current rules
The configuration in .editorconfig:1 sets the following rules:Rule explanations
Trailing commas
Trailing commas
Disabled rules:
ktlint_standard_trailing-comma-on-call-sitektlint_standard_trailing-comma-on-declaration-site
Line length
Line length
Disabled rule:
ktlint_standard_max-line-lengthMaximum line length is not enforced, allowing longer lines when necessary for readability:While not enforced, aim to keep lines under 120 characters when practical.
Import ordering
Import ordering
Disabled rule:
ktlint_standard_import-orderingImport ordering is not enforced by KtLint. The IDE handles import organization based on Kotlin official style.Composable function naming
Composable function naming
Custom rule:
ktlint_function_naming_ignore_when_annotated_with = ComposableComposable functions can use PascalCase naming (capitalized), which is standard for Compose:Code formatting
Automatic formatting
Format all code automatically:The
ktlintFormat task automatically fixes most style violations.Check code style
Validate code style without making changes:Output reports
KtLint generates three types of reports:- PLAIN - Human-readable console output
- CHECKSTYLE - XML format for CI tools
- SARIF - Static analysis format for GitHub, Azure DevOps
Pre-commit hooks
Automatic enforcement
KtLint checks are automatically run before every build via pre-build hooks in app/build.gradle.kts:48:Manual hooks
You can also run checks manually before committing:IDE integration
Android Studio / IntelliJ IDEA
Configure your IDE to use the project’s code style:Apply EditorConfig
The IDE automatically detects
.editorconfig and applies settings to Kotlin files.Set Kotlin code style
The project uses official Kotlin style (gradle.properties:19):This is automatically applied to all modules.
KtLint IDE plugin
Install the KtLint plugin for real-time feedback:- Open Settings → Plugins
- Search for “ktlint”
- Install ktlint (unofficial) plugin
- Restart IDE
Code style guidelines
Kotlin official style
The project follows the Kotlin official coding conventions:Naming conventions
Naming conventions
Indentation and spacing
Indentation and spacing
Function formatting
Function formatting
Composable conventions
Composable conventions
Troubleshooting
Build fails due to KtLint
If the build fails with KtLint violations:-
Run auto-format:
-
Check remaining issues:
-
Review the report:
- Fix manual issues that auto-format couldn’t resolve
Disable specific rules
To disable additional rules, add them to.editorconfig:
Ignore specific violations
Use suppression annotations for exceptional cases:Clear KtLint cache
If KtLint behaves unexpectedly:Continuous integration
CI pipeline integration
KtLint checks run automatically in CI via the pre-build hooks. For explicit CI validation:PR validation
Add KtLint checks to pull request workflows:Best practices
Format before committing
Always format code before committing:Review auto-formatting
Review changes made byktlintFormat before committing to ensure they’re correct.
Team consistency
Ensure all team members:- Use the same IDE settings
- Have EditorConfig support enabled
- Run KtLint before pushing code
Update KtLint regularly
Keep KtLint up to date for the latest rules and fixes:Next steps
Building
Learn about build configuration and Gradle tasks
Testing
Write unit and instrumented tests