ktlint
Kotlin code formatter and linter from Pinterest — zero-configuration (no .editorconfig required for defaults) formatter that enforces the Kotlin official style guide. ktlint provides: auto-formatting (ktlint --format), lint checking (ktlint check), Gradle integration (ktlintCheck/ktlintFormat tasks), IntelliJ/Android Studio plugin, and EditorConfig support for custom rules. Works as a complementary tool to Detekt — ktlint handles formatting (indentation, spaces, blank lines, trailing whitespace) while Detekt handles code smells and complexity. Part of most Android/Kotlin CI pipelines.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Code formatting tool — no security concerns. No network access during formatting. Consistent formatting indirectly improves security by making code easier to review.
⚡ Reliability
Best When
You want zero-effort, zero-configuration Kotlin code formatting enforcement in CI — ktlint's defaults match official Kotlin style guide and require no team debate on formatting.
Avoid When
You need code smell detection (use Detekt instead or in addition), you have complex custom formatting rules not supported by ktlint's .editorconfig options, or you're in a non-Kotlin project.
Use Cases
- • Enforce consistent Kotlin code formatting in agent codebase using ktlint Gradle tasks — ktlintCheck in CI fails PRs with formatting issues; ktlintFormat auto-fixes locally
- • Standardize Kotlin code style across agent project team using ktlint's zero-configuration defaults — no committee debate on formatting rules; ktlint enforces official Kotlin style guide
- • Pre-commit hook for automatic agent code formatting — git hook runs ktlintFormat before commits to prevent formatting PRs from polluting git history
- • Customize agent project formatting rules with .editorconfig — override specific ktlint rules (max line length, trailing commas) while keeping ktlint's default enforcement
- • Generate SARIF output for GitHub Code Scanning integration — ktlint --reporter=sarif for GitHub Advanced Security formatting findings display in PRs
Not For
- • Code smell detection beyond formatting — use Detekt for complexity, code smells, and logic issues; ktlint focuses on formatting not logic
- • Non-Kotlin files — ktlint is Kotlin-only; use Prettier (JS/TS), Black (Python), or gofmt (Go) for other languages in polyglot repositories
- • Complex custom rule enforcement — ktlint custom rule creation is possible but complex; Detekt custom rules are easier to write for business-specific code quality rules
Interface
Authentication
Code formatting tool — no auth concepts.
Pricing
ktlint is MIT licensed, maintained by Pinterest and community. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ ktlint 1.x vs 0.x breaking changes — ktlint 1.0 changed rule IDs and EditorConfig property names; .editorconfig files configured for 0.x may silently not apply to ktlint 1.x; update rule names after upgrading
- ⚠ Android Studio/IntelliJ auto-format conflict — IDE's Kotlin formatter may apply different formatting than ktlint; configure IDE to use ktlint via ktlint-intellij-plugin or Spotless IDE integration; misaligned formatting causes constant ktlintCheck failures
- ⚠ Gradle task configuration varies by plugin — jlleitschuh/ktlint-gradle plugin and Spotless both support ktlint; configuration syntax differs; follow the specific plugin's docs; mixing documentation from different plugins causes misconfigured tasks
- ⚠ Generated Kotlin files should be excluded — Room, KSP, and kapt-generated .kt files in build/ directory should be excluded from ktlint check; add build/ to .editorconfig ktlint exclusion or Gradle task source configuration
- ⚠ Multi-module Gradle projects need per-module configuration — ktlint Gradle plugin applies to each module separately; root project configuration doesn't auto-apply to subprojects without explicit subprojects { } block
- ⚠ Pre-commit hook with Husky vs manual setup — pre-commit ktlint hooks require staged-file filtering (ktlintFormat only changed files); formatting all files in pre-commit is too slow; use lint-staged pattern or custom git hook script
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for ktlint.
Scores are editorial opinions as of 2026-03-06.