spotless icon indicating copy to clipboard operation
spotless copied to clipboard

feat: Implement conversion of diff content to ReviewDog format

Open YongGoose opened this issue 7 months ago • 8 comments

Related issue: #655

YongGoose avatar May 09 '25 13:05 YongGoose

@nedtwigg

I’m planning to implement this feature in three steps:

  1. Create the ReviewDogGenerator class
  2. Add a task in the Gradle-plugin that uses the information stored by ReviewDogGenerator
  3. Write test codes

This https://github.com/diffplug/spotless/pull/2478/commits/dc52b26fa9f66952d1a5371612c1dd809edbf376 includes only the implementation of step 1.

Also, I have a question!

After ReviewDogGenerator generates a diff for ReviewDog, I’d like to store that information in a separate directory (like SpotlessTaskImpl does). However, it seems that classes from gradle.api can’t be used within the lib-extra directory.

Would you be able to offer some guidance on this?

YongGoose avatar May 11 '25 06:05 YongGoose

Here is my suggestion:

class ReviewDog {
  public static String rdjsonlDiff(String path, String actualContent, String formattedContent)
  public static String rdjsonlLints(String path, String formattedContent, List<FormatterStep> steps, List<List<Lint>> lintsPerStep)
}

You can test this easily in lib-extra

class ReviewDogTest {
  @Test
  public void diffSingleLine() {
    expectSelfie(ReviewDog.rdjsonlDiff("test.txt", "dirty", "clean")).toBe_TODO()
  }
  ... etc
}

So you can build and test the ReviewDog features in isolation, no gradle API required. Once these are working, you can pipe them together in a Gradle task.

nedtwigg avatar May 12 '25 20:05 nedtwigg

Here is my suggestion:

class ReviewDog {
  public static String rdjsonlDiff(String path, String actualContent, String formattedContent)
  public static String rdjsonlLints(String path, String formattedContent, List<FormatterStep> steps, List<List<Lint>> lintsPerStep)
}

Sorry for the late reply.

Would you mind explaining the purpose of the ReviewDog class? I’m still having a bit of trouble understanding it. To be more specific, I’m curious where actualContext and formattedContent are coming from.

Would it be correct to understand this test as one meant to verify the functionality in isolation?

YongGoose avatar May 16 '25 11:05 YongGoose

I’m curious where actualContext and formattedContent are coming from

  • actualContent is the file as it exists
  • formattedContent is the formatter version of the file

Depending on the plugin integration, they will come from different places. But I promise they are available! If you build it this way, the ReviewDog stuff is decoupled from Formatter etc. You don't have to make fake and irrelevant Formatter instances to test it.

nedtwigg avatar May 21 '25 03:05 nedtwigg

I’m curious where actualContext and formattedContent are coming from

  • actualContent is the file as it exists
  • formattedContent is the formatter version of the file

Depending on the plugin integration, they will come from different places. But I promise they are available! If you build it this way, the ReviewDog stuff is decoupled from Formatter etc. You don't have to make fake and irrelevant Formatter instances to test it.

Based on the comments, I removed the internal formatter and refactored it into a utility class. PTAL ⚡️

Since I had worked on it previously, I was able to make the changes quickly. 😁

YongGoose avatar May 21 '25 04:05 YongGoose

@nedtwigg

Feel free to update the code if you think any changes are necessary. 🚀

YongGoose avatar May 21 '25 04:05 YongGoose

@nedtwigg

I've added an initial version of the README. https://github.com/diffplug/spotless/pull/2478/commits/e7015dff40582a22f3ceb6b408bd46c2d3402915 I think the gradle code will need to be updated after we complete the implementation.

Please take a look :)

YongGoose avatar May 21 '25 06:05 YongGoose

@nedtwigg

Hello! Hope you’re having a great day 🙂 When you have some time, would you mind taking a look and sharing your feedback?

YongGoose avatar Jun 01 '25 02:06 YongGoose

Any updates?

YongGoose avatar Jun 19 '25 01:06 YongGoose