prettier-plugin-java 2.8.0 → 2.9.0
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.
- package/README.md +42 -102
- package/dist/index.cjs +2215 -0
- package/dist/index.d.cts +1630 -0
- package/dist/index.d.mts +1633 -0
- package/dist/index.mjs +2215 -0
- package/dist/tree-sitter-java_orchard.wasm +0 -0
- package/package.json +62 -24
- package/dist/comments.d.ts +0 -17
- package/dist/comments.js +0 -229
- package/dist/index.d.ts +0 -563
- package/dist/index.js +0 -29
- package/dist/options.d.ts +0 -43
- package/dist/options.js +0 -284
- package/dist/parser.d.ts +0 -9
- package/dist/parser.js +0 -24
- package/dist/printer.d.ts +0 -18
- package/dist/printer.js +0 -40
- package/dist/printers/arrays.d.ts +0 -9
- package/dist/printers/arrays.js +0 -9
- package/dist/printers/blocks-and-statements.d.ts +0 -117
- package/dist/printers/blocks-and-statements.js +0 -340
- package/dist/printers/classes.d.ts +0 -157
- package/dist/printers/classes.js +0 -485
- package/dist/printers/expressions.d.ts +0 -134
- package/dist/printers/expressions.js +0 -625
- package/dist/printers/helpers.d.ts +0 -73
- package/dist/printers/helpers.js +0 -273
- package/dist/printers/index.d.ts +0 -2
- package/dist/printers/index.js +0 -13
- package/dist/printers/interfaces.d.ts +0 -62
- package/dist/printers/interfaces.js +0 -175
- package/dist/printers/lexical-structure.d.ts +0 -14
- package/dist/printers/lexical-structure.js +0 -29
- package/dist/printers/names.d.ts +0 -12
- package/dist/printers/names.js +0 -11
- package/dist/printers/packages-and-modules.d.ts +0 -46
- package/dist/printers/packages-and-modules.js +0 -169
- package/dist/printers/types-values-and-variables.d.ts +0 -46
- package/dist/printers/types-values-and-variables.js +0 -90
package/README.md
CHANGED
|
@@ -1,80 +1,18 @@
|
|
|
1
|
-
[](https://www.jhipster.tech/prettier-java/)
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Prettier Java Plugin
|
|
4
4
|
|
|
5
|
-
](https://github.com/jhipster/prettier-java/actions/workflows/github-ci.yml?query=branch%3Amain) [](https://www.npmjs.com/package/prettier-plugin-java) [](https://www.npmjs.com/package/prettier-plugin-java) [](https://github.com/prettier/prettier#badge)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Intro
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
|
|
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
|
-
|
|
135
|
-
```prettier --write MyJavaCode.java --entrypoint classBodyDeclaration```
|
|
85
|
+
Yarn:
|
|
136
86
|
|
|
137
|
-
|
|
138
|
-
|
|
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).
|