@prettier/plugin-php 0.17.5 → 0.18.2
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 +9 -14
- package/src/needs-parens.js +8 -0
- package/src/options.js +1 -0
- package/src/printer.js +45 -11
- 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.2",
|
|
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.4"
|
|
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
|
-
"eslint": "
|
|
22
|
+
"eslint": "8.9.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/options.js
CHANGED
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)
|
|
@@ -1212,14 +1214,14 @@ function printAttrs(path, options, print, { inline = false } = {}) {
|
|
|
1212
1214
|
}
|
|
1213
1215
|
path.each((agPath) => {
|
|
1214
1216
|
const attrGroup = ["#["];
|
|
1215
|
-
if (allAttrs.length > 0) {
|
|
1216
|
-
allAttrs.push(
|
|
1217
|
+
if (!inline && allAttrs.length > 0) {
|
|
1218
|
+
allAttrs.push(hardline);
|
|
1217
1219
|
}
|
|
1218
|
-
attrGroup.push(
|
|
1220
|
+
attrGroup.push(softline);
|
|
1219
1221
|
agPath.each((attrPath) => {
|
|
1220
1222
|
const attrNode = attrPath.getValue();
|
|
1221
1223
|
if (attrGroup.length > 2) {
|
|
1222
|
-
attrGroup.push(",",
|
|
1224
|
+
attrGroup.push(",", line);
|
|
1223
1225
|
}
|
|
1224
1226
|
const attrStmt = [attrNode.name];
|
|
1225
1227
|
if (attrNode.args.length > 0) {
|
|
@@ -1231,10 +1233,10 @@ function printAttrs(path, options, print, { inline = false } = {}) {
|
|
|
1231
1233
|
group(
|
|
1232
1234
|
concat([
|
|
1233
1235
|
indent(concat(attrGroup)),
|
|
1234
|
-
ifBreak(
|
|
1235
|
-
"]",
|
|
1236
|
+
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
|
|
1236
1237
|
softline,
|
|
1237
|
-
|
|
1238
|
+
"]",
|
|
1239
|
+
inline ? ifBreak(softline, " ") : "",
|
|
1238
1240
|
])
|
|
1239
1241
|
)
|
|
1240
1242
|
);
|
|
@@ -1266,6 +1268,10 @@ function printClass(path, options, print) {
|
|
|
1266
1268
|
declaration.push(" ", path.call(print, "name"));
|
|
1267
1269
|
}
|
|
1268
1270
|
|
|
1271
|
+
if (node.kind === "enum" && node.valueType) {
|
|
1272
|
+
declaration.push(": ", path.call(print, "valueType"));
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1269
1275
|
// Only `class` can have `extends` and `implements`
|
|
1270
1276
|
if (node.extends && node.implements) {
|
|
1271
1277
|
declaration.push(
|
|
@@ -1735,6 +1741,7 @@ function printNode(path, options, print) {
|
|
|
1735
1741
|
node.alias ? concat([" as ", path.call(print, "alias")]) : "",
|
|
1736
1742
|
]);
|
|
1737
1743
|
case "class":
|
|
1744
|
+
case "enum":
|
|
1738
1745
|
case "interface":
|
|
1739
1746
|
case "trait":
|
|
1740
1747
|
return printClass(path, options, print);
|
|
@@ -1814,6 +1821,7 @@ function printNode(path, options, print) {
|
|
|
1814
1821
|
const name = concat([
|
|
1815
1822
|
...printAttrs(path, options, print, { inline: true }),
|
|
1816
1823
|
promoted,
|
|
1824
|
+
node.readonly ? "readonly " : "",
|
|
1817
1825
|
node.nullable ? "?" : "",
|
|
1818
1826
|
node.type ? concat([path.call(print, "type"), " "]) : "",
|
|
1819
1827
|
node.byref ? "&" : "",
|
|
@@ -1852,6 +1860,7 @@ function printNode(path, options, print) {
|
|
|
1852
1860
|
case "property":
|
|
1853
1861
|
return group(
|
|
1854
1862
|
concat([
|
|
1863
|
+
node.readonly ? "readonly " : "",
|
|
1855
1864
|
node.type
|
|
1856
1865
|
? concat([node.nullable ? "?" : "", path.call(print, "type"), " "])
|
|
1857
1866
|
: "",
|
|
@@ -2225,7 +2234,7 @@ function printNode(path, options, print) {
|
|
|
2225
2234
|
])
|
|
2226
2235
|
: "",
|
|
2227
2236
|
...path.call(
|
|
2228
|
-
(pa
|
|
2237
|
+
(pa) => printAttrs(pa, options, print, { inline: true }),
|
|
2229
2238
|
"what"
|
|
2230
2239
|
),
|
|
2231
2240
|
"class",
|
|
@@ -2819,7 +2828,11 @@ function printNode(path, options, print) {
|
|
|
2819
2828
|
const parentParent = path.getParentNode(1);
|
|
2820
2829
|
const pureParent =
|
|
2821
2830
|
parent.kind === "cast" && parentParent ? parentParent : parent;
|
|
2822
|
-
const breakLookupNodes = [
|
|
2831
|
+
const breakLookupNodes = [
|
|
2832
|
+
"propertylookup",
|
|
2833
|
+
"nullsafepropertylookup",
|
|
2834
|
+
"staticlookup",
|
|
2835
|
+
];
|
|
2823
2836
|
const breakClosingParens = breakLookupNodes.includes(pureParent.kind);
|
|
2824
2837
|
|
|
2825
2838
|
const printedTest = path.call(print, "test");
|
|
@@ -3056,6 +3069,27 @@ function printNode(path, options, print) {
|
|
|
3056
3069
|
: "";
|
|
3057
3070
|
case "namedargument":
|
|
3058
3071
|
return concat([node.name, ": ", path.call(print, "value")]);
|
|
3072
|
+
|
|
3073
|
+
case "enumcase":
|
|
3074
|
+
return group(
|
|
3075
|
+
concat([
|
|
3076
|
+
"case ",
|
|
3077
|
+
path.call(print, "name"),
|
|
3078
|
+
node.value
|
|
3079
|
+
? concat([
|
|
3080
|
+
" =",
|
|
3081
|
+
printAssignmentRight(
|
|
3082
|
+
node.name,
|
|
3083
|
+
node.value,
|
|
3084
|
+
path.call(print, "value"),
|
|
3085
|
+
false,
|
|
3086
|
+
options
|
|
3087
|
+
),
|
|
3088
|
+
])
|
|
3089
|
+
: "",
|
|
3090
|
+
])
|
|
3091
|
+
);
|
|
3092
|
+
|
|
3059
3093
|
case "error":
|
|
3060
3094
|
default:
|
|
3061
3095
|
// 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
|
);
|