Coder Social home page Coder Social logo

prettier-java's Introduction

Github Actions Build Status

Prettier Java

Prettier-java Banner

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

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:

Install

Pre-requirements

Install Prettier and Prettier-Java plugin

# Local installation
npm install prettier-plugin-java --save-dev

# Or globally
npm install -g prettier prettier-plugin-java

or with yarn:

# Local installation
yarn add prettier-plugin-java --dev

# Or globally
yarn global add prettier prettier-plugin-java

Note: If you want to install the prettier-plugin-java globally, you should also install the prettier package globally.

Usage

To reformat all your Java files, run:

# If you have installed the package locally
npx prettier --write "**/*.java"

# Or globally
prettier --write "**/*.java"

To see an advanced usage: please go to the Advanced Usage section

Maven plugin

A neat maven plugin for prettier-java was made by developers from HubSpot.
Add it to the plugins section of your build configuration

<build>
  <plugins>
    <plugin>
      <groupId>com.hubspot.maven.plugins</groupId>
        <artifactId>prettier-maven-plugin</artifactId>
        <!-- Find the latest version at https://github.com/jhipster/prettier-java/releases -->
        <version>0.8</version>
    </plugin>
  </plugins>
</build>

If you would like to use this plugin, we recommend you to check their project as is it well documented.

Organize imports

Prettier-java is currently sorting imports according to the Google Java Style guide.

If you are using an IDE such as IntelliJ, you might want to configure it to match with Prettier-java.

For IntelliJ, you can use this configuration: IntelliJ config

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.

We would also like to thank the Chevrotain and Prettier contributors which made this possible.

prettier-java's People

Contributors

azz avatar bd82 avatar clementdessoude avatar danielfran avatar dependabot[bot] avatar fauxfaux avatar graham42 avatar hawkurane avatar iamandrewluca avatar jdubois avatar jhaber avatar lipis avatar maxfie1d avatar pascalgrimaud avatar ruddell avatar shaolans avatar shepherdjerred avatar sudharakap avatar victornoel 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.