-
Notifications
You must be signed in to change notification settings - Fork 388
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
CLDR-15381 Java formatting with prettier, tabWidth 4 #1911
Conversation
-Add package.json with custom setting for .java files: tabWidth 4 -Only java files in tools/cldr-code/src/main/java/org/unicode/cldr/util
@@ -0,0 +1,12 @@ | |||
{ |
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.
it's… a little unusual and confusing to have a package.json at the top level. I think it might misrepresent what structure is underneath.
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.
https://prettier.io/docs/en/configuration.html could we use a .prettierrc.json
file instead?
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.
yes, I think so
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.
I think that might make sense.
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.
see #1919
@@ -1,5 +1,19 @@ | |||
package org.unicode.cldr.util; | |||
|
|||
import com.google.common.base.Joiner; |
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.
is it going to conflict with eclipse and intellij's import structure?
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.
maybe in the same sense that it will conflict with their java formatting in general -- anytime we edit a file, regardless of which IDE or editor we use, we'll need to re-run prettier -- though we might get the IDE/editor to run it automatically, in which case i don't know if the IDE/editor will get in a fight with itself over the imports
"\",\"" + | ||
Joiner.on("|").join(keywords) + | ||
"\"}," | ||
); |
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.
very much expanded
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.
right -- compare this version of the same code in my other PR #1913:
System.out.println(
"{\"" + s + "\",\"" + shortName + "\",\"" + Joiner.on("|").join(keywords) + "\"},"
);
if you like that better, that's an argument for printWidth 100
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.
i was just looking for a width parameter! Yes, let's do printwidth 100
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.
the width is the only real issue i have otherwise lgtm
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.
great, lets see what @macchiati and others think
FYI: there is an eclipse format option that adds braces in if-statements
that don't have them., eg the following. Those kinds of 'more than
formatting' steps would be good to do periodically.
if (msg.length() == 0)
msg = temp;
else if (temp.length() != 0) {
into
if (msg.length() == 0) {
msg = temp;
} else if (temp.length() != 0) {
…On Wed, Apr 13, 2022 at 1:39 PM Tom Bishop ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In package.json
<#1911 (comment)>:
> @@ -0,0 +1,12 @@
+{
yes, I think so
—
Reply to this email directly, view it on GitHub
<#1911 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJLEMGVZHKHMZ6B3O6ZHZ3VE4WHDANCNFSM5TLXHZJA>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
I prefer always to include braces even where optional. This formatter (prettier) doesn't add or remove braces, but as you say, Mark, there's always the option to run a different formatter to add braces, and then run prettier again |
What I found strange is that prettier did make non-whitespace changes in
the text, notably adding () to returns, eg return a+b+c ==> return (a+b+c)
(but not always)
…On Thu, Apr 14, 2022 at 8:05 AM Tom Bishop ***@***.***> wrote:
I prefer always to include braces even where optional. This formatter
(prettier) doesn't add or remove braces, but as you say, Mark, there's
always the option to run a different formatter to add braces, and then run
prettier again
—
Reply to this email directly, view it on GitHub
<#1911 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJLEMEWMVIFP2S7O2VRU23VFAX3TANCNFSM5TLXHZJA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes it's sort of inscrutable and sometimes does things that would never occur to me -- overall, though, I've been really happy with how it works for javascript. When the result is ugly it's sometimes because the original code is too dense, and creation of a new variable or subroutine will make it format better and be more maintainable |
@btangmu is this the same prettier? It doesn't list Java nor options for java. https://prettier.io/docs/en/index.html |
OK… it's a plugin https://github.com/jhipster/prettier-java … looks like there may be some options in https://github.com/jhipster/prettier-java/blob/main/packages/prettier-plugin-java/src/options.js |
it's based on that, as a plugin: npm install -g prettier prettier-plugin-java |
The Unicodetools group is looking at this, and considering incorporating a formatter in the build process. We should coordinate with them. |
Closing, because we should at this point just import the mechanism that the Unicodetools group is using
|
@macchiati maybe, would need consensus on changing all source files and invalidating many in-progress PRs. not impossible, just a bit higher impact than with unicodetools. |
I don't have any in-progress PRs myself currently -- it will be a morale-booster when we do have Java formatting! |
I agree. But also think that a "pull off the bandage" reformatting of all
the source code is by far the cleanest approach. Would take some timing.
…On Wed, Aug 3, 2022 at 11:44 AM Steven R. Loomis ***@***.***> wrote:
@macchiati <https://github.com/macchiati> maybe, would need consensus on
changing all source files and invalidating many in-progress PRs. not
impossible, just a bit higher impact than with unicodetools.
—
Reply to this email directly, view it on GitHub
<#1911 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJLEMDNKVSANPPHJPRZUR3VXK42PANCNFSM5TLXHZJA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
-Add package.json with custom setting for .java files: tabWidth 4
-Only java files in tools/cldr-code/src/main/java/org/unicode/cldr/util
CLDR-15381