Skip to content

removeWildcardImports: throw new AssertionError instead of removing #2557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Pankraz76
Copy link
Contributor

@Pankraz76 Pankraz76 commented Jul 16, 2025

Please DO NOT FORCE PUSH. Don't worry about messy history, it's easier to do code review if we can tell what happened after the review, and force pushing breaks that.

Please make sure that your PR allows edits from maintainers. Sometimes it's faster for us to just fix something than it is to describe how to fix it.

Allow edits from maintainers

After creating the PR, please add a commit that adds a bullet-point under the [Unreleased] section of CHANGES.md, plugin-gradle/CHANGES.md, and plugin-maven/CHANGES.md which includes:

  • a summary of the change
  • either
    • a link to the issue you are resolving (for small changes)
    • a link to the PR you just created (for big changes likely to have discussion)

If your change only affects a build plugin, and not the lib, then you only need to update the plugin-foo/CHANGES.md for that plugin.

If your change affects lib in an end-user-visible way (fixing a bug, updating a version) then you need to update CHANGES.md for both the lib and all build plugins. Users of a build plugin shouldn't have to refer to lib to see changes that affect them.

This makes it easier for the maintainers to quickly release your changes :)

kindly request your feedback.
@owaiskazi19
@iddeepak
@sbrannen

@Pankraz76 Pankraz76 marked this pull request as ready for review July 16, 2025 20:19
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is much better than silently removing, but we have a better way to do that.

@Pankraz76 Pankraz76 force-pushed the fix-RemoveWildcardImportsStep branch from 8e3a5f4 to 57f2b91 Compare July 17, 2025 08:27
@Pankraz76 Pankraz76 force-pushed the fix-RemoveWildcardImportsStep branch from 57f2b91 to a93a424 Compare July 17, 2025 08:36
FormatterFunc toLinter() {
return raw -> {
if (regex.matcher(raw).find()) {
throw atUndefinedLine("", replacement).shortcut();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would like to determine the line. But adding with line number 444 it was not mentioned in the error log. So i dont know how to test it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Looks like ReplaceRegexStep is missing its step-level test. It should have one called ReplaceRegexStepTest which should be a peer of this
  • We use selfie to do snapshot tests of the lint results, here is an example how that looks
  • void works0_49_0() {
    FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral());
    StepHarnessWithFile.forStep(this, step)
    .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean")
    .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import");
    }
  • don't write out what's inside of toBe, just put toBe_TODO() and then run the test, it will write the string literal for you
  • KtLint needs the path to work, thus StepHarnessWithFile, you can use just StepHarness which is easier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not understand the code, but the output does not show the line number given.

Expecting actual:
  "[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Spotless Maven Plugin Tests 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) @ spotless-maven-plugin-tests ---
[INFO] Index file does not exist. Fallback to an empty index
[ERROR] Step 'removeWildcardImports' found problem in 'test.java':
Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
com.diffplug.spotless.Lint$ShortcutException: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
	at com.diffplug.spotless.Lint.shortcut(Lint.java:111)
	at com.diffplug.spotless.generic.ReplaceRegexStep$State.lambda$toLinter$1(ReplaceRegexStep.java:68)
	at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
	at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
	at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
	at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
	at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:55)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.440 s
[INFO] Finished at: 2025-07-18T21:55:53+02:00
[INFO] Final Memory: 11M/40M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) on project spotless-maven-plugin-tests: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) on project spotless-maven-plugin-tests: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
	at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
	at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:55)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:73)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 22 more
Caused by: com.diffplug.spotless.Lint$ShortcutException: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
	at com.diffplug.spotless.Lint.shortcut(Lint.java:111)
	at com.diffplug.spotless.generic.ReplaceRegexStep$State.lambda$toLinter$1(ReplaceRegexStep.java:68)
	at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
	at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
	at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
	... 25 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
"
to contain:
  "11111" 
java.lang.AssertionError: 
Expecting actual:
  "[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Spotless Maven Plugin Tests 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) @ spotless-maven-plugin-tests ---
[INFO] Index file does not exist. Fallback to an empty index
[ERROR] Step 'removeWildcardImports' found problem in 'test.java':
Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
com.diffplug.spotless.Lint$ShortcutException: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
	at com.diffplug.spotless.Lint.shortcut(Lint.java:111)
	at com.diffplug.spotless.generic.ReplaceRegexStep$State.lambda$toLinter$1(ReplaceRegexStep.java:68)
	at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
	at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
	at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
	at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
	at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:55)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.440 s
[INFO] Finished at: 2025-07-18T21:55:53+02:00
[INFO] Final Memory: 11M/40M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) on project spotless-maven-plugin-tests: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.46.0-SNAPSHOT:apply (default-cli) on project spotless-maven-plugin-tests: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
	at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
	at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:55)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to format file /private/var/folders/3m/r9yztvfj0tl0sw8s6zl75_x00000gn/T/junit-7476299284891749091/src/main/java/test.java
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:73)
	at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute(AbstractSpotlessMojo.java:255)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 22 more
Caused by: com.diffplug.spotless.Lint$ShortcutException: Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
	at com.diffplug.spotless.Lint.shortcut(Lint.java:111)
	at com.diffplug.spotless.generic.ReplaceRegexStep$State.lambda$toLinter$1(ReplaceRegexStep.java:68)
	at com.diffplug.spotless.FormatterFunc.apply(FormatterFunc.java:33)
	at com.diffplug.spotless.FormatterStepEqualityOnStateSerialization.format(FormatterStepEqualityOnStateSerialization.java:49)
	at com.diffplug.spotless.Formatter.computeWithLint(Formatter.java:170)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:97)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:82)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:77)
	at com.diffplug.spotless.DirtyState.of(DirtyState.java:73)
	at com.diffplug.spotless.maven.SpotlessApplyMojo.process(SpotlessApplyMojo.java:63)
	... 25 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
"
to contain:
  "11111" 
	at com.diffplug.spotless.maven.java.RemoveWildcardImportsStepTest.testRemoveWildcardImports(RemoveWildcardImportsStepTest.java:48)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

@Pankraz76 Pankraz76 requested a review from nedtwigg July 17, 2025 08:52
@Pankraz76 Pankraz76 requested a review from iddeepak July 22, 2025 08:38
@Pankraz76
Copy link
Contributor Author

@iddeepak kindly asking if you might complete the linting approach? idk how to continue here. Actually it should be quite simple, but i dont get it working. Thanks.

@iddeepak
Copy link
Contributor

iddeepak commented Jul 22, 2025

@iddeepak kindly asking if you might complete the linting approach? idk how to continue here. Actually it should be quite simple, but i dont get it working. Thanks.

FormatterFunc toLinter() {
			return raw -> {
				var matcher = regex.matcher(raw);
				if (matcher.find()) {
					int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count();
					throw atLine(line, "", replacement).shortcut();
				}
				return raw;
			};
		}
image


String path = "src/main/java/test.java";
setFile(path).toResource("java/removewildcardimports/JavaCodeWildcardsUnformatted.test");
FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meant to validate only the removeWildcardImports behavior, Is it just for testing...... pulling in a KtLint step is not required here.

@iddeepak
Copy link
Contributor

iddeepak commented Jul 22, 2025

@Pankraz76
Lets add Line number in Lint#ShortcutException as well.
toString() for message instead of just passing detail here.

@Pankraz76
Copy link
Contributor Author

thanks @iddeepak, as always took care.

@Pankraz76 Pankraz76 closed this Jul 22, 2025
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.

4 participants