-
Notifications
You must be signed in to change notification settings - Fork 115
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
Format code base #86
Comments
I've found a solution based on option (3) at google/conscrypt (https://github.com/google/conscrypt/blob/c240f160e4346d57d9ba3b0b3c08da687812922f/.travis.yml). I'm currently in the middle of writing up a PR for review. |
(Sorry for the delay.) tl;dr: (1) and (5) sound OK, (3) sounds incomplete but perhaps you have more to say about this. (1) sounds reasonable to me. JUNG isn't required to follow the Google Style Guide. (It also seems plausible that the author of that plugin might accept a PR to add the ability to follow the guide.) And most IDEs are pretty good at reminding people to clean up imports. (2) doesn't sound very useful; I prefer having something that does the formatting to something that tells us how we're violating the expectations. :) (3) might be OK but I'd prefer it if we can do the formatting pass before the PR stage, to make it easier for people to fix any egregious weirdness that the formatter might impose. (4) is basically abandoning the idea of an automated solution. (5) is potentially of interest if there are other significant reasons to use Gradle over Maven. I'm not a big fan of Maven but it does have the nice property that we already have it set up for JUNG, but I'm open to hearing reasons why we should migrate. (Although that should be considered as a separate issue.) |
Yes, I realise I hadn't explained the full story for (3). Allow me to elaborate. Since I wrote up this issue, I discovered that the team at google/conscrypt have apparently found a workaround for google-java-format's lack of verification ability. They seem to be running a Shell script at Travis CI time which runs google-java-format on the codebase and then runs If I understand it correctly, if the error code code is 0, then it means that there are no formatting changes, and thus logically all the code is properly formatted already. However if the error code is 1 (or maybe some other value), then it means that running google-java-format did produce formatting changes, which means google-java-format wasn't run beforehand on the codebase, which logically equates to a failed validation check. I found this solution of theirs here. If this sounds too complicated for you, then I'd be happy to pursue (1) or (5) instead. |
With regards to (5), the two biggest reasons I personally use Gradle over Maven are as follows:
|
Those do sound like nice properties of Gradle, but perhaps not enough to warrant converting the existing Maven setup to use them. (If Guava ever decides to convert over, I may piggyback on their effort.) Regarding the original topic: the approach that (3) is taking seems reasonable. My reservation is that I would prefer that the formatting happen before the code shows up in a pull request, ideally automatically, which is why I favor solutions like (1) and (5). (I'm assuming, perhaps incorrectly, that (3) does not actually modify the pull request itself; does it?) That said, at least having a check at PR time (perhaps using CheckStyle, presuming we can set that up with Travis) might also be useful. So maybe a hybrid of (1)+(2)? |
That's fair enough. It seems more likely to me that Guava will switch to Bazel than Gradle in the future (google/guava#2850). So if anything, Bazel would probably be the way to go for JUNG.
No, AFAICT, (3) doesn't actually modify the PR itself - when it runs google-java-format on Travis and checks if any changes were made, it automatically discards any changes found at the end of the job. So AFAICT, (3) would be similar to options (1) and (5). With options (1) and (5), contributors would need to manually run Similarly, for (3), contributors would need to download & install google-java-format first, and then run Although, having said this, I realise now that asking contributors, especially those running Windows, to go through the kerfuffle needed to format PRs via option (3) would be too restrictive, since it's rather involved and, for Windows, requires a specific setup. Being able to just run |
I'm also open to a hybrid like (1)+(2) if we discover that Checkstyle has a check or two that would be useful for us. |
So (1)[+(2)] looks like the most sensible option to me, even though I personally dislike how it can't order imports and remove unused imports like (3) or (5) can. |
I now have no objections at all to (1), because issue spotify/fmt-maven-plugin#11, which was looking into adding import sorting and unused import removal, has been resolved now. |
Closing since this is resolved as of #114. |
Five potential options:
The text was updated successfully, but these errors were encountered: