@prettier/plugin-php 0.17.4 → 0.18.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.
- package/package.json +8 -13
- package/src/needs-parens.js +8 -0
- package/src/printer.js +51 -13
- package/src/util.js +3 -0
- package/standalone.js +1 -1
- package/src/.clean.js.swp +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prettier/plugin-php",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Prettier PHP Plugin",
|
|
5
5
|
"repository": "prettier/prettier-php",
|
|
6
6
|
"author": "Lucas Azzola <@azz>",
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"linguist-languages": "^7.5.1",
|
|
15
15
|
"mem": "^8.0.0",
|
|
16
|
-
"php-parser": "
|
|
16
|
+
"php-parser": "3.1.0-beta.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/preset-env": "^7.
|
|
19
|
+
"@babel/preset-env": "^7.16.11",
|
|
20
20
|
"codecov": "3.8.3",
|
|
21
21
|
"cross-env": "^7.0.2",
|
|
22
22
|
"eslint": "7.32.0",
|
|
23
23
|
"eslint-config-prettier": "8.3.0",
|
|
24
|
-
"eslint-plugin-import": "2.
|
|
25
|
-
"eslint-plugin-jest": "
|
|
24
|
+
"eslint-plugin-import": "2.25.4",
|
|
25
|
+
"eslint-plugin-jest": "26.1.0",
|
|
26
26
|
"eslint-plugin-prettier": "4.0.0",
|
|
27
|
-
"jest": "27.1
|
|
28
|
-
"jest-runner-eslint": "0.
|
|
27
|
+
"jest": "27.5.1",
|
|
28
|
+
"jest-runner-eslint": "1.0.0",
|
|
29
29
|
"jest-snapshot-serializer-raw": "^1.1.0",
|
|
30
30
|
"prettier": "2.1.2",
|
|
31
|
-
"rollup": "^2.
|
|
31
|
+
"rollup": "^2.67.2",
|
|
32
32
|
"rollup-plugin-alias": "^2.0.0",
|
|
33
33
|
"rollup-plugin-babel": "^4.3.2",
|
|
34
34
|
"rollup-plugin-commonjs": "^10.0.2",
|
|
@@ -49,10 +49,5 @@
|
|
|
49
49
|
"prettier": "prettier --plugin=. --parser=php",
|
|
50
50
|
"build-standalone": "rollup -c build/rollup.config.js",
|
|
51
51
|
"debug": "node --inspect-brk node_modules/.bin/jest --runInBand"
|
|
52
|
-
},
|
|
53
|
-
"jest": {
|
|
54
|
-
"projects": [
|
|
55
|
-
"<rootDir>/jest.*.config.js"
|
|
56
|
-
]
|
|
57
52
|
}
|
|
58
53
|
}
|
package/src/needs-parens.js
CHANGED
|
@@ -52,6 +52,7 @@ function needsParens(path) {
|
|
|
52
52
|
(node.type === "+" || node.type === "-")
|
|
53
53
|
);
|
|
54
54
|
case "propertylookup":
|
|
55
|
+
case "nullsafepropertylookup":
|
|
55
56
|
case "staticlookup":
|
|
56
57
|
case "offsetlookup":
|
|
57
58
|
case "call":
|
|
@@ -76,6 +77,7 @@ function needsParens(path) {
|
|
|
76
77
|
return true;
|
|
77
78
|
case "call":
|
|
78
79
|
case "propertylookup":
|
|
80
|
+
case "nullsafepropertylookup":
|
|
79
81
|
case "staticlookup":
|
|
80
82
|
case "offsetlookup":
|
|
81
83
|
return name === "what" && parent.what === node;
|
|
@@ -121,6 +123,7 @@ function needsParens(path) {
|
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
case "propertylookup":
|
|
126
|
+
case "nullsafepropertylookup":
|
|
124
127
|
case "staticlookup": {
|
|
125
128
|
switch (parent.kind) {
|
|
126
129
|
case "call":
|
|
@@ -138,6 +141,7 @@ function needsParens(path) {
|
|
|
138
141
|
case "new": {
|
|
139
142
|
switch (parent.kind) {
|
|
140
143
|
case "propertylookup":
|
|
144
|
+
case "nullsafepropertylookup":
|
|
141
145
|
case "staticlookup":
|
|
142
146
|
case "offsetlookup":
|
|
143
147
|
case "call":
|
|
@@ -149,6 +153,7 @@ function needsParens(path) {
|
|
|
149
153
|
case "yield": {
|
|
150
154
|
switch (parent.kind) {
|
|
151
155
|
case "propertylookup":
|
|
156
|
+
case "nullsafepropertylookup":
|
|
152
157
|
case "staticlookup":
|
|
153
158
|
case "offsetlookup":
|
|
154
159
|
case "call":
|
|
@@ -196,6 +201,7 @@ function needsParens(path) {
|
|
|
196
201
|
|
|
197
202
|
return true;
|
|
198
203
|
case "propertylookup":
|
|
204
|
+
case "nullsafepropertylookup":
|
|
199
205
|
case "staticlookup":
|
|
200
206
|
case "offsetlookup":
|
|
201
207
|
case "call":
|
|
@@ -211,6 +217,7 @@ function needsParens(path) {
|
|
|
211
217
|
|
|
212
218
|
// https://github.com/prettier/plugin-php/issues/1675
|
|
213
219
|
case "propertylookup":
|
|
220
|
+
case "nullsafepropertylookup":
|
|
214
221
|
return true;
|
|
215
222
|
|
|
216
223
|
default:
|
|
@@ -225,6 +232,7 @@ function needsParens(path) {
|
|
|
225
232
|
case "array":
|
|
226
233
|
switch (parent.kind) {
|
|
227
234
|
case "propertylookup":
|
|
235
|
+
case "nullsafepropertylookup":
|
|
228
236
|
case "staticlookup":
|
|
229
237
|
case "offsetlookup":
|
|
230
238
|
case "call":
|
package/src/printer.js
CHANGED
|
@@ -288,7 +288,7 @@ function printMemberChain(path, options, print) {
|
|
|
288
288
|
if (
|
|
289
289
|
printedNodes[i].node.kind === "call" &&
|
|
290
290
|
printedNodes[i - 1] &&
|
|
291
|
-
["propertylookup", "staticlookup"].includes(
|
|
291
|
+
["propertylookup", "nullsafepropertylookup", "staticlookup"].includes(
|
|
292
292
|
printedNodes[i - 1].node.kind
|
|
293
293
|
) &&
|
|
294
294
|
printedNodes[i - 1].needsParens
|
|
@@ -635,7 +635,9 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
|
|
|
635
635
|
(shouldPrintComma(options, "7.3") &&
|
|
636
636
|
["call", "new", "unset", "isset"].includes(node.kind)) ||
|
|
637
637
|
(shouldPrintComma(options, "8.0") &&
|
|
638
|
-
["function", "closure", "method", "arrowfunc"].includes(
|
|
638
|
+
["function", "closure", "method", "arrowfunc", "attribute"].includes(
|
|
639
|
+
node.kind
|
|
640
|
+
))
|
|
639
641
|
? indent(
|
|
640
642
|
concat([
|
|
641
643
|
lastArg && shouldPrintHardlineBeforeTrailingComma(lastArg)
|
|
@@ -1049,14 +1051,20 @@ function printLines(path, options, print, childrenAttribute = "children") {
|
|
|
1049
1051
|
: isProgramLikeNode(node) && isFirstNode && node.kind !== "namespace"
|
|
1050
1052
|
? ""
|
|
1051
1053
|
: concat([beforeCloseTagInlineNode, "?>"]);
|
|
1054
|
+
|
|
1055
|
+
const nextV = path.getNode(index + 1);
|
|
1056
|
+
const skipLastComment = nextV && nextV.children && nextV.children.length;
|
|
1057
|
+
|
|
1052
1058
|
const afterInline =
|
|
1053
1059
|
childNode.comments && childNode.comments.length
|
|
1054
1060
|
? concat([
|
|
1055
1061
|
openTag,
|
|
1056
1062
|
hardline,
|
|
1057
|
-
|
|
1063
|
+
skipLastComment
|
|
1064
|
+
? comments.printComments(childNode.comments, options)
|
|
1065
|
+
: "",
|
|
1058
1066
|
hardline,
|
|
1059
|
-
"?>",
|
|
1067
|
+
skipLastComment ? "?>" : "",
|
|
1060
1068
|
])
|
|
1061
1069
|
: isProgramLikeNode(node) && isLastNode
|
|
1062
1070
|
? ""
|
|
@@ -1206,14 +1214,14 @@ function printAttrs(path, options, print, { inline = false } = {}) {
|
|
|
1206
1214
|
}
|
|
1207
1215
|
path.each((agPath) => {
|
|
1208
1216
|
const attrGroup = ["#["];
|
|
1209
|
-
if (allAttrs.length > 0) {
|
|
1210
|
-
allAttrs.push(
|
|
1217
|
+
if (!inline && allAttrs.length > 0) {
|
|
1218
|
+
allAttrs.push(hardline);
|
|
1211
1219
|
}
|
|
1212
|
-
attrGroup.push(
|
|
1220
|
+
attrGroup.push(softline);
|
|
1213
1221
|
agPath.each((attrPath) => {
|
|
1214
1222
|
const attrNode = attrPath.getValue();
|
|
1215
1223
|
if (attrGroup.length > 2) {
|
|
1216
|
-
attrGroup.push(",",
|
|
1224
|
+
attrGroup.push(",", line);
|
|
1217
1225
|
}
|
|
1218
1226
|
const attrStmt = [attrNode.name];
|
|
1219
1227
|
if (attrNode.args.length > 0) {
|
|
@@ -1225,10 +1233,10 @@ function printAttrs(path, options, print, { inline = false } = {}) {
|
|
|
1225
1233
|
group(
|
|
1226
1234
|
concat([
|
|
1227
1235
|
indent(concat(attrGroup)),
|
|
1228
|
-
ifBreak(
|
|
1229
|
-
"]",
|
|
1236
|
+
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
|
|
1230
1237
|
softline,
|
|
1231
|
-
|
|
1238
|
+
"]",
|
|
1239
|
+
inline ? ifBreak(softline, " ") : "",
|
|
1232
1240
|
])
|
|
1233
1241
|
)
|
|
1234
1242
|
);
|
|
@@ -1260,6 +1268,10 @@ function printClass(path, options, print) {
|
|
|
1260
1268
|
declaration.push(" ", path.call(print, "name"));
|
|
1261
1269
|
}
|
|
1262
1270
|
|
|
1271
|
+
if (node.kind === "enum" && node.valueType) {
|
|
1272
|
+
declaration.push(": ", path.call(print, "valueType"));
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1263
1275
|
// Only `class` can have `extends` and `implements`
|
|
1264
1276
|
if (node.extends && node.implements) {
|
|
1265
1277
|
declaration.push(
|
|
@@ -1729,6 +1741,7 @@ function printNode(path, options, print) {
|
|
|
1729
1741
|
node.alias ? concat([" as ", path.call(print, "alias")]) : "",
|
|
1730
1742
|
]);
|
|
1731
1743
|
case "class":
|
|
1744
|
+
case "enum":
|
|
1732
1745
|
case "interface":
|
|
1733
1746
|
case "trait":
|
|
1734
1747
|
return printClass(path, options, print);
|
|
@@ -2219,7 +2232,7 @@ function printNode(path, options, print) {
|
|
|
2219
2232
|
])
|
|
2220
2233
|
: "",
|
|
2221
2234
|
...path.call(
|
|
2222
|
-
(pa
|
|
2235
|
+
(pa) => printAttrs(pa, options, print, { inline: true }),
|
|
2223
2236
|
"what"
|
|
2224
2237
|
),
|
|
2225
2238
|
"class",
|
|
@@ -2813,7 +2826,11 @@ function printNode(path, options, print) {
|
|
|
2813
2826
|
const parentParent = path.getParentNode(1);
|
|
2814
2827
|
const pureParent =
|
|
2815
2828
|
parent.kind === "cast" && parentParent ? parentParent : parent;
|
|
2816
|
-
const breakLookupNodes = [
|
|
2829
|
+
const breakLookupNodes = [
|
|
2830
|
+
"propertylookup",
|
|
2831
|
+
"nullsafepropertylookup",
|
|
2832
|
+
"staticlookup",
|
|
2833
|
+
];
|
|
2817
2834
|
const breakClosingParens = breakLookupNodes.includes(pureParent.kind);
|
|
2818
2835
|
|
|
2819
2836
|
const printedTest = path.call(print, "test");
|
|
@@ -3050,6 +3067,27 @@ function printNode(path, options, print) {
|
|
|
3050
3067
|
: "";
|
|
3051
3068
|
case "namedargument":
|
|
3052
3069
|
return concat([node.name, ": ", path.call(print, "value")]);
|
|
3070
|
+
|
|
3071
|
+
case "enumcase":
|
|
3072
|
+
return group(
|
|
3073
|
+
concat([
|
|
3074
|
+
"case ",
|
|
3075
|
+
path.call(print, "name"),
|
|
3076
|
+
node.value
|
|
3077
|
+
? concat([
|
|
3078
|
+
" =",
|
|
3079
|
+
printAssignmentRight(
|
|
3080
|
+
node.name,
|
|
3081
|
+
node.value,
|
|
3082
|
+
path.call(print, "value"),
|
|
3083
|
+
false,
|
|
3084
|
+
options
|
|
3085
|
+
),
|
|
3086
|
+
])
|
|
3087
|
+
: "",
|
|
3088
|
+
])
|
|
3089
|
+
);
|
|
3090
|
+
|
|
3053
3091
|
case "error":
|
|
3054
3092
|
default:
|
|
3055
3093
|
// istanbul ignore next
|
package/src/util.js
CHANGED
|
@@ -165,6 +165,7 @@ function nodeHasStatement(node) {
|
|
|
165
165
|
"program",
|
|
166
166
|
"namespace",
|
|
167
167
|
"class",
|
|
168
|
+
"enum",
|
|
168
169
|
"interface",
|
|
169
170
|
"trait",
|
|
170
171
|
"traituse",
|
|
@@ -420,6 +421,7 @@ function lineShouldEndWithSemicolon(path) {
|
|
|
420
421
|
"traitalias",
|
|
421
422
|
"goto",
|
|
422
423
|
"constantstatement",
|
|
424
|
+
"enumcase",
|
|
423
425
|
"global",
|
|
424
426
|
"static",
|
|
425
427
|
"echo",
|
|
@@ -485,6 +487,7 @@ function hasTrailingComment(node) {
|
|
|
485
487
|
function isLookupNode(node) {
|
|
486
488
|
return (
|
|
487
489
|
node.kind === "propertylookup" ||
|
|
490
|
+
node.kind === "nullsafepropertylookup" ||
|
|
488
491
|
node.kind === "staticlookup" ||
|
|
489
492
|
node.kind === "offsetlookup"
|
|
490
493
|
);
|