Skip to content

nonomoho/prettier-java

 
 

🚧 Work in Progress! 🚧

Azure DevOps Build Status Build Status

Prettier Java

Prettier Banner

How it works

A Prettier plugin must first parse the source code of the target language into a traversable data structure (Usually an Abstract Syntax Tree) and then print out that data structure in a "pretty" style.

Prettier-Java uses a Java-Parser implemented in JavaScript using the Chevrotain Parser Building Toolkit for JavaScript. What this means is that unlike many other Prettier plugins, prettier-java has no additional runtime pre-requisites (e.g: Python executable). It could even be used inside a browser.

Subpackages

This project contains 2 packages:

Status

  • Parser package alpha version done, it can parse most of Java code. However, we still need to make some tweaks and improvements.
  • The printer (actually prettier-java package) is mostly done, it can output formatted code but needs to be improved on some cases.

Install

Pre-requirements

Since the plugin is meant to be used with Prettier, you need to install it:

npm install -g prettier

or

yarn global add prettier

Install plugin

npm install -g prettier-plugin-java

or

yarn global add prettier-plugin-java

Usage

prettier --write MyJavaFile.java

If the plugin is not automatically loaded:

# Example where the plugin is locate in node_modules
prettier --write MyJavaFile.java --plugin=./node_modules/prettier-plugin-java

Contributing

Contributions are very welcome. See the contribution guide to get started. And the Help Wanted issues.

Credits

Special thanks to @thorbenvh8 for creating the original prettier-java plugin and the associated Java Parser implemented in JavaScript.

About

Prettier Java Plugin

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 62.7%
  • Java 34.6%
  • CSS 1.9%
  • Other 0.8%