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

ignore Eclipse files + incremental 4-space indent Java formatter #254

Merged
merged 19 commits into from
Jun 15, 2022

Conversation

echeran
Copy link
Contributor

@echeran echeran commented May 16, 2022

Based on previous discussion about #217, if we start ignoring Eclipse project settings dot files/folders in the codebase, we may also lose consistent source formatting (for those who use Eclipse).

Before progressing, we wanted to see if we could also handle source code style & formatting functionality in an IDE-agnostic way (while still having Eclipse support). This is similar to what we have done using Maven for build functionality.

This PR adds a couple of commits on top of #217 to add a Java source formatter that supports 4-space indents, and it only applies itself to files in a PR branch that have been changed (relative to the latest state of the codebase in the upstream repo).

This PR is a cleaned up version of echeran#5, whose checks pass. Also, a negative test PR echeran#6 adds a commit to its branch which touches a single file to create 2-space indents, and the checks fail.

pom.xml Outdated
- Apply Spotless to specific files: https://github.com/diffplug/spotless/tree/main/plugin-maven#can-i-apply-spotless-to-specific-files
-->
<plugin>
<groupId>com.diffplug.spotless</groupId>
Copy link
Member

Choose a reason for hiding this comment

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

Indentation in this file: Please stay consistent, and don't use tabs. 4 spaces??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Fixed the inconsistent indentation.

That being said... since the rest of the file is using tabs, I made one commit to make the indentation consistent with the tab-based indents. The subsequent commit converts the entire file from tabs to spaces.

It seems that multiple *.xml files in the repo use tabs, not spaces. Interested in adding a 4-space indent rule for certain files to the formatter / style checker?

Copy link
Member

Choose a reason for hiding this comment

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

It seems that multiple *.xml files in the repo use tabs, not spaces. Interested in adding a 4-space indent rule for certain files to the formatter / style checker?

Yes, I think so.

@josh-hadley it looks like the tab checker does not look at XML files?

We probably can't enforce much about .txt files. Or maybe none of them even use indentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, tab checker only looks at files ending with .java. Easy enough to add XML or others if desired.

Copy link
Member

Choose a reason for hiding this comment

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

our xml files [pom.xml, build.xml, all cldr data files] have traditionally used tabs. Is there a reason to change?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like icu4j's build.xml uses spaces, though

Copy link
Member

Choose a reason for hiding this comment

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

Tabs are generally trouble because there is not a standard advance width for them. Many tools default to tab stops every 8 columns, but some people set some of their tools to 4, and when files use a mix of tabs and spaces (which often happens) the indentation is all messed up in one editor / code review tool or another. Or indentation with tabs and vertically aligned comments at the ends of lines. That's why we try to avoid tabs.

pom.xml Outdated Show resolved Hide resolved
Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

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

generally lgtm with comments

# for the git remote name for unicode-org/unicodetools?
- name: Fetch git branches for unicode-org/unicodetools
run: |
git fetch origin
Copy link
Member

Choose a reason for hiding this comment

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

why is this a separate step? is it because actions/checkout has fetch-depth: 1 by default?

Copy link
Member

Choose a reason for hiding this comment

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

or is this a different fetch than the PR's fetch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for pointing out the fetch-depth config for actions/checkout, I'm using that instead. The reason for having the git fetch in the first place is because of the Spotless configuration for the "ratchet" feature that only checks formatting diffs to modified files in the PR (and it needs the reference point origin/main to diff and grok what's in the PR).... however, we are leaning towards having a single big bang change globally for formatting, which will remove noise from future PRs by allowing those future PRs to only spotlight the changed lines of interest. That makes sense, and would obviate the need for the ratchet feature.

@echeran echeran marked this pull request as ready for review June 14, 2022 18:48
@echeran echeran requested a review from srl295 June 14, 2022 18:48
@echeran
Copy link
Contributor Author

echeran commented Jun 14, 2022

I've updated this PR to include both: 1) adding the Eclipse project files to .gitignore, and 2) a) the formatter configs in CI + b) large initial application of the formatter to all files. The PR already includes the latest from upstream.

Note: One detail that I encountered is that one of the CI jobs to auto run tools for smoke test purposes runs a tool (GenerateEnums) that generates some source code, and then does a diff, according to documented instructions, to ensure changes are committed. So in that CI job, the formatter needs to be applied after GenerateEnums regenerates source code but before the git diff test occurs.

The main files to look at should be the root pom.xml and .github/workflows/ci-build-instructions.yml -- these control the changes. The rest of the changes are derivative due to formatting, but within that set, maybe unicodetools/src/main/java/org/unicode/props/UcdPropertyValues.java is interesting as one of the files generated by GenerateEnums.

Copy link
Member

@macchiati macchiati left a comment

Choose a reason for hiding this comment

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

I haven't looked over all the files, but did do some spot checks, and looks good to me.

@echeran echeran merged commit 70dce2c into unicode-org:main Jun 15, 2022
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.

None yet

5 participants