spotless:off and spotless:on fails to prevent changes to imports (v2)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- build-system, tooling
Research direction
Reproduce the Maven configuration with java ImportSorter and toggleOffOn using the spotless:off/on example. Start by reading ImportOrderStep and the toggleOut handling in PipeStepPair, then check the existing tests for these steps. Done means the trailing import comment remains intact and the toggle markers no longer trigger the reported exception.
Written by the indexing model from the issue text.
Description
This can be seen as a reboot of https://github.com/diffplug/spotless/issues/558 and https://github.com/diffplug/spotless/issues/996.
I want Java ImportSorter not to remove the trailing comment from:
import java.util.TreeSet; // NOPMD false positive, see https://github.com/pmd/pmd/issues/4816
```.
To do so, I wrote:
com.diffplug.spotless
spotless-maven-plugin
2.43.0
[...]
```
and
// spotless:off
import java.util.TreeSet; // NOPMD false positive, see https://github.com/pmd/pmd/issues/4816
// spotless:on
It led to the exception:
[INFO] --- spotless-maven-plugin:2.43.0:apply (default-cli) @ sp-core ---
[INFO] Index file corresponds to a different configuration of the plugin. Either the plugin version or its configuration has changed. Fallback to an empty index
[ERROR] Step 'toggleOut' found problem in 'src/main/java/.../XXX.java':
An intermediate step removed a match of spotless:off spotless:on
java.lang.Error: An intermediate step removed a match of spotless:off spotless:on
at com.diffplug.spotless.generic.PipeStepPair.stateOutCompute (PipeStepPair.java:207)
at com.diffplug.spotless.generic.PipeStepPair$StateOut.format (PipeStepPair.java:176)
at com.diffplug.spotless.generic.PipeStepPair.lambda$new$2 (PipeStepPair.java:97)
at com.diffplug.spotless.FormatterFunc.apply (FormatterFunc.java:32)
at com.diffplug.spotless.FormatterStepImpl$Standard.format (FormatterStepImpl.java:82)
at com.diffplug.spotless.FormatterStep$Strict.format (FormatterStep.java:103)
at com.diffplug.spotless.Formatter.compute (Formatter.java:246)
at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:203)
at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:190)
at com.diffplug.spotless.maven.SpotlessApplyMojo.process (SpotlessApplyMojo.java:63)
at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:237)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
[...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.807 s
[INFO] Finished at: 2024-02-15T14:21:17+04:00
[INFO] ------------------------------------------------------------------------
---------------------------------------------------
[...]
---------------------------------------------------
Exception in thread "main" java.lang.Error: An intermediate step removed a match of spotless:off spotless:on
at com.diffplug.spotless.generic.PipeStepPair.stateOutCompute(PipeStepPair.java:207)
at com.diffplug.spotless.generic.PipeStepPair$StateOut.format(PipeStepPair.java:176)
at com.diffplug.spotless.generic.PipeStepPair.lambda$new$2(PipeStepPair.java:97)
at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:32)
at com.diffplug.spotless.FormatterStepImpl$Standard.format(FormatterStepImpl.java:82)
at com.diffplug.spotless.FormatterStep$Strict.format(FormatterStep.java:103)
at com.diffplug.spotless.Formatter.compute(Formatter.java:246)
at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:203)
at com.diffplug.spotless.PaddedCell.calculateDirtyState(PaddedCell.java:190)
at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:237)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
Is this a missing feature of ImportOrderStep? Or a bug around toggleOffOn?
- Dominant language
- Java
- Stars
- 5.7k
- Forks
- 560
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 43
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diffplug/spotless
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 66/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
All issues in diffplug/spotless
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
1.0.0-alpha2 Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#272 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100