Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

btangmu
Copy link
Member

@btangmu btangmu commented Apr 13, 2022

-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

  • This PR completes the ticket.

-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
@btangmu btangmu requested review from macchiati and srl295 and removed request for macchiati April 13, 2022 20:14
@btangmu btangmu self-assigned this Apr 13, 2022
@btangmu btangmu requested a review from macchiati April 13, 2022 20:16
@@ -0,0 +1,12 @@
{
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think so

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

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) +
"\"},"
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very much expanded

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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

@macchiati
Copy link
Member

macchiati commented Apr 14, 2022 via email

@btangmu
Copy link
Member Author

btangmu commented Apr 14, 2022

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

@macchiati
Copy link
Member

macchiati commented Apr 14, 2022 via email

@btangmu
Copy link
Member Author

btangmu commented Apr 14, 2022

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)

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

@srl295
Copy link
Member

srl295 commented Apr 14, 2022

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)

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

@srl295
Copy link
Member

srl295 commented Apr 14, 2022

@btangmu
Copy link
Member Author

btangmu commented Apr 14, 2022

@btangmu is this the same prettier? It doesn't list Java nor options for java. https://prettier.io/docs/en/index.html

it's based on that, as a plugin:

npm install -g prettier prettier-plugin-java

https://www.npmjs.com/package/prettier-plugin-java

@macchiati
Copy link
Member

The Unicodetools group is looking at this, and considering incorporating a formatter in the build process. We should coordinate with them.

@macchiati
Copy link
Member

Closing, because we should at this point just import the mechanism that the Unicodetools group is using

The Unicodetools group is looking at this, and considering incorporating a formatter in the build process. We should coordinate with them.

@macchiati macchiati closed this Aug 3, 2022
@srl295
Copy link
Member

srl295 commented Aug 3, 2022

@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.

@btangmu
Copy link
Member Author

btangmu commented Aug 3, 2022

I don't have any in-progress PRs myself currently -- it will be a morale-booster when we do have Java formatting!

@macchiati
Copy link
Member

macchiati commented Aug 3, 2022 via email

@btangmu btangmu deleted the t15381_d branch September 23, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants