Skip to main content

Module ktlint

Module ktlint 

Source
Expand description

Port of the ktlint 2.0.0-ALPHA-4 CLI (ktlint-cli): the ktlint binary’s flags, messages, reporters and exit codes, over ktrs-lint’s engine and standard rules. Differential test: tools/ktlint-oracle/cli-diff.sh. With --ktlint-version=1.8 (or ktrs_ktlint_version = 1.8) it is the 1.8.0 CLI instead: version.

A run that loads a rule set (-R) or reporter (artifact=) JAR with JVM code is handed to the real ktlint jar (ktlint_jar). Deviations: --log-level=debug|trace prints only the CLI’s own messages, not the engine’s; help text is wrapped for 80 columns whatever the terminal; a rule crash shows the panic, not a JVM stack trace.

Re-exports§

pub use command_line::ExitCode;
pub use command_line::KtlintCli;

Modules§

args
The options of KtlintCommandLine and its subcommands (Main.kt), parsed the way Clikt does.
baseline
Port of ktlint-cli-reporter-baseline’s Baseline.kt: loading a baseline of errors to ignore.
command_line
Port of ktlint-cli internal/KtlintCommandLine.kt (and Main.kt): the ktlint command.
console
The process streams the ktlint CLI writes to, swappable for in-process tests.
file_utils
Port of ktlint-cli internal/FileUtils.kt: patterns (globs with gitignore-style ! negation, files, directories) to the files to lint, walked in directory order from the patterns’ common parent.
gradle
Hidden, ktrs-only options for the ktlint-gradle drop-in (io.github.hexay.ktrs.ktlint, research/29). That plugin runs ktlint’s engine in-process with its own reporting; these options make a CLI run behave the same way:
java_glob
Java’s glob: PathMatcher (sun.nio.fs.Globs.toUnixRegexPattern), matched against a path string.
jpath
java.nio.file.Path semantics that ktlint’s file handling depends on, over /-separated strings (on Windows, \ is read as /): parsing drops redundant separators, resolve keeps ./.., normalize is lexical, startsWith compares whole names.
ktlint_jar
Runs the real ktlint release jar with the run’s argv when it loads a rule set JAR ktrs can’t run natively (research/27-custom-rulesets-impl.md): stdout, stderr and exit code pass through untouched. The jar is the release asset of the active KtlintVersion, downloaded once into the user cache and checked against a pinned SHA-256; KTRS_KTLINT_JAR overrides the path (not checked).
logger
ktlint’s logging: kotlin-logging over logback with its default TTLLLayout console appender, which writes HH:mm:ss.SSS [thread] LEVEL logger -- message to stdout (also with --stdin).
reporter
Ports of the built-in ktlint reporters (ktlint-cli-reporter-*) and of ktlint-cli-reporter-core. A reporter is looked up by id (get_reporter), as ktlint’s ReporterProviderV2 service loader does.
version
Which ktlint CLI the drop-in imitates: --ktlint-version=<1.8|2.0> (ktrs only, hidden), else ktrs_ktlint_version of the .editorconfig that applies to the working directory, else 2.0. Chosen once per run and passed to the engine as an .editorconfig override, so every file follows it. The engine and rule switches: research/26-ktlint-18-mode.md.

Functions§

main
The ktlint binary: args without the program name; returns the exit code.