@codacy/tools-scalastyle-1
v0.4.1
Published
Scalastyle adapter — CLI-mode Scala style checker
Readme
@codacy/tools-scalastyle-1
Table of Contents
Overview
Scala style checker and static analysis tool using the Scalastyle assembly JAR. Uses the CLI execution strategy -- spawns java -cp scalastyle.jar org.scalastyle.Main via spawnTool() and parses its Checkstyle-format XML output.
| Property | Value |
| ------------- | --------------------------------------------- |
| Tool ID | ScalaStyle |
| Codacy UUID | 21586cd3-3eaa-4454-878e-ac0211a833c2 |
| Strategy | CLI |
| Languages | Scala |
| Binary | java -cp scalastyle.jar org.scalastyle.Main |
| File patterns | **/*.scala |
| Pattern count | 74 |
Scalastyle is primarily a Scala 2 tool. It parses Scala source files and checks for style violations, complexity issues, and potential bugs. The assembly JAR is hosted on Maven Central.
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs follow the format ScalaStyle_MagicNumberChecker, ScalaStyle_FileLengthChecker, etc. Note the capital S in ScalaStyle and that the Checker suffix is retained (unlike Checkstyle which strips Check).
Updating the Scalastyle version
- Update
SCALASTYLE_VERSIONinsrc/adapter.ts - Update
JAR_URLto point to the new assembly JAR on Maven Central - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
scalastyle-2/)
The Maven Central artifact coordinates are:
com.beautiful-scala:scalastyle_2.13:{version}:assemblyDevelopment
pnpm build # Build with tsup
pnpm test # Run tests (unit tests always run; integration tests require java + JAR)To install the Scalastyle JAR locally for integration testing:
mkdir -p /tmp/codacy-scalastyle-test-tools
curl -L -o /tmp/codacy-scalastyle-test-tools/scalastyle.jar \
https://repo1.maven.org/maven2/com/beautiful-scala/scalastyle_2.13/1.5.1/scalastyle_2.13-1.5.1-assembly.jarNotes for maintainers
- Scalastyle requires Java 8+ as a runtime. The adapter uses
ensureJre()to download Adoptium Temurin JDK 17 if no system Java is found. - The assembly JAR (~9 MB) is downloaded from Maven Central via
downloadJar()to~/.codacy/tools/scalastyle-1/. - Scalastyle takes directories as input, not individual file lists. The adapter passes the repository root and then filters the XML output by
ctx.targetFiles. - XML output is written to a temp file via
--xmlOutput, not to stdout. The adapter reads and parses the temp file after execution. - The
sourceattribute in XML output is an FQCN likeorg.scalastyle.scalariform.MagicNumberChecker. The adapter extracts the last segment to derive the pattern ID. - Checker namespace mapping: checkers in the static
FILE_LEVEL_CHECKERSset map toorg.scalastyle.file.*; all others map toorg.scalastyle.scalariform.*. - Exit code 0 = clean, 1 = findings found or error. The adapter reads the XML output regardless of exit code (0 or 1).
- Config file detection looks for
scalastyle_config.xmlorscalastyle-config.xmlin the repository root (underscore variant preferred). - When generating config from patterns, each check is emitted with
level="warning"and includes default parameters frompatterns.json. - The
columnattribute may be absent in Scalastyle output; it is omitted from the issue when not present. fast-xml-parseris configured withignoreAttributes: falseandisArrayforfile/errorelements to handle single-element cases.
