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

Linting and Formatting

Status: ⚪ Planned — [lint] and [format] parse today, and the kargo-lint crate is scaffolded, but kargo lint, kargo fmt, and kargo fix are not implemented. This page describes the intended behavior. See Implementation Status.

Linting and formatting are built in. There is no plugin to add, no second tool to version, and no separate configuration file.

kargo lint          # report problems
kargo lint --fix    # fix what can be fixed
kargo fmt           # format
kargo fmt --check   # verify formatting, for CI
kargo fix           # apply every auto-fixable suggestion

Why in the build tool

A linter that ships with the build tool shares the build's parsed sources, dependency graph, and configuration. That means one pass over the code instead of three, and no possibility of your linter and your compiler disagreeing about which Kotlin version they are reading.

It also means one fewer thing to install, pin, and upgrade in lockstep.

Configuring rules

[lint]
rules = ["naming", "style", "complexity", "performance", "correctness"]
severity = "warning"
CategoryCatches
namingClass, function, property, and constant naming conventions
styleBrace placement, spacing, import order, trailing commas
complexityLong functions, deep nesting, high cyclomatic complexity
performanceNeedless allocation, inefficient collection use, deprecated APIs
correctnessUnreachable code, unused values, suspicious comparisons

severity sets the default level: error fails the command, warning reports and succeeds, info is advisory only.

Start with naming and style — they are mechanical and uncontroversial. complexity on an existing codebase produces a large list on day one; introduce it at info, work the list down, then promote it to warning.

The full rule list is in the Lint Rules reference.

Formatting

[format]
style = "official"
indent = 4
max-line-length = 120
KeyValuesDefault
styleofficialofficial
indentspaces per level4
max-line-lengthcolumns120

The default is the Kotlin coding conventions. Formatting is not a place to be creative: pick the standard, run it on save, and stop thinking about it.

kargo fmt           # rewrite files
kargo fmt --check   # exit non-zero if anything is unformatted

--check prints a diff of what it would change, so a CI failure tells you what to run rather than only that something is wrong.

The formatter preserves comment placement and blank-line structure where it can. Reformatting a file should produce a small diff, not a wholesale rewrite — a formatter that churns unrelated lines makes every review harder.

Auto-fixing

kargo lint --fix    # fix lint violations
kargo fix           # everything auto-fixable, lint and format

Only unambiguous fixes are applied: an import order, a redundant qualifier, a missing trailing comma. Anything requiring a judgment call is reported, not changed. A tool that guesses at intent produces diffs you have to review line by line, which defeats the purpose.

Commit before running --fix on a large codebase, so the result is one reviewable diff.

Output formats

kargo lint --format text     # colored terminal output (default)
kargo lint --format json     # machine-readable
kargo lint --format sarif    # for GitHub code scanning and similar

SARIF is what makes findings appear inline on a pull request:

- run: kargo lint --format sarif > results.sarif
- uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: results.sarif

In CI

kargo fmt --check
kargo lint

Keep them separate from the build. A formatting failure should not hide a compile error, and a 30-second lint job that fails fast is more useful than a 10-minute build that fails at the end for a missing newline.

See Continuous Integration.

With editors

Status: ⚪ Planned — see Editors and IDEs.

kargo lsp surfaces lint diagnostics inline and offers the auto-fixes as code actions, so problems appear as you type rather than when CI tells you.

Custom rules

Status: ⚪ Planned.

Project-specific rules via script plugins:

[lint.custom]
no-println = "lint-rules/no-println.rhai"

For enforcing conventions a general-purpose linter cannot know about: an internal API that must not be called from a particular module, a logging facade that must be used instead of println.

Next