Giter Site home page Giter Site logo

react-native-firebase / google-java-format Goto Github PK

View Code? Open in Web Editor NEW

This project forked from invertase/nodejs-google-java-format

0.0 1.0 0.0 2.86 MB

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

License: Apache License 2.0

JavaScript 74.58% Shell 23.03% Java 2.39%

google-java-format's Introduction

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 @invertase/google-java-format (or npm -i @invertase/google-java-format if you prefer)
  2. npx 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 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 google-java-format -i --glob=folder/**/*.java

Dry-run

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

npx 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


Built and maintained by Invertase.

google-java-format's People

Contributors

mikehardy avatar salakar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.