-
Notifications
You must be signed in to change notification settings - Fork 458
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
Allow custom separator for years in license header #199
Conversation
Great, thanks! A few issues:
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java Lines 38 to 65 in 115aa61
|
Thanks for the quick feedback. Yes, I don't mind using the pattern used for
or allow multiple calls to update the same object
but none of these solutions seem idiomatic Gradle configurations (or maybe I misunderstood how the |
ScalaFmtConfig is the builder pattern, exactly as your example. Here's another place it's used: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java Lines 118 to 143 in 115aa61
What's different about it compared to a regular builder is that the "build()" is implicit. |
I think I understand what you mean, it's a builder in the sense that one can configure one property after having created the configuration object. However, in order to really follow a builder or fluent style, individual methods of the config objects must return "this" so that calls can be chained (especially since a new Instance of the config object is created if the method if googleJavaFormat is called again). Anyways, I've updated the PR to follow this style (Again, I would like to point out that this does not appear to be a very idiomatic way to do it in Gradle). |
Great! The steps that I linked have only one entry point and one optional second argument, so there's no need for chaining. Looks like the license header is gonna be growing as people need new features for it, so there'll be a need to return |
if (licenseHeaderExtension != null) { | ||
licenseHeaderExtension.setupTask(task); | ||
if (licenseHeaderConfig != null) { | ||
licenseHeaderConfig.setupTask(this, task); | ||
} | ||
task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> task.target)); |
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.
Order matters for FormatterStep. e.g. if I have a license with trailing whitespace, I'll get a different result if I trim whitespace then apply the license, vs apply the license then trim whitespace. Currently, the order that you declare steps is the order that they all happen (which is the rationale behind the weird "replaceStep()" in the examples I linked. This approach allows you to not have a licenseHeaderConfig object.
After fixing this, just squash the commits and update the CHANGES.md and we should be good to go.
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.
Ok, I've updated the PR to include the CHANGES and fully follow the existing "config object pattern" including the replaceStep() logic.
Again thanks for the feedback and very impressive response times.
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.
Found a few things I missed before. Once these are fixed I'll be ready to merge.
|
||
/** | ||
* @param delimiter | ||
* Spotless will look for a line that starts with this to know what the "top" is. |
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.
Spotless will look for the first match to this regex to what the "top" is.
See the kotlin separator for an example of why it has to be a regex.
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.
Clarified the (pre-existing) comment
String delimiter; | ||
|
||
static final String DEFAULT_LICENSE_YEAR_DELIMITER = "-"; | ||
String yearSeparator = DEFAULT_LICENSE_YEAR_DELIMITER; |
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 default should be moved to LicenseHeaderStep.
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.
Try to match this style:
spotless/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java
Lines 77 to 79 in 115aa61
public static String defaultVersion() { | |
return DEFAULT_VERSION; | |
} |
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.
done
private static final String LICENSE_HEADER_DELIMITER = "package "; | ||
private static final String LICENSE_YEAR_DELIMITER = "-"; | ||
|
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.
Rather than introducing changes to the tests, it would be better to use the backward-compatible LicenseHeaderStep. Not a big deal, fine to leave these as they are, just a tip for the future. When adding a feature, if you can add a default parameter and thus avoid changing a bunch of tests, just add a default parameter. The less things change, the easier it is for code-reviewers to verify that there aren't regressions.
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.
done
Can you click |
I very, very much agree with this. I actually spotted the corresponding piece of code a couple of hours or so ago, so thanks for addressing it for me @nedtwigg! :) |
If you care about license headers, you should checkout our new |
I've recently noticed the support for YEAR templates in license headers.
Unfortunately our code doesn't use the hyphen character but coma to separate year ranges (for example https://github.com/delphix/delphix-os/blob/a0f0d0dd2ed6832f0cca929a44b71bd8f33fee32/usr/src/uts/common/fs/zfs/dmu_zfetch.c#L27)
In this review, we are adding support in the library and gradle-plugin to configure the separator.
Instead of adding a third optional argument to the licenseHeader/licenseHeaderFile gradle configurations, we're creating a license header extension object which can be used as
However, both because most users won't need the advanced configuration and for backwards compatibility, we're maintaining support for the the existing syntax (the implementation always creates the extension, but that is transparent to users).
We've updated the Gradle plugin README.md to document and new feature and provide examples of both the simple (one line) and advanced (with licenseHeader extension) syntaxes.
We've updated the unit test for the license header step to cover the new feature, and updated the KotlinExtensionTest to cover the new gradle syntax (It appears that this is the only test covering the license header in the gradle plugin).