Skip to content

Instructions about source formatter #275

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

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,22 @@ Currently, some tests run on the generated output files of a tool (ex: in order
| UVERSION | 14.0.0 |


### Eclipse-specific Additional Setup
### Editing and tool execution setup

#### Source code formatting

Like other projects, Unicode Tools uses a source formatter to ensure a consistent code style automatically, and it uses a single common formatter to avoid spurious diff noise in code reviews. This is now enforced via a [formatter](https://github.com/google/google-java-format) that is [configured in the Maven build](https://github.com/unicode-org/unicodetools/pull/254) via a [Maven plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven) and checked by continuous integration on pull requests.

When creating pull requests, you can check the formatting locally using the command `mvn spotless:check`. You can apply the formatter's changes using the command `mvn spotless:apply`. Continuous integration errors for formatting can be fixed by committing the changes resulting from applying the formatter locally and pushing the new commit.

Some IDEs can integrate the formatter via plugins, which can minimize the need to manually run the formatter separately. The following links for specific IDEs may work:

* Eclipse: Follow the [instructions](https://source.android.com/devices/tech/test_infra/tradefed/development/eclipse#auto_format) in the "Auto format" section. You can alternatively use this link for [`android-formatting.xml`](https://raw.githubusercontent.com/aosp-mirror/platform_development/master/ide/eclipse/android-formatting.xml).
* VSCode: Follow the [instructions](https://code.visualstudio.com/docs/java/java-linting#_formatter) in "Applying formatter settings", but use the same `android-formatting.xml` link mentioned for Eclipse (ex: `"java.format.settings.url": "https://raw.githubusercontent.com/aosp-mirror/platform_development/master/ide/eclipse/android-formatting.xml",`). Also use the profile name corresponding to that XML file: (ex: `"java.format.settings.profile": "Android",`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried this in VSCode and it "sort of works" -- I tried Format -> Document on a couple of random Java files in the repo and it inserted a blank line at the top of the file. The rest of the formatting rules work fine. Maybe something weird with the VSCode implementation?

* IntelliJ: Use the [official plugin](https://plugins.jetbrains.com/plugin/8527-google-java-format/) for the formatter.


#### Eclipse-specific Additional Setup

1. Follow the Eclipse-specific settings at <http://cldr.unicode.org/development/maven>
1. Edit the cldr-code project’s Build Path:
Expand Down