prettier-plugin-java 2.8.1 → 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 -627
- 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
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,45 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-java",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Prettier Java Plugin",
|
|
5
|
+
"homepage": "https://jhipster.github.io/prettier-java/",
|
|
6
|
+
"repository": "https://github.com/jhipster/prettier-java",
|
|
7
|
+
"license": "Apache-2.0",
|
|
5
8
|
"type": "module",
|
|
6
9
|
"exports": {
|
|
7
|
-
"
|
|
8
|
-
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
9
20
|
},
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
10
23
|
"files": [
|
|
11
24
|
"dist"
|
|
12
25
|
],
|
|
13
|
-
"homepage": "https://jhipster.github.io/prettier-java/",
|
|
14
|
-
"repository": "https://github.com/jhipster/prettier-java",
|
|
15
|
-
"license": "Apache-2.0",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"java-parser": "3.0.1"
|
|
18
|
-
},
|
|
19
26
|
"scripts": {
|
|
27
|
+
"build": "tsdown && cp node_modules/tree-sitter-java-orchard/tree-sitter-java_orchard.wasm dist/",
|
|
28
|
+
"ci": "yarn build && yarn lint && yarn format:validate && yarn test",
|
|
29
|
+
"clone-samples": "node scripts/clone-samples.js",
|
|
30
|
+
"format:fix": "prettier --write \"**/*.@(js|json|ts)\"",
|
|
31
|
+
"format:validate": "prettier --list-different \"**/*.@(js|json|ts)\"",
|
|
32
|
+
"postinstall": "node scripts/generate-node-types.ts && prettier --write src/node-types.ts",
|
|
33
|
+
"lerna:publish": "lerna publish from-git --yes",
|
|
34
|
+
"lerna:version": "lerna version --exact --no-private",
|
|
35
|
+
"lint": "eslint src test",
|
|
36
|
+
"prepare": "husky",
|
|
20
37
|
"test": "yarn run test:unit && yarn run test:e2e-core",
|
|
21
|
-
"test:
|
|
38
|
+
"test:all": "yarn run test && yarn run test:e2e-jhipster1 && yarn run test:e2e-jhipster2",
|
|
22
39
|
"test:e2e-core": "node scripts/clone-samples e2e-core && mocha \"test/repository-test/core-test.ts\"",
|
|
23
40
|
"test:e2e-jhipster1": "node scripts/clone-samples e2e-jhipster1 && mocha \"test/repository-test/jhipster-1-test.ts\"",
|
|
24
41
|
"test:e2e-jhipster2": "node scripts/clone-samples e2e-jhipster2 && mocha \"test/repository-test/jhipster-2-test.ts\"",
|
|
25
|
-
"test:
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
42
|
+
"test:unit": "mocha \"test/unit-test/**/*.spec.ts\" \"test/unit-test/**/*-spec.ts\"",
|
|
43
|
+
"typecheck": "tsc",
|
|
44
|
+
"update-test-outputs": "node scripts/update-test-output.js"
|
|
45
|
+
},
|
|
46
|
+
"lint-staged": {
|
|
47
|
+
"*.json": [
|
|
48
|
+
"prettier --write"
|
|
49
|
+
],
|
|
50
|
+
"*.js,*.ts": [
|
|
51
|
+
"eslint --fix",
|
|
52
|
+
"prettier --write"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"web-tree-sitter": "0.26.8"
|
|
29
57
|
},
|
|
30
58
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@types/chai": "5.
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
59
|
+
"@eslint/js": "^10.0.1",
|
|
60
|
+
"@types/chai": "^5.2.3",
|
|
61
|
+
"@types/emscripten": "^1.41.5",
|
|
62
|
+
"@types/mocha": "^10.0.10",
|
|
63
|
+
"@types/node": "^25.5.0",
|
|
64
|
+
"chai": "^6.2.2",
|
|
65
|
+
"eslint": "^10.1.0",
|
|
66
|
+
"globals": "^17.4.0",
|
|
67
|
+
"husky": "^9.1.7",
|
|
68
|
+
"lerna": "^9.0.7",
|
|
69
|
+
"lint-staged": "^17.0.2",
|
|
70
|
+
"mitata": "^1.0.34",
|
|
71
|
+
"mocha": "^11.7.5",
|
|
72
|
+
"prettier": "^3.8.1",
|
|
73
|
+
"tree-sitter-java-orchard": "0.5.6",
|
|
74
|
+
"tsdown": "^0.22.0",
|
|
75
|
+
"typescript": "^6.0.3",
|
|
76
|
+
"typescript-eslint": "^8.57.1"
|
|
40
77
|
},
|
|
41
78
|
"peerDependencies": {
|
|
42
79
|
"prettier": "^3.0.0"
|
|
43
80
|
},
|
|
44
|
-
"
|
|
81
|
+
"packageManager": "yarn@1.22.22",
|
|
82
|
+
"gitHead": "6e94f5ee92ff695918ce05f91ba12ef45d076afa"
|
|
45
83
|
}
|
package/dist/comments.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { IToken } from "java-parser";
|
|
2
|
-
import { type AstPath } from "prettier";
|
|
3
|
-
import { type JavaNode, type JavaNonTerminal, type JavaParserOptions } from "./printers/helpers.js";
|
|
4
|
-
export declare function determinePrettierIgnoreRanges(cst: JavaNonTerminal): void;
|
|
5
|
-
export declare function isFullyBetweenPrettierIgnore(path: AstPath<JavaNode>): boolean;
|
|
6
|
-
export declare function canAttachComment(node: JavaNode): boolean;
|
|
7
|
-
export declare function handleLineComment(commentNode: JavaComment, _: string, options: JavaParserOptions): boolean;
|
|
8
|
-
export declare function handleRemainingComment(commentNode: JavaComment): boolean;
|
|
9
|
-
export type JavaComment = IToken & {
|
|
10
|
-
value: string;
|
|
11
|
-
leading: boolean;
|
|
12
|
-
trailing: boolean;
|
|
13
|
-
printed: boolean;
|
|
14
|
-
enclosingNode?: JavaNonTerminal;
|
|
15
|
-
precedingNode?: JavaNode;
|
|
16
|
-
followingNode?: JavaNode;
|
|
17
|
-
};
|
package/dist/comments.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { util } from "prettier";
|
|
2
|
-
import parser from "./parser.js";
|
|
3
|
-
import { isEmptyStatement, isNonTerminal, isTerminal } from "./printers/helpers.js";
|
|
4
|
-
const prettierIgnoreRangesByCst = new WeakMap();
|
|
5
|
-
export function determinePrettierIgnoreRanges(cst) {
|
|
6
|
-
const { comments } = cst;
|
|
7
|
-
if (!comments) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const ranges = comments
|
|
11
|
-
.filter(({ image }) => /^\/(?:\/\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*|\*\s*(?:prettier-ignore-(?:start|end)|@formatter:(?:off|on))\s*\*\/)$/.test(image))
|
|
12
|
-
.reduce((ranges, { image, startOffset }) => {
|
|
13
|
-
const previous = ranges.at(-1);
|
|
14
|
-
if (image.includes("start") || image.includes("off")) {
|
|
15
|
-
if ((previous === null || previous === void 0 ? void 0 : previous.end) !== Infinity) {
|
|
16
|
-
ranges.push({ start: startOffset, end: Infinity });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else if ((previous === null || previous === void 0 ? void 0 : previous.end) === Infinity) {
|
|
20
|
-
previous.end = startOffset;
|
|
21
|
-
}
|
|
22
|
-
return ranges;
|
|
23
|
-
}, new Array());
|
|
24
|
-
prettierIgnoreRangesByCst.set(cst, ranges);
|
|
25
|
-
}
|
|
26
|
-
export function isFullyBetweenPrettierIgnore(path) {
|
|
27
|
-
var _a;
|
|
28
|
-
const { node, root } = path;
|
|
29
|
-
const start = parser.locStart(node);
|
|
30
|
-
const end = parser.locEnd(node);
|
|
31
|
-
return (((_a = prettierIgnoreRangesByCst
|
|
32
|
-
.get(root)) === null || _a === void 0 ? void 0 : _a.some(range => range.start < start && end < range.end)) === true);
|
|
33
|
-
}
|
|
34
|
-
export function canAttachComment(node) {
|
|
35
|
-
var _a, _b, _c;
|
|
36
|
-
if (isTerminal(node)) {
|
|
37
|
-
const { name, CATEGORIES } = node.tokenType;
|
|
38
|
-
return (name === "Identifier" ||
|
|
39
|
-
(CATEGORIES === null || CATEGORIES === void 0 ? void 0 : CATEGORIES.find(({ name }) => name === "BinaryOperator")) !== undefined);
|
|
40
|
-
}
|
|
41
|
-
const { children, name } = node;
|
|
42
|
-
switch (name) {
|
|
43
|
-
case "argumentList":
|
|
44
|
-
case "blockStatements":
|
|
45
|
-
case "emptyStatement":
|
|
46
|
-
case "enumBodyDeclarations":
|
|
47
|
-
return false;
|
|
48
|
-
case "annotationInterfaceMemberDeclaration":
|
|
49
|
-
case "classMemberDeclaration":
|
|
50
|
-
case "interfaceMemberDeclaration":
|
|
51
|
-
case "methodBody":
|
|
52
|
-
return !children.Semicolon;
|
|
53
|
-
case "blockStatement":
|
|
54
|
-
return !children.statement || !isEmptyStatement(children.statement[0]);
|
|
55
|
-
case "classBodyDeclaration":
|
|
56
|
-
return !((_a = children.classMemberDeclaration) === null || _a === void 0 ? void 0 : _a[0].children.Semicolon);
|
|
57
|
-
case "recordBodyDeclaration":
|
|
58
|
-
return !((_c = (_b = children.classBodyDeclaration) === null || _b === void 0 ? void 0 : _b[0].children.classMemberDeclaration) === null || _c === void 0 ? void 0 : _c[0].children.Semicolon);
|
|
59
|
-
case "statement":
|
|
60
|
-
return !isEmptyStatement(node);
|
|
61
|
-
case "statementWithoutTrailingSubstatement":
|
|
62
|
-
return !children.emptyStatement;
|
|
63
|
-
default:
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export function handleLineComment(commentNode, _, options) {
|
|
68
|
-
return [
|
|
69
|
-
handleBinaryExpressionComments,
|
|
70
|
-
handleConditionalExpressionComments,
|
|
71
|
-
handleFqnOrRefTypeComments,
|
|
72
|
-
handleIfStatementComments,
|
|
73
|
-
handleJumpStatementComments,
|
|
74
|
-
handleLabeledStatementComments,
|
|
75
|
-
handleNameComments,
|
|
76
|
-
handleTryStatementComments
|
|
77
|
-
].some(fn => fn(commentNode, options));
|
|
78
|
-
}
|
|
79
|
-
export function handleRemainingComment(commentNode) {
|
|
80
|
-
return [
|
|
81
|
-
handleFqnOrRefTypeComments,
|
|
82
|
-
handleMethodDeclaratorComments,
|
|
83
|
-
handleNameComments,
|
|
84
|
-
handleJumpStatementComments
|
|
85
|
-
].some(fn => fn(commentNode));
|
|
86
|
-
}
|
|
87
|
-
function handleBinaryExpressionComments(commentNode, options) {
|
|
88
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
89
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "binaryExpression") {
|
|
90
|
-
if (isBinaryOperator(followingNode)) {
|
|
91
|
-
if (options.experimentalOperatorPosition === "start") {
|
|
92
|
-
util.addLeadingComment(followingNode, commentNode);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
util.addTrailingComment(followingNode, commentNode);
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
else if (options.experimentalOperatorPosition === "start" &&
|
|
100
|
-
isBinaryOperator(precedingNode)) {
|
|
101
|
-
util.addLeadingComment(precedingNode, commentNode);
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
function handleConditionalExpressionComments(commentNode) {
|
|
108
|
-
const { startLine, endLine, enclosingNode, precedingNode, followingNode } = commentNode;
|
|
109
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "conditionalExpression" &&
|
|
110
|
-
precedingNode &&
|
|
111
|
-
followingNode &&
|
|
112
|
-
isNonTerminal(precedingNode) &&
|
|
113
|
-
isNonTerminal(followingNode) &&
|
|
114
|
-
precedingNode.location.endLine < startLine &&
|
|
115
|
-
endLine < followingNode.location.startLine) {
|
|
116
|
-
util.addLeadingComment(followingNode, commentNode);
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
function handleFqnOrRefTypeComments(commentNode) {
|
|
122
|
-
const { enclosingNode, followingNode } = commentNode;
|
|
123
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "fqnOrRefType" && followingNode) {
|
|
124
|
-
util.addLeadingComment(followingNode, commentNode);
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
function handleIfStatementComments(commentNode) {
|
|
130
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
131
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "ifStatement" &&
|
|
132
|
-
precedingNode &&
|
|
133
|
-
isNonTerminal(precedingNode) &&
|
|
134
|
-
precedingNode.name === "statement") {
|
|
135
|
-
util.addDanglingComment(enclosingNode, commentNode, undefined);
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
function handleJumpStatementComments(commentNode) {
|
|
141
|
-
const { enclosingNode, precedingNode, followingNode } = commentNode;
|
|
142
|
-
if (enclosingNode &&
|
|
143
|
-
!precedingNode &&
|
|
144
|
-
!followingNode &&
|
|
145
|
-
["breakStatement", "continueStatement", "returnStatement"].includes(enclosingNode.name)) {
|
|
146
|
-
util.addTrailingComment(enclosingNode, commentNode);
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
function handleLabeledStatementComments(commentNode) {
|
|
152
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
153
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "labeledStatement" &&
|
|
154
|
-
precedingNode &&
|
|
155
|
-
isTerminal(precedingNode) &&
|
|
156
|
-
precedingNode.tokenType.name === "Identifier") {
|
|
157
|
-
util.addLeadingComment(precedingNode, commentNode);
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
function handleMethodDeclaratorComments(commentNode) {
|
|
163
|
-
const { enclosingNode } = commentNode;
|
|
164
|
-
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.name) === "methodDeclarator" &&
|
|
165
|
-
!enclosingNode.children.receiverParameter &&
|
|
166
|
-
!enclosingNode.children.formalParameterList &&
|
|
167
|
-
enclosingNode.children.LBrace[0].startOffset < commentNode.startOffset &&
|
|
168
|
-
commentNode.startOffset < enclosingNode.children.RBrace[0].startOffset) {
|
|
169
|
-
util.addDanglingComment(enclosingNode, commentNode, undefined);
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
function handleNameComments(commentNode) {
|
|
175
|
-
const { enclosingNode, precedingNode } = commentNode;
|
|
176
|
-
if (enclosingNode &&
|
|
177
|
-
precedingNode &&
|
|
178
|
-
isTerminal(precedingNode) &&
|
|
179
|
-
precedingNode.tokenType.name === "Identifier" &&
|
|
180
|
-
[
|
|
181
|
-
"ambiguousName",
|
|
182
|
-
"classOrInterfaceTypeToInstantiate",
|
|
183
|
-
"expressionName",
|
|
184
|
-
"moduleDeclaration",
|
|
185
|
-
"moduleName",
|
|
186
|
-
"packageDeclaration",
|
|
187
|
-
"packageName",
|
|
188
|
-
"packageOrTypeName",
|
|
189
|
-
"typeName"
|
|
190
|
-
].includes(enclosingNode.name)) {
|
|
191
|
-
util.addTrailingComment(precedingNode, commentNode);
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
function handleTryStatementComments(commentNode) {
|
|
197
|
-
var _a, _b;
|
|
198
|
-
const { enclosingNode, followingNode } = commentNode;
|
|
199
|
-
if (enclosingNode &&
|
|
200
|
-
["catches", "tryStatement"].includes(enclosingNode.name) &&
|
|
201
|
-
followingNode &&
|
|
202
|
-
isNonTerminal(followingNode)) {
|
|
203
|
-
const block = (_a = (followingNode.name === "catches"
|
|
204
|
-
? followingNode.children.catchClause[0]
|
|
205
|
-
: followingNode.name === "catchClause" ||
|
|
206
|
-
followingNode.name === "finally"
|
|
207
|
-
? followingNode
|
|
208
|
-
: null)) === null || _a === void 0 ? void 0 : _a.children.block[0];
|
|
209
|
-
if (!block) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
const blockStatement = (_b = block.children.blockStatements) === null || _b === void 0 ? void 0 : _b[0].children.blockStatement[0];
|
|
213
|
-
if (blockStatement) {
|
|
214
|
-
util.addLeadingComment(blockStatement, commentNode);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
util.addDanglingComment(block, commentNode, undefined);
|
|
218
|
-
}
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
function isBinaryOperator(node) {
|
|
224
|
-
var _a;
|
|
225
|
-
return (node !== undefined &&
|
|
226
|
-
(isNonTerminal(node)
|
|
227
|
-
? node.name === "shiftOperator"
|
|
228
|
-
: (_a = node.tokenType.CATEGORIES) === null || _a === void 0 ? void 0 : _a.some(({ name }) => name === "BinaryOperator")));
|
|
229
|
-
}
|