Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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"
SeverityEffect
errorReported, command exits non-zero
warningReported, command succeeds
infoReported quietly

naming

Kotlin naming conventions.

RuleFlags
class-namingClasses and interfaces not in PascalCase
function-namingFunctions not in camelCase (backtick test names exempt)
property-namingProperties not in camelCase
constant-namingconst val and top-level val not in SCREAMING_SNAKE_CASE
package-namingPackages not lowercase and dot-separated
type-parameter-namingType parameters not single uppercase letters or PascalCase
boolean-prefixBoolean 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.

RuleFlags
import-orderingImports not alphabetized
unused-importImports nothing in the file uses
wildcard-importimport foo.*
redundant-qualifierFully qualified names that are already imported
trailing-commaMissing trailing commas in multi-line argument lists
brace-styleBraces not in Kotlin's standard position
max-line-lengthLines over [format] max-line-length
semicolonsUnnecessary statement terminators
explicit-unit-returnA redundant : Unit

Most are auto-fixable with kargo lint --fix.

complexity

RuleDefault threshold
function-length60 lines
cyclomatic-complexity15 branches
nesting-depth4 levels
parameter-count7 parameters
class-length600 lines
nested-block-depth4 levels
cognitive-complexity20

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

RuleFlags
unnecessary-allocationA temporary collection where a sequence would do
inefficient-collection-callfilter {}.first() instead of first {}
string-concat-in-loopBuilding a string with += in a loop
boxed-primitiveA boxed type where the primitive would serve
deprecated-apiCalls to APIs marked @Deprecated
redundant-suspendsuspend on a function that never suspends
eager-collection-opsA chain of eager operations that should be an asSequence()

correctness

The category most likely to find real bugs.

RuleFlags
unreachable-codeCode after an unconditional return or throw
unused-variableA local that is assigned and never read
unused-parameterA parameter the function body ignores
suspicious-equals== between unrelated types
platform-type-npeAn unchecked platform type from Java interop
empty-catchA catch block that swallows silently
unsafe-castas where as? would be safe
implicit-nothingAn inferred Nothing type that is probably unintended
missing-actualAn expect with no actual for a configured target
coroutine-scope-leakA 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.

Next