GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - feedly/prettier-java: Prettier Java Plugin

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

726 Commits
726 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
benchmark/java-parser
benchmark/java-parser
 
 
docs
docs
 
 
logo
logo
 
 
packages
packages
 
 
scripts
scripts
 
 
website
website
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.yaml
.prettierrc.yaml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
NOTICE
NOTICE
 
 
README.md
README.md
 
 
RELEASE.md
RELEASE.md
 
 
eslint.config.mjs
eslint.config.mjs
 
 
lerna.json
lerna.json
 
 
package.json
package.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

Github Actions Build Status

Prettier Java

Prettier Java Banner 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:

  • prettier-plugin-java A plugin for Prettier to format Java code

    npm-prettier-plugin-java

  • java-parser A Java Parser using Chevrotain which output a Concrete Syntax Tree

    npm-java-parser

Install

Pre-requirements

  • Node version 10+
  • Prettier

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, you first need to create .prettierrc.yaml with following content:

plugins:
  - prettier-plugin-java

Then run:

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

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

To see IDE configuration or other 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

You can also import the Checkstyle configuration provided in the next section.

For VSCode with Language Support for Java, you can use this configuration (settings.json):

{
  "java.completion.importOrder": ["#"]
}

Checkstyle configuration

You can use Prettier in combination with other linter, like Checkstyle.

Here is one Checkstyle Prettier compatible configuration you can use to start with !

You can directly import the config into IntelliJ Idea for instance:

Import Checkstyle configuration

Indent configuration

In .prettierrc.yaml, you can configure the indent:

For using four spaces:

tabWidth: 4

For more configuration options such as using tabs, maximum line length, and more see https://prettier.io/docs/en/configuration.html.

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.

About

Prettier Java Plugin

www.jhipster.tech/prettier-java/

Resources

Readme
License

Code of conduct

Code of conduct

Contributing

Contributing
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.