npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@willh/google-java-format

v0.1.0

Published

node wrapper around google-java-format

Downloads

3

Readme

google-java-format

Node repackaging of Google's native google-java-format tool

Very useful in libraries that wrap native java code in javascript

Usage Example

  1. (optional) yarn add google-java-format (or npm -i google-java-format if you prefer)
  2. npx @willh/google-java-format <path to java file>

All arguments are passed directly to the underlying google-java-format tool, with the exception of --glob.

Multiple files as a glob must be pre-processed to avoid errors with command line arguments being too long

Globbing files

npx @willh/google-java-format -i --glob=folder/**/*.java

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

See node-glob for globbing semantics.

Auto-format

Use the -i or --replace argument to format the files by re-writing instead of printing the changes to stdout:

npx @willh/google-java-format -i --glob=folder/**/*.java

Dry-run

To just check files use the -n (or --dry-run) parameter:

npx @willh/google-java-format -n --glob=folder/**/*.java

Integrations

Pre-commit

May be wrapped in git pre-commit if desired, there are examples on line demonstrating this

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 :-)

Github Actions

May be used in GitHub Actions workflows to verify PRs meet formatting standards, as done in 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:

  // ...
  "scripts": {
    // ...
    "lint:android": "google-java-format --set-exit-if-changed --replace --glob=\"packages/**/android/**/*.java\"",
    // ...
  },
  // ...

Something like that (with a glob that matches your java file roots) could work for you

Inspiration

The wonderful clang-format from the Angular team is so useful, we wanted the same package for java formatting.

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

Go to their repo, integrate it for objective-c code, and give them a star! They have earned it. Thanks for the code + inspiration Angular community!

Contributing

License