feat: Implement conversion of diff content to ReviewDog format
Related issue: #655
@nedtwigg
I’m planning to implement this feature in three steps:
- Create the
ReviewDogGeneratorclass - Add a task in the Gradle-plugin that uses the information stored by
ReviewDogGenerator - 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?
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.
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?
I’m curious where actualContext and formattedContent are coming from
actualContentis the file as it existsformattedContentis 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.
I’m curious where actualContext and formattedContent are coming from
actualContentis the file as it existsformattedContentis the formatter version of the fileDepending on the plugin integration, they will come from different places. But I promise they are available! If you build it this way, the
ReviewDogstuff is decoupled fromFormatteretc. You don't have to make fake and irrelevantFormatterinstances 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. 😁
@nedtwigg
Feel free to update the code if you think any changes are necessary. 🚀
@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 :)
@nedtwigg
Hello! Hope you’re having a great day 🙂 When you have some time, would you mind taking a look and sharing your feedback?
Any updates?