Skip to content

Commit 35f058a

Browse files
committed
docs(README): touch up readme
1 parent 8d57518 commit 35f058a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@ Very useful in libraries that wrap native java code in javascript
99
1. (optional) `yarn add @invertase/google-java-format` (or `npm -i @invertase/google-java-format` if you prefer)
1010
1. `npx google-java-format <path to java file>`
1111

12-
Please note this wrapper has made the design decision to pass all arguments directly to the underlying tool.
13-
This ensures that we will never have compatibility issues with versions.
12+
All arguments are passed directly to the underlying google-java-format tool, with the exception of `--glob`.
1413

15-
The only exception is globbing multiple files, which we must process to not cause errors with command line arguments being too long
14+
Multiple files as a glob must be pre-processed to avoid errors with command line arguments being too long
1615

1716
### Globbing files
1817

1918
`npx google-java-format -i --glob=folder/**/*.java`
2019

21-
This will run find the matching files and run `google-java-format` on chunks of 30 files at a time, then show the total
20+
This will find the matching files and run `google-java-format` on chunks of 30 files at a time, then show the total
2221
formatted files at the end.
2322

2423
See [node-glob](https://github.com/isaacs/node-glob) for globbing semantics.
2524

25+
### Auto-format
26+
27+
Use the `-i` or `--replace` argument to format the files by re-writing instead of printing the changes to stdout:
28+
29+
`npx google-java-format -i --glob=folder/**/*.java`
30+
2631
### Dry-run
2732

2833
To just check files use the `-n` (or `--dry-run`) parameter:
@@ -35,20 +40,32 @@ To just check files use the `-n` (or `--dry-run`) parameter:
3540

3641
May be wrapped in git pre-commit if desired, there are [examples on line](https://github.com/justinludwig/gjfpc-hook) demonstrating this
3742

38-
If you would like to contribute a pre-commit hook, perhaps one that is Husky-compatible, that would be great! Open a PR with the hook and remove this comment 🙏😊
43+
If you would like to contribute a pre-commit hook, perhaps one that is Husky-compatible, that would be great! Open a PR with the hook and remove this comment :-)
3944

4045
### Github Actions
4146

4247
May be used in GitHub Actions workflows to verify PRs meet formatting standards,
43-
as done in [Invertase](https://invertase.io) [react-native-firebase](https://github.com/Invertase/react-native-firebase/)
48+
as done in [Invertase](https://invertase.io) [react-native-firebase](https://github.com/Invertase/react-native-firebase/), specifically this `package.json` run script is called in a CI job and sets exit status correctly to fail the job if there are formatting inconsistencies found:
49+
50+
```json
51+
// ...
52+
"scripts": {
53+
// ...
54+
"lint:android": "google-java-format --set-exit-if-changed --replace --glob=\"packages/**/android/**/*.java\"",
55+
// ...
56+
},
57+
// ...
58+
```
59+
60+
Something like that (with a glob that matches your java file roots) could work for you
4461

4562
## Inspiration
4663

4764
The wonderful [clang-format](https://github.com/angular/clang-format) from the Angular team is so useful, we wanted the same package for java formatting.
4865

4966
That package already solves so many of the little problems that occur with different platforms, and globbing etc - it's fantastic.
5067

51-
Go to [their repo](https://github.com/angular/clang-format), integrate it for objective-c code, and give them a ⭐, they have earned it. Thanks for the code + inspiration Angular community!
68+
Go to [their repo](https://github.com/angular/clang-format), integrate it for objective-c code, and give them a star! They have earned it. Thanks for the code + inspiration Angular community!
5269

5370
## Contributing
5471

0 commit comments

Comments
 (0)