@codacy/tools-detekt-1
v0.2.1
Published
detekt adapter — CLI-mode Kotlin static analyzer
Readme
@codacy/tools-detekt-1
Table of Contents
Overview
Kotlin static analyzer using the detekt CLI JAR. Uses the CLI execution strategy -- spawns java -jar detekt-cli-all.jar via spawnTool() and parses its Checkstyle XML output.
| Property | Value |
|----------|-------|
| Tool ID | detekt |
| Codacy UUID | cb36c32d-fc0d-4b4c-8f21-66e536ef4513 |
| Strategy | CLI |
| Languages | Kotlin |
| Binary | detekt-cli-1.23.8-all.jar (downloaded from GitHub) |
| File patterns | **/*.kt, **/*.kts |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs are bare rule names (no prefix): LongMethod, MagicNumber, ComplexCondition, etc.
Updating the detekt version
- Update
DETEKT_VERSIONandJAR_NAMEinsrc/adapter.ts - Update
JAR_URLto point to the new release - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
detekt-2/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (requires java in PATH + detekt JAR)To install detekt locally for testing:
# Download the all-in-one JAR
curl -L -o /tmp/codacy-detekt-test-tools/detekt-cli-1.23.8-all.jar \
https://github.com/detekt/detekt/releases/download/v1.23.8/detekt-cli-1.23.8-all.jarNotes for maintainers
- detekt requires Java 8+ as a runtime. The adapter uses
ensureJre()to download Adoptium Temurin JDK 17 if no system Java is found. - The detekt CLI JAR is an all-in-one fat JAR downloaded from GitHub releases to
ctx.toolInstallDir. - Output format is Checkstyle 4.3 XML written to a temp file via
--report xml:<path>. --base-path <repoRoot>ensures file paths in the XML are relative to the repository root.--parallelenables multi-threaded analysis for performance.- The
sourceattribute in XML has formatdetekt.RuleNameordetekt.ruleset.RuleName. The adapter strips thedetekt.prefix and any ruleset prefix to get just the rule name. - Pattern IDs in
patterns.jsonhave no prefix -- they are bare rule names (e.g.LongMethod, notdetekt_LongMethod). - Exit codes: 0 = no findings, 1 = findings found (build failure threshold), 2 = findings found, 3 = invalid config.
- Config file detection supports
detekt.ymlanddefault-detekt-config.yml. When a local config is found, it is passed via--config <path>. - Pattern filtering is post-hoc: detekt runs with all default rules, then output is filtered by the enabled patterns set.
