Installations
npm install java-parser
Releases
2.6.5
Published on 25 Oct 2024
2.6.4
Published on 12 Jul 2024
2.6.0
Published on 22 Feb 2024
v2.5.0
Published on 26 Nov 2023
v2.4.0
Published on 12 Nov 2023
v2.3.1
Published on 04 Sept 2023
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
21.1.0
NPM Version
lerna/8.1.2/node@v21.1.0+x64 (darwin)
Statistics
1,106 Stars
721 Commits
104 Forks
22 Watching
1 Branches
65 Contributors
Updated on 27 Nov 2024
Languages
Java (39.77%)
JavaScript (29.89%)
TypeScript (28.32%)
CSS (1.45%)
HTML (0.46%)
MDX (0.08%)
Shell (0.04%)
Total Downloads
Cumulative downloads
Total Downloads
25,742,334
Last day
-26.1%
52,332
Compared to previous day
Last week
2.1%
305,045
Compared to previous week
Last month
45.3%
1,283,422
Compared to previous month
Last year
80.1%
11,270,760
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Prettier Java
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
-
java-parser A Java Parser using Chevrotain which output a Concrete Syntax Tree
Install
Pre-requirements
- Node version 10+
- Prettier
Install Prettier and Prettier-Java plugin
1# Local installation 2npm install prettier-plugin-java --save-dev 3 4# Or globally 5npm install -g prettier prettier-plugin-java
or with yarn:
1# Local installation 2yarn add prettier-plugin-java --dev 3 4# Or globally 5yarn 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:
1plugins: 2 - prettier-plugin-java
Then run:
1# If you have installed the package locally 2npx prettier --write "**/*.java" 3 4# Or globally 5prettier --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
1<build> 2 <plugins> 3 <plugin> 4 <groupId>com.hubspot.maven.plugins</groupId> 5 <artifactId>prettier-maven-plugin</artifactId> 6 <!-- Find the latest version at https://github.com/jhipster/prettier-java/releases --> 7 <version>0.8</version> 8 </plugin> 9 </plugins> 10</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:
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
):
1{ 2 "java.completion.importOrder": ["#"] 3}
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:
Indent configuration
In .prettierrc.yaml
, you can configure the indent:
For using four spaces:
1tabWidth: 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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
18 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/jhipster/.github/SECURITY.md:1
- Info: Found linked content: github.com/jhipster/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/jhipster/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/jhipster/.github/SECURITY.md:1
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/copyright-update.yml:12
- Warn: no topLevel permission defined: .github/workflows/binaries.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/copyright-update.yml:7
- Warn: no topLevel permission defined: .github/workflows/github-ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/github-pages-deploy.yml:1
- Warn: no topLevel permission defined: .github/workflows/github-pages-test.yml:1
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact prettier-plugin-java@2.6.0 not signed: https://api.github.com/repos/jhipster/prettier-java/releases/143142685
- Warn: release artifact prettier-plugin-java@2.6.0 does not have provenance: https://api.github.com/repos/jhipster/prettier-java/releases/143142685
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/binaries.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/binaries.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/binaries.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/binaries.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/binaries.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/binaries.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/binaries.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/binaries.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/copyright-update.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/copyright-update.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/copyright-update.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/copyright-update.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-ci.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-deploy.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-deploy.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-deploy.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-deploy.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-deploy.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-deploy.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-deploy.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-deploy.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/github-pages-test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/jhipster/prettier-java/github-pages-test.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/binaries.yml:24
- Warn: npmCommand not pinned by hash: .github/workflows/binaries.yml:28
- Warn: npmCommand not pinned by hash: .github/workflows/binaries.yml:31
- Warn: npmCommand not pinned by hash: .github/workflows/binaries.yml:43
- Info: 0 out of 16 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 4 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 23 are checked with a SAST tool
Score
5
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More