prettier-plugin-java 2.8.1 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +42 -102
  2. package/dist/index.cjs +2215 -0
  3. package/dist/index.d.cts +1630 -0
  4. package/dist/index.d.mts +1633 -0
  5. package/dist/index.mjs +2215 -0
  6. package/dist/tree-sitter-java_orchard.wasm +0 -0
  7. package/package.json +62 -24
  8. package/dist/comments.d.ts +0 -17
  9. package/dist/comments.js +0 -229
  10. package/dist/index.d.ts +0 -563
  11. package/dist/index.js +0 -29
  12. package/dist/options.d.ts +0 -43
  13. package/dist/options.js +0 -284
  14. package/dist/parser.d.ts +0 -9
  15. package/dist/parser.js +0 -24
  16. package/dist/printer.d.ts +0 -18
  17. package/dist/printer.js +0 -40
  18. package/dist/printers/arrays.d.ts +0 -9
  19. package/dist/printers/arrays.js +0 -9
  20. package/dist/printers/blocks-and-statements.d.ts +0 -117
  21. package/dist/printers/blocks-and-statements.js +0 -340
  22. package/dist/printers/classes.d.ts +0 -157
  23. package/dist/printers/classes.js +0 -485
  24. package/dist/printers/expressions.d.ts +0 -134
  25. package/dist/printers/expressions.js +0 -627
  26. package/dist/printers/helpers.d.ts +0 -73
  27. package/dist/printers/helpers.js +0 -273
  28. package/dist/printers/index.d.ts +0 -2
  29. package/dist/printers/index.js +0 -13
  30. package/dist/printers/interfaces.d.ts +0 -62
  31. package/dist/printers/interfaces.js +0 -175
  32. package/dist/printers/lexical-structure.d.ts +0 -14
  33. package/dist/printers/lexical-structure.js +0 -29
  34. package/dist/printers/names.d.ts +0 -12
  35. package/dist/printers/names.js +0 -11
  36. package/dist/printers/packages-and-modules.d.ts +0 -46
  37. package/dist/printers/packages-and-modules.js +0 -169
  38. package/dist/printers/types-values-and-variables.d.ts +0 -46
  39. package/dist/printers/types-values-and-variables.js +0 -90
