@codacy/tools-checkstyle-10
v0.2.0
Published
Checkstyle adapter — CLI-mode Java style checker
Readme
@codacy/tools-checkstyle-10
Table of Contents
Overview
Java style checker and static analysis tool using the Checkstyle fat JAR. Uses the CLI execution strategy -- spawns java -jar checkstyle-all.jar via spawnTool() and parses its XML output.
| Property | Value |
|----------|-------|
| Tool ID | Checkstyle |
| Codacy UUID | f4a54ce0-1fe1-4bc7-a9ed-9f91f675c409 |
| Strategy | CLI |
| Languages | Java |
| Binary | java -jar checkstyle-10.26.1-all.jar |
| File patterns | **/*.java |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs follow the format Checkstyle_AvoidStarImport, Checkstyle_WhitespaceAround, etc. The check name is extracted from the FQCN source attribute (e.g. com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck becomes AvoidStarImport).
Updating the Checkstyle version
- Update
CHECKSTYLE_VERSIONinsrc/adapter.ts - Update
JAR_NAMEandJAR_URLconstants accordingly - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
checkstyle-11/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (requires java in PATH + JAR in tools dir)To install the Checkstyle JAR locally for testing:
mkdir -p /tmp/codacy-checkstyle-test-tools
curl -L -o /tmp/codacy-checkstyle-test-tools/checkstyle-10.26.1-all.jar \
https://github.com/checkstyle/checkstyle/releases/download/checkstyle-10.26.1/checkstyle-10.26.1-all.jarNotes for maintainers
- Checkstyle requires Java 11+ as a runtime. The adapter uses
ensureJre()to download Adoptium Temurin JDK 17 if no system Java is found. - The fat JAR is downloaded from GitHub releases via
downloadJar()to~/.codacy/tools/checkstyle-10/. - Exit code 0 = no violations, >0 = violations found (parse XML), negative = error.
- XML output is on stdout (unlike cppcheck which uses stderr).
error/@sourceis an FQCN likecom.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck. The adapter strips the package prefix andChecksuffix to derive the check name.error/@columnmay be absent; defaults to 1 when missing.- Line/column numbers in Checkstyle XML are already 1-based; no conversion needed.
- Some modules (Header, FileLength, LineLength, etc.) are global and must be placed under
<module name="Checker">rather than inside<module name="TreeWalker">. The adapter handles this split when generating config from patterns. - Config file detection looks for
checkstyle.xmlin the repository root. - When no local config and no patterns are specified, the adapter uses Checkstyle's built-in
sun_checks.xml. - Checkstyle prints
Starting audit...andAudit done.to stderr; these are filtered out from the error output.
