-
Notifications
You must be signed in to change notification settings - Fork 460
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
Html/JS/Json integration #315
Conversation
/** | ||
* XML delimiter is also valid for HTML. | ||
*/ | ||
public static final String DELIMITER_EXPR = XmlDefaults.DELIMITER_EXPR; |
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.
For all of these XxxDefaults
classes, it would be better if their constants were public static String delimiterExpr() {}
rather than public static final String DELIMITER_EXPR = ...
. See https://wiki.sei.cmu.edu/confluence/display/java/DCL59-J.+Do+not+apply+public+final+to+constants+whose+value+might+change+in+later+releases for details.
We've had to change quite a few of our DELIMITER_EXPR so far, I'd expect these might need to be revised in the future as well...
My concern is that web projects generally do not have the same constrained layout that JVM projects have. I wonder how many projects will be able to use the default FILE_FILTER arguments - anyone who does use them is going to have to read their documentation first, and they're fairly large constants. An alternative is to do something closer to what we're doing for prettier: format 'js', {
target 'src/main/js/**/*.js'
eclipseWtp(JS) // default version
}
format 'html', {
target 'src/main/html/**/*.htm'
eclipseWtp(HTML, '1.7.0') // specifies version 1.7.0
} My worry is that this PR adds 1,000 lines, and it's mostly boilerplate and defaults. In order for users to get the benefit of these defaults and boilerplate, we have to document it all, and users have to read it all, and even after we've done that work (us devs and them users), I expect most users will still probably have to throw it away and set their own target. And if that's the case, I think we can reduce the size of the code and the docs a ton by using our approach for prettier. What do you think about: public class EclipseWtpFormatterStep {
...
public enum Kind {
CSS, JS, HTML, ...
}
}
public class FormatExtension {
...
public class EclipseWtpConfig {
private final EclipseBasedStepBuilder builder;
EclipseConfig(EclipseWtpFormatterStep.Kind kind, String version) {
builder = EclipseWtpFormatterStep.createBuilder(kind, GradleProvisioner.fromProject(getProject()));
builder.setVersion(version);
addStep(builder.build());
} |
@nedtwigg I have no preferences on this subject. I thought that the outcome of our previous discussion was to provide separate extensions. And since you accepted #311, I thought that this was the final word. What I had in mind when I provided #279, is just one eclipseWtp and that per default Eclipse decides by filename extension. But you are right, there should be also an optional selector. This is really a decision how Spotless configuration shall look like. The separate extensions have the advantage, that you can provide reasonable defaults for different languages. For example I could imagine that the license header can be enhanced, so that the license text does not necessarily contains the language specific comment delimiters. What you propose now is quite close to what I had in mind during #279. Your decision. |
Sorry if I steered you off course :) I'm pretty swamped, but I try really hard to not be the slowpoke that's keeping somebody's hard work form getting merged-in so that they can use it. Seeing the CSS PR on its own, it was a decent hunk of docs, but not a huge amount, so it was easy to merge and release. Seeing the In our previous discussion which you linked, my intent was to emphasize
Since that discussion, prettier has been merged in, and we can see how it gets used in the wild: That approach is easy to read, and it's easy to see exactly what is getting formatted. In the per-format approach with default includes, the user has to read quite a lot in order to tell what is and isn't getting formatted. A casual user of the buildscript, who might not know where the Spotless docs even are, would have a hard time debugging the per-format case, compared to the prettier example that I linked above. In the long term, I think we should
In the short term, if you plan to use these formatters at work, I'm happy to merge this as-is so that you can get on with your formatting, and we can open up an issue to redo them in a more generic way. |
@nedtwigg Afterwards I will mark the XML and CSS as deprecated in a separate PR, whereas I will refer to the new Java methods. In the ReadMe I will remove the sections entirely (since the interfaces shall not be used anymore). Please confirm that it is understood that both extensions should be removed (anything else would make no sense). Agreed? Then we can close this PR. I would like to keep this branch (not the PR) alive until the other two PRs are agreed. |
I agree 100%. Your WTP formatter is so versatile, I think it was
inevitable that we would stumble around a little while we searched for just
the right approach :) Thanks for the valuable prototyping to get here.
|
@nedtwigg I provided a new branch, containing a proposal for WTP formatter configurable via custom target. Let me know what you think about the approach. After we agreed on an implementation, I will:
|
Looks great. I added a commit with some comments: 11147a9 |
PR replaced by #325. |
Providing extension for HTML, JavaScript and JSON.
Gradle and Maven are supported.
Extensions supporting Eclipse-WTP formatter.
Example for
gradle
usage can be found here.