package/README.md CHANGED
@@ -1,80 +1,18 @@
1
- [![npm](https://img.shields.io/npm/v/prettier-plugin-java.svg)](https://www.npmjs.com/package/prettier-plugin-java)
1
+ [![Prettier Java Banner](https://raw.githubusercontent.com/jhipster/prettier-java/main/logo/prettier-java-banner-light.svg)](https://www.jhipster.tech/prettier-java/)
2
2
 
3
- # prettier-plugin-java
3
+ # Prettier Java Plugin
4
4
 
5
- ![Prettier Java Banner](https://raw.githubusercontent.com/jhipster/prettier-java/main/logo/prettier-java-banner-light.svg)
5
+ [![CI Status](https://img.shields.io/github/actions/workflow/status/jhipster/prettier-java/github-ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/jhipster/prettier-java/actions/workflows/github-ci.yml?query=branch%3Amain) [![npm version](https://img.shields.io/npm/v/prettier-plugin-java.svg?style=flat-square)](https://www.npmjs.com/package/prettier-plugin-java) [![weekly downloads from npm](https://img.shields.io/npm/dw/prettier-plugin-java.svg?style=flat-square)](https://www.npmjs.com/package/prettier-plugin-java) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier#badge)
6
6
 
7
- Prettier is an opinionated code formatter which forces a certain coding style. It makes the code consistent through an entire project.
7
+ ## Intro
8
8
 
9
- This plugin allows the support of Java on Prettier.
9
+ 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.
10
10
 
11
- The plugin implementation is pretty straightforward as it uses [java-parser](../java-parser) (thanks to Chevrotain) visitor to traverse the **C**oncrete **S**yntax **T**ree and apply the format processing on each node (it uses Prettier API).
12
-
13
- ## Installation
14
-
15
- ### Pre-requirements
16
-
17
- Since the plugin is meant to be used with Prettier, you need to install it:
18
-
19
- `npm install --save-dev --save-exact prettier`
20
-
21
- or
22
-
23
- `yarn add prettier --dev --exact`
24
-
25
- ### Install plugin
26
-
27
- `npm install prettier-plugin-java --save-dev`
28
-
29
- or
30
-
31
- `yarn add prettier-plugin-java --dev`
32
-
33
- ### CLI
34
-
35
- If you installed Prettier globally and want to format java code via the CLI, run the following command:
36
-
37
- `npm install -g prettier-plugin-java`
38
-
39
- The plugin will be automatically loaded, check [here](https://prettier.io/docs/en/plugins.html#using-plugins) for more.
40
-
41
- ## Usage
42
-
43
- ### CLI
44
-
45
- ```bash
46
- prettier --write MyJavaFile.java
47
- ```
48
-
49
- If the plugin is not automatically loaded:
50
-
51
- ```bash
52
- # Example where the plugin is locate in node_modules
53
- prettier --write MyJavaFile.java --plugin=./node_modules/prettier-plugin-java
54
- ```
55
-
56
- ### API
57
-
58
- ```javascript
59
- const prettier = require("prettier");
60
- const javaText = `
61
- public class HelloWorldExample{
62
- public static void main(String args[]){
63
- System.out.println("Hello World !");
64
- }
65
- }
66
- `;
67
-
68
- const formattedText = prettier.format(javaText, {
69
- parser: "java",
70
- tabWidth: 2
71
- });
72
- ```
73
-
74
- ## Example of formatted code
11
+ This plugin adds support for the Java language to Prettier.
75
12
 
76
13
  ### Input
77
14
 
15
+ <!-- prettier-ignore -->
78
16
  ```java
79
17
  public class HelloWorld {
80
18
  public static void main(String[] args) {System.out.println("Hello World!");;;;;}
@@ -116,43 +54,45 @@ public class HelloWorld {
116
54
  }
117
55
  ```
118
56
 
119
- ## Options
120
- We added a custom option ```entrypoint``` in order to run prettier on code snippet.
57
+ ### Playground
58
+
59
+ You can give the plugin a try in our [playground](https://www.jhipster.tech/prettier-java/playground)!
60
+
61
+ ## Getting Started
62
+
63
+ ### Installation
64
+
65
+ npm:
66
+
67
+ ```shell
68
+ npm install --save-dev --save-exact prettier prettier-plugin-java
69
+ ```
70
+
71
+ Yarn:
72
+
73
+ ```shell
74
+ yarn add --dev --exact prettier prettier-plugin-java
75
+ ```
121
76
 
122
77
  ### Usage
123
- ```prettier --write MyJava.java --entrypoint compilationUnit``` \
124
- [Here](https://github.com/jhipster/prettier-java/blob/main/packages/prettier-plugin-java/src/options.js) is the exhaustive list of all entrypoints.
125
78
 
126
- ### Example
127
- MyJavaCode.java content:
128
- ```java
129
- public void myfunction() {
130
- mymethod.is().very().very().very().very().very().very().very().very().very().very().very().very().very().very().big();
131
- }
79
+ npm:
80
+
81
+ ```shell
82
+ npx prettier --plugin=prettier-plugin-java --write "**/*.java"
132
83
  ```
133
84
 
134
- Run: \
135
- ```prettier --write MyJavaCode.java --entrypoint classBodyDeclaration```
85
+ Yarn:
136
86
 
137
- Result:
138
- ```java
139
- public void myfunction() {
140
- mymethod
141
- .is()
142
- .very()
143
- .very()
144
- .very()
145
- .very()
146
- .very()
147
- .very()
148
- .very()
149
- .very()
150
- .very()
151
- .very()
152
- .very()
153
- .very()
154
- .very()
155
- .very()
156
- .big();
157
- }
87
+ ```shell
88
+ yarn exec prettier --plugin=prettier-plugin-java --write "**/*.java"
158
89
  ```
90
+
91
+ ### Integration
92
+
93
+ - [Editors](docs/advanced_usage.md#ide-integrations)
94
+ - [Spotless](https://github.com/diffplug/spotless) lets you run Prettier from [Gradle](https://github.com/diffplug/spotless/tree/main/plugin-gradle#prettier) or [Maven](https://github.com/diffplug/spotless/tree/main/plugin-maven#prettier)
95
+
96
+ ## Contributing
97
+
98
+ See [CONTRIBUTING.md](CONTRIBUTING.md).