-
Notifications
You must be signed in to change notification settings - Fork 455
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
Extension of FormatterFunc accepting source file as parameter. #290
Conversation
Finalized WTP integration into lib-extra.
Strange. According to Travis, some Spotless Eclipse formatters cannot be downloaded. For example spotless-ext-greclipse-2.3.0.pom access fails. Have no problem using Travis Error code is Travis works again. Restarting builds of all affected PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done very elegantly.
My first instinct is that it's bad for FormatterFunc
to take a File
. Allowing access to the File directly is a risky hack, because it means the formatter might read the file from disk, rather than use the "unix input" that is supplied. Reading from disk will break the composability that spotless has currently. That's why the File is currently only actually used by FileFilters.
But the only alternative that I can see is to rebuild all of FormatterStep.createLazy() with a parallel FormatterStepWithFile.createLazy(). But that's a lot of duplicate code - since the code change submitted here is so small, and still encourages FormatterStep authors to use only the String argument because of the default method.
If there were another way, I would definitely prefer that other way, but I can't see it. I would like at least one more opinion from one of the other committers before we merge this though...
Oh, really? I'm not sure I see why. Can you explain things further for me @nedtwigg? 🤔 |
(Once I better understand why reading from the file directly breaks the composability of Spotless, I'd be more than happy to pitch in my own review!) |
Wait, am I right to think that reading from the file directly would break composability because at any given time, the supplied "unix input" could be partially formatted and thus inconsistent with the contents of the original file? |
EDIT: exactly! Didn't see this comment until I already wrote: The data flow in spotless is:
The only thing a step knows is what gets passed to it by the previous step. If a step has a file path, it can ignore its input parameter and just load the content straight from disk. Currently, we only ever use the path to skip applying a step - not to actually implement the formatter itself. This PR will be the first time that a formatter implementation is using the file path to decide how to format the file. spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java Lines 228 to 242 in 366c1b9
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to @nedtwigg, I agree that allowing the original file to be read could be bad (if I understand correctly what he meant by breaking "composability".) However, I also cannot see an easy way around this, so I think this PR is actually okay!
I'm also impressed by how elegant the changes are and how small the changes are. So well done @fvgh!
I would have suggested, as a small nit, that the File
parameter be changed to be a Path
instead. However, I do realise that we use File
and Path
inconsistently throughout Spotless, I think originally because Gradle depends on File
for many of its user-facing APIs including project.file()
. So ultimately I don't mind which of File
and Path
is used.
Cool, thanks @nedtwigg! In that case, my earlier review still stands: consider this PR approved from me. :) |
@nedtwigg And your comment regarding Spotless's data flow/pipeline makes complete sense to me, so cheers for confirming my understanding for me! 👍 |
So all in all, I would propose to stick with the current solution. |
Makes sense to me! I'm happy for |
Extension of FormatterFunc accepting source file as parameter.
Finalized WTP integration into lib-extra which has been started in #279 .