Skip to content

allow ReplaceRegexStep to function as a Linter, use that to improve RemoveWildcardImports#2571

Merged
nedtwigg merged 22 commits intodiffplug:mainfrom
iddeepak:fix-RemoveWildcardImportsStep
Sep 23, 2025
Merged

allow ReplaceRegexStep to function as a Linter, use that to improve RemoveWildcardImports#2571
nedtwigg merged 22 commits intodiffplug:mainfrom
iddeepak:fix-RemoveWildcardImportsStep

Conversation

@iddeepak
Copy link
Copy Markdown
Contributor

Thank you @Pankraz76. please feel free to use these changes
Original PR: #2557

@Pankraz76
Copy link
Copy Markdown

nice one, thank you so much.

@iddeepak
Copy link
Copy Markdown
Contributor Author

Most of the work is already done by @Pankraz76. I updated Lint changes on top of it. kindly request your feedback.
@owaiskazi19
@sbrannen
@nedtwigg

@iddeepak iddeepak marked this pull request as ready for review July 22, 2025 18:12
@nedtwigg
Copy link
Copy Markdown
Member

This is close! It needs

  • ReplaceRegexStepTest which should be next to this
  • right now it can only catch the first problem. but it would be easy to catch all of them
    • in the format function, just return the input unchanged, don't throw
    • in the lint function, return multiple lints
    • public interface FormatterFunc {
      String apply(String input) throws Exception;
      default String apply(String unix, File file) throws Exception {
      return apply(unix);
      }
      /**
      * Calculates a list of lints against the given content.
      * By default, that's just an throwables thrown by the lint.
      */
      default List<Lint> lint(String content, File file) throws Exception {
      return List.of();
      }
    • the exception thing is a hack for a formatter which is primarily about formatting. if you are primarily about linting, better to use the other method

int line = 1 + (int) raw.codePoints().limit(matcher.start()).filter(c -> c == '\n').count();
lints.add(atLine(line, matcher.group(0), replacement));
}
return lints;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nedtwigg
spotless:apply for maven does not show lint errors ? for gradle it does.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

aha! you are correct! i will try to fix that problem this week...

Copy link
Copy Markdown

@Pankraz76 Pankraz76 Aug 6, 2025

Choose a reason for hiding this comment

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

is it resolved so we can continue, or is the issue bigger than expected?


public class MavenIntegrationHarness extends ResourceHarness {

protected static final String PATH = "src/main/java/test.java";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undo by inline. Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks

@iddeepak
Copy link
Copy Markdown
Contributor Author

#2455
In maven-plugin too

@Pankraz76
Copy link
Copy Markdown

please let fix this first and have this as second version.

Just fail the build with an bread error like done in open search. The detailed line number can follow afterwards not to block this issue.

@nedtwigg nedtwigg changed the title RemoveWildCardImports Lint issue allow ReplaceRegexStep to function as a Linter, use that to improve RemoveWildcardImports Sep 23, 2025
@nedtwigg nedtwigg enabled auto-merge September 23, 2025 19:35
@nedtwigg nedtwigg merged commit c530176 into diffplug:main Sep 23, 2025
19 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.

3 participants