Skip to content

Attribute lints forwarded through toggleOffOn to their originating step (#2859) - #3204

Open
Pankraz76 wants to merge 2 commits into
diffplug:mainfrom
Pankraz76:fix/2859-toggle-lint-attribution
Open

Pankraz76 wants to merge 2 commits into
diffplug:mainfrom
Pankraz76:fix/2859-toggle-lint-attribution

Conversation

@Pankraz76

@Pankraz76 Pankraz76 commented Nov 23, 2026 •

Copy link
Copy Markdown

Fixes #2859. Follow-up to #2962.

Problem

#2962 made toggleOffOn forward lints from its inner steps, but they are attributed to the fence step toggle instead of the step that produced them:

Step 'toggle' found problem in 'Main.java':
Main.java:L1 toggle(import java.util.*;) Do not use wildcard imports ...

Because of that, a suppression for the real step does not match while toggleOffOn is enabled:

  • Maven: <lintSuppression><step>forbidWildcardImports</step></lintSuppression>
  • Gradle: suppressLintsFor { step = 'forbidWildcardImports' }

Only toggle or * work.

After this change:

Step 'forbidWildcardImports' found problem in 'Main.java':
Main.java:L1 forbidWildcardImports(import java.util.*;) Do not use wildcard imports ...

Change

  • Lint gets an optional step name: getStepName() and withStepName(String). withStepName returns a copy and keeps an existing name, so for nested fences the innermost step wins. The field is not part of equals/hashCode/toString, and serialVersionUID is unchanged, so lint files Gradle has already written still deserialize.
  • FenceStep.preserveWithin sets the inner step's name on each lint it forwards. The fence's own fenceRemoved lint is still reported as the fence step.
  • LintState.getLintsByStep and asString report each lint under that step name when it is set, and otherwise under the formatter step. All Maven (check/apply/report) and Gradle messages go through these two methods.
  • LintSuppression matches a step against the inner step name or the formatter step name, so existing toggle suppressions keep working.

Why this approach

I started with the simplest version: the change stays inside FenceStep and the two places that resolve a lint's step name, it adds only one optional field to Lint, and nothing changes for builds without a fence.

Alternatives I considered:

  • Leave Lint alone and have LintState look inside FenceStep's inner steps. That avoids touching Lint, but it ties core lint handling to FenceStep internals: more code and more coupling for the same result.
  • Put the step name into shortCode. That would break suppressions by shortCode.

If you'd prefer a different approach, tell me in review and I'll change it.

Tests

  • lib: LintTest (step name copy, innermost wins, not part of identity, serialization round trip), LintStateTest (grouping and output by step name), LintSuppressionTest (suppression by inner and by fence step name)
  • testlib: FenceStepTest. The expectation changes from toggle(...) to forbidWildcardImports(...), plus nested fences and suppression end to end
  • plugin-maven: ToggleOffOnTest. Covers the reported step name, the same output without the toggle, suppression by forbidWildcardImports and by toggle, and the issue's own config (toggleOffOn + removeUnusedImports + forbidWildcardImports with spotless:apply)
  • plugin-gradle: ToggleOffOnTest, with the config cache on and off. Covers the reported step name and both suppressions

Verified locally:

  • Without the fix, the new tests fail on main as expected (Step 'toggle' …); the backward-compatibility tests (suppression by toggle, output without toggle) pass on main.
  • With the fix: :lib:test 105/105, testlib FenceStepTest 7/7, plugin-maven ToggleOffOnTest 7/7 + LintSuppressionTest 5/5, plugin-gradle ToggleOffOnTest 10/10 (with and without configuration cache).
  • spotlessCheck and :lib:spotbugsMain pass.

Changelog entries are in CHANGES.md, plugin-maven/CHANGES.md and plugin-gradle/CHANGES.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MTr23yLJcRtZewXQd4rbQS

…diffplug#2859)

Lints that FenceStep.preserveWithin (toggleOffOn) forwards from its inner
steps were reported under the fence step name "toggle", so messages named
the wrong step and lint suppressions by the real step name (e.g.
forbidWildcardImports) did not match.

FenceStep now records the inner step name on each forwarded lint
(Lint#withStepName, innermost step wins). LintState reports lints under
that name, and LintSuppression matches either the inner step name or the
fence step name, so existing "toggle" suppressions keep working.

Tests for lib, testlib, plugin-maven and plugin-gradle are included;
they have not been run yet (Maven Central rate limiting in the build
environment).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MTr23yLJcRtZewXQd4rbQS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MTr23yLJcRtZewXQd4rbQS
@Pankraz76
Pankraz76 marked this pull request as ready for review November 23, 2026 16:01

This branch has not been deployed

No deployments
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.

spotless-maven-plugin: <toggleOffOn/> breaks <forbidWildcardImports/>

2 participants