Skip to content

fix: pad the last table row and report tables at the right level - #188

Merged
NicklasWallgren merged 1 commit into
mainfrom
fix/console-violation-reporter-padding
Sep 11, 2026
Merged

NicklasWallgren merged 1 commit into
mainfrom
fix/console-violation-reporter-padding

Conversation

@NicklasWallgren

Copy link
Copy Markdown
Member

Two output bugs in ConsoleTableViolationReporter, plus test coverage of the rendered output.

The last row of every table was rendered unpadded

table.setPadding(1) was called inside the row loop. AsciiTable.setPaddingLeft iterates the rows added so far and applies the padding retroactively — it is not a default for rows added later. Each iteration therefore padded everything up to the previous row, and the final violation never got padded:

│ checkstyle │ LineLength   │ Line is longer than 160 characters. │   ← padded
├────────────┼──────────────┼─────────────────────────────────────┤
│NullAway    │NullAway      │Passing @Nullable parameter 'name' … │   ← last row, unpadded

Now set once, after every row is in place. Note that hoisting the call above the loop would have been worse — only the header would have been padded.

Tables were logged at info even for non-permissive violations

The category header went through logWithLevel (→ warn), but the table itself was a hardcoded log.info(...). Under a quiet build you got the warning header and lost the violations it referred to. Now routed through logWithLevel, matching ConsolePlainViolationReporter.

Shared base class

report(), logViolationsForType(), logWithLevel(), the PermissiveType enum and the ANSI constants were byte-identical in both reporters. Extracted into AbstractConsoleViolationReporter with a single abstract hook, logViolations(log, violations, permissiveType) — the only thing the two reporters actually do differently.

Also dropped the stale Severity#MINOR javadoc (neither reporter filters by severity), corrected the column comments, and named the magic render(200).

Tests

11 tests over both reporters. RecordingLog captures each message together with the level it was logged at, which is what makes the level bug assertable. UnitTest#snapshotText snapshots output verbatim rather than as JSON, so the rendered table is reviewable in the .snap file.

Both bugs were re-introduced to confirm the tests catch them — 4 of 6 failed:

givenViolations_whenReport_thenEveryRowIsPadded
  Cell isn't padded to the left: 'NullAway    ' of row '│NullAway    │NullAway  …'

givenNonPermissiveViolations_whenReport_thenTableIsReportedAsWarning
  Expected the table to be reported at [WARN] ==> expected: <true> but was: <false>

givenPermissiveViolations_whenReport_thenTableIsReportedAsInfo kept passing, since info is correct on that path.

Not addressed

  • ANSI escapes are emitted unconditionally, so redirected or non-ANSI output gets the literal escape sequences rather than colour. The idiomatic fix is MessageUtils, which would mean adding maven-shared-utils as a provided dependency.
  • Neither console reporter surfaces Violation.severity, though GitLabFileViolationReporter does.

The padding of an AsciiTable applies to the rows added so far, so setting
it inside the row loop left the row added last unpadded.

The rendered table was also always logged at info, while the header of the
category it belongs to was logged at warn, which dropped the violations of
a quiet build.

Extracts the parts shared by both console reporters into
AbstractConsoleViolationReporter, and covers the rendered output with
snapshot tests.
@NicklasWallgren
NicklasWallgren enabled auto-merge (squash) September 11, 2026 17:14
@NicklasWallgren
NicklasWallgren merged commit 14fd04f into main Sep 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant