Lint Rules
Status: ⚪ Planned —
[lint]parses, but no rules run yet. This page specifies the intended rule set. See Implementation Status.
Rules are grouped into categories. Enable categories, not individual rules, in the common case:
[lint]
rules = ["naming", "style", "complexity", "performance", "correctness"]
severity = "warning"
| Severity | Effect |
|---|---|
error | Reported, command exits non-zero |
warning | Reported, command succeeds |
info | Reported quietly |
naming
Kotlin naming conventions.
| Rule | Flags |
|---|---|
class-naming | Classes and interfaces not in PascalCase |
function-naming | Functions not in camelCase (backtick test names exempt) |
property-naming | Properties not in camelCase |
constant-naming | const val and top-level val not in SCREAMING_SNAKE_CASE |
package-naming | Packages not lowercase and dot-separated |
type-parameter-naming | Type parameters not single uppercase letters or PascalCase |
boolean-prefix | Boolean properties without an is, has, or can prefix |
Mechanical and uncontroversial. A good first category to turn on at error.
style
Formatting-adjacent issues the formatter does not rewrite on its own.
| Rule | Flags |
|---|---|
import-ordering | Imports not alphabetized |
unused-import | Imports nothing in the file uses |
wildcard-import | import foo.* |
redundant-qualifier | Fully qualified names that are already imported |
trailing-comma | Missing trailing commas in multi-line argument lists |
brace-style | Braces not in Kotlin's standard position |
max-line-length | Lines over [format] max-line-length |
semicolons | Unnecessary statement terminators |
explicit-unit-return | A redundant : Unit |
Most are auto-fixable with kargo lint --fix.
complexity
| Rule | Default threshold |
|---|---|
function-length | 60 lines |
cyclomatic-complexity | 15 branches |
nesting-depth | 4 levels |
parameter-count | 7 parameters |
class-length | 600 lines |
nested-block-depth | 4 levels |
cognitive-complexity | 20 |
Thresholds are configurable:
[lint.complexity]
function-length = 40
cyclomatic-complexity = 10
On an existing codebase this category produces a long list on day one. Introduce
it at info, work the list down, then promote it.
performance
| Rule | Flags |
|---|---|
unnecessary-allocation | A temporary collection where a sequence would do |
inefficient-collection-call | filter {}.first() instead of first {} |
string-concat-in-loop | Building a string with += in a loop |
boxed-primitive | A boxed type where the primitive would serve |
deprecated-api | Calls to APIs marked @Deprecated |
redundant-suspend | suspend on a function that never suspends |
eager-collection-ops | A chain of eager operations that should be an asSequence() |
correctness
The category most likely to find real bugs.
| Rule | Flags |
|---|---|
unreachable-code | Code after an unconditional return or throw |
unused-variable | A local that is assigned and never read |
unused-parameter | A parameter the function body ignores |
suspicious-equals | == between unrelated types |
platform-type-npe | An unchecked platform type from Java interop |
empty-catch | A catch block that swallows silently |
unsafe-cast | as where as? would be safe |
implicit-nothing | An inferred Nothing type that is probably unintended |
missing-actual | An expect with no actual for a configured target |
coroutine-scope-leak | A CoroutineScope created and never cancelled |
Configuring individual rules
[lint]
rules = ["naming", "style", "correctness"]
severity = "warning"
[lint.rules]
wildcard-import = "error" # stricter than the category default
max-line-length = "off" # the formatter already handles it
empty-catch = "error"
Per-rule values override the category: off, info, warning, error.
Suppressing in code
@Suppress("function-length")
fun theBigOne() { … }
// kargo-lint-disable-next-line unsafe-cast
val x = y as String
// kargo-lint-disable-file max-line-length
A suppression should come with a reason in a comment. An unexplained suppression is indistinguishable from an abandoned one.
Generated code
[lint]
exclude = ["**/generated/**", "**/BuildConfig.kt", "build/**"]
Generated files are excluded by default — build/, KSP and KAPT output, and
BuildConfig. Linting code you did not write produces noise you cannot fix.
Output formats
kargo lint --format text # colored terminal output, the default
kargo lint --format json # machine-readable
kargo lint --format sarif # GitHub code scanning and similar
Custom rules
Status: ⚪ Planned.
[lint.custom]
no-println = "lint-rules/no-println.rhai"
For conventions a general-purpose linter cannot know: an internal API that must
not be called from a particular module, or a logging facade that must be used
instead of println. See Plugins and Hooks.