@prettier/plugin-php 0.17.3 → 0.18.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/package.json +10 -15
- package/src/.printer.js.swp +0 -0
- package/src/index.js +18 -5
- package/src/needs-parens.js +8 -0
- package/src/printer.js +79 -13
- package/src/util.js +1 -0
- package/standalone.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prettier/plugin-php",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
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.0"
|
|
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": "7.
|
|
22
|
+
"eslint": "7.32.0",
|
|
23
23
|
"eslint-config-prettier": "8.3.0",
|
|
24
|
-
"eslint-plugin-import": "2.
|
|
25
|
-
"eslint-plugin-jest": "
|
|
26
|
-
"eslint-plugin-prettier": "
|
|
27
|
-
"jest": "27.
|
|
28
|
-
"jest-runner-eslint": "0.
|
|
24
|
+
"eslint-plugin-import": "2.25.4",
|
|
25
|
+
"eslint-plugin-jest": "26.0.0",
|
|
26
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
27
|
+
"jest": "27.4.7",
|
|
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.0",
|
|
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
|
}
|
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -115,16 +115,29 @@ const printers = {
|
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
hasPrettierIgnore(path) {
|
|
118
|
-
const node = path.getNode();
|
|
119
118
|
const isSimpleIgnore = (comment) =>
|
|
120
119
|
comment.value.includes("prettier-ignore") &&
|
|
121
120
|
!comment.value.includes("prettier-ignore-start") &&
|
|
122
121
|
!comment.value.includes("prettier-ignore-end");
|
|
122
|
+
|
|
123
|
+
const parentNode = path.getParentNode();
|
|
124
|
+
const node = path.getNode();
|
|
125
|
+
|
|
123
126
|
return (
|
|
124
|
-
node &&
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
(node &&
|
|
128
|
+
node.kind !== "classconstant" &&
|
|
129
|
+
node.comments &&
|
|
130
|
+
node.comments.length > 0 &&
|
|
131
|
+
node.comments.some(isSimpleIgnore)) ||
|
|
132
|
+
// For proper formatting, the classconstant ignore formatting should
|
|
133
|
+
// run on the "constant" child
|
|
134
|
+
(node &&
|
|
135
|
+
node.kind === "constant" &&
|
|
136
|
+
parentNode &&
|
|
137
|
+
parentNode.kind === "classconstant" &&
|
|
138
|
+
parentNode.comments &&
|
|
139
|
+
parentNode.comments.length > 0 &&
|
|
140
|
+
parentNode.comments.some(isSimpleIgnore))
|
|
128
141
|
);
|
|
129
142
|
},
|
|
130
143
|
},
|
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
|
? ""
|
|
@@ -1199,10 +1207,51 @@ function printClassPart(
|
|
|
1199
1207
|
);
|
|
1200
1208
|
}
|
|
1201
1209
|
|
|
1210
|
+
function printAttrs(path, options, print, { inline = false } = {}) {
|
|
1211
|
+
const allAttrs = [];
|
|
1212
|
+
if (!path.getValue().attrGroups) {
|
|
1213
|
+
return [];
|
|
1214
|
+
}
|
|
1215
|
+
path.each((agPath) => {
|
|
1216
|
+
const attrGroup = ["#["];
|
|
1217
|
+
if (!inline && allAttrs.length > 0) {
|
|
1218
|
+
allAttrs.push(hardline);
|
|
1219
|
+
}
|
|
1220
|
+
attrGroup.push(softline);
|
|
1221
|
+
agPath.each((attrPath) => {
|
|
1222
|
+
const attrNode = attrPath.getValue();
|
|
1223
|
+
if (attrGroup.length > 2) {
|
|
1224
|
+
attrGroup.push(",", line);
|
|
1225
|
+
}
|
|
1226
|
+
const attrStmt = [attrNode.name];
|
|
1227
|
+
if (attrNode.args.length > 0) {
|
|
1228
|
+
attrStmt.push(printArgumentsList(attrPath, options, print, "args"));
|
|
1229
|
+
}
|
|
1230
|
+
attrGroup.push(group(concat(attrStmt)));
|
|
1231
|
+
}, "attrs");
|
|
1232
|
+
allAttrs.push(
|
|
1233
|
+
group(
|
|
1234
|
+
concat([
|
|
1235
|
+
indent(concat(attrGroup)),
|
|
1236
|
+
ifBreak(shouldPrintComma(options, "8.0") ? "," : ""),
|
|
1237
|
+
softline,
|
|
1238
|
+
"]",
|
|
1239
|
+
inline ? ifBreak(softline, " ") : "",
|
|
1240
|
+
])
|
|
1241
|
+
)
|
|
1242
|
+
);
|
|
1243
|
+
}, "attrGroups");
|
|
1244
|
+
if (allAttrs.length === 0) {
|
|
1245
|
+
return [];
|
|
1246
|
+
}
|
|
1247
|
+
return [concat([...allAttrs, inline ? "" : hardline])];
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1202
1250
|
function printClass(path, options, print) {
|
|
1203
1251
|
const node = path.getValue();
|
|
1204
|
-
|
|
1205
|
-
const
|
|
1252
|
+
const isAnonymousClass = node.kind === "class" && node.isAnonymous;
|
|
1253
|
+
const attrs = printAttrs(path, options, print, { inline: isAnonymousClass });
|
|
1254
|
+
const declaration = isAnonymousClass ? [] : [...attrs];
|
|
1206
1255
|
|
|
1207
1256
|
if (node.isFinal) {
|
|
1208
1257
|
declaration.push("final ");
|
|
@@ -1212,8 +1261,6 @@ function printClass(path, options, print) {
|
|
|
1212
1261
|
declaration.push("abstract ");
|
|
1213
1262
|
}
|
|
1214
1263
|
|
|
1215
|
-
const isAnonymousClass = node.kind === "class" && node.isAnonymous;
|
|
1216
|
-
|
|
1217
1264
|
// `new` print `class` keyword with arguments
|
|
1218
1265
|
declaration.push(isAnonymousClass ? "" : node.kind);
|
|
1219
1266
|
|
|
@@ -1318,7 +1365,9 @@ function printClass(path, options, print) {
|
|
|
1318
1365
|
|
|
1319
1366
|
function printFunction(path, options, print) {
|
|
1320
1367
|
const node = path.getValue();
|
|
1321
|
-
const declaration = [
|
|
1368
|
+
const declaration = [
|
|
1369
|
+
...printAttrs(path, options, print, { inline: node.kind === "closure" }),
|
|
1370
|
+
];
|
|
1322
1371
|
|
|
1323
1372
|
if (node.isFinal) {
|
|
1324
1373
|
declaration.push("final ");
|
|
@@ -1745,6 +1794,7 @@ function printNode(path, options, print) {
|
|
|
1745
1794
|
return printFunction(path, options, print);
|
|
1746
1795
|
case "arrowfunc":
|
|
1747
1796
|
return concat([
|
|
1797
|
+
...printAttrs(path, options, print, { inline: true }),
|
|
1748
1798
|
node.isStatic ? "static " : "",
|
|
1749
1799
|
"fn",
|
|
1750
1800
|
printArgumentsList(path, options, print),
|
|
@@ -1764,6 +1814,7 @@ function printNode(path, options, print) {
|
|
|
1764
1814
|
promoted = "private ";
|
|
1765
1815
|
}
|
|
1766
1816
|
const name = concat([
|
|
1817
|
+
...printAttrs(path, options, print, { inline: true }),
|
|
1767
1818
|
promoted,
|
|
1768
1819
|
node.nullable ? "?" : "",
|
|
1769
1820
|
node.type ? concat([path.call(print, "type"), " "]) : "",
|
|
@@ -1823,6 +1874,11 @@ function printNode(path, options, print) {
|
|
|
1823
1874
|
])
|
|
1824
1875
|
);
|
|
1825
1876
|
case "propertystatement": {
|
|
1877
|
+
const attrs = [];
|
|
1878
|
+
path.map(
|
|
1879
|
+
(propPath) => attrs.push(...printAttrs(propPath, options, print)),
|
|
1880
|
+
"properties"
|
|
1881
|
+
);
|
|
1826
1882
|
const printed = path.map((childPath) => {
|
|
1827
1883
|
return print(childPath);
|
|
1828
1884
|
}, "properties");
|
|
@@ -1842,6 +1898,7 @@ function printNode(path, options, print) {
|
|
|
1842
1898
|
|
|
1843
1899
|
return group(
|
|
1844
1900
|
concat([
|
|
1901
|
+
...attrs,
|
|
1845
1902
|
hasVisibility
|
|
1846
1903
|
? concat([node.visibility === null ? "var" : node.visibility, ""])
|
|
1847
1904
|
: "",
|
|
@@ -2148,6 +2205,7 @@ function printNode(path, options, print) {
|
|
|
2148
2205
|
) {
|
|
2149
2206
|
return concat([
|
|
2150
2207
|
"new ",
|
|
2208
|
+
...path.call(printAttrs, "what"),
|
|
2151
2209
|
path.call(print, "what"),
|
|
2152
2210
|
"(",
|
|
2153
2211
|
join(", ", path.map(print, "arguments")),
|
|
@@ -2168,6 +2226,10 @@ function printNode(path, options, print) {
|
|
|
2168
2226
|
" ",
|
|
2169
2227
|
])
|
|
2170
2228
|
: "",
|
|
2229
|
+
...path.call(
|
|
2230
|
+
(pa) => printAttrs(pa, options, print, { inline: true }),
|
|
2231
|
+
"what"
|
|
2232
|
+
),
|
|
2171
2233
|
"class",
|
|
2172
2234
|
node.arguments.length > 0
|
|
2173
2235
|
? concat([" ", printArgumentsList(path, options, print)])
|
|
@@ -2406,9 +2468,8 @@ function printNode(path, options, print) {
|
|
|
2406
2468
|
}
|
|
2407
2469
|
case "constantstatement":
|
|
2408
2470
|
case "classconstant": {
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2411
|
-
}, "constants");
|
|
2471
|
+
const attrs = printAttrs(path, options, print);
|
|
2472
|
+
const printed = path.map((childPath) => print(childPath), "constants");
|
|
2412
2473
|
|
|
2413
2474
|
let firstVariable;
|
|
2414
2475
|
|
|
@@ -2421,6 +2482,7 @@ function printNode(path, options, print) {
|
|
|
2421
2482
|
|
|
2422
2483
|
return group(
|
|
2423
2484
|
concat([
|
|
2485
|
+
...attrs,
|
|
2424
2486
|
node.visibility ? concat([node.visibility, " "]) : "",
|
|
2425
2487
|
"const",
|
|
2426
2488
|
firstVariable ? concat([" ", firstVariable]) : "",
|
|
@@ -2759,7 +2821,11 @@ function printNode(path, options, print) {
|
|
|
2759
2821
|
const parentParent = path.getParentNode(1);
|
|
2760
2822
|
const pureParent =
|
|
2761
2823
|
parent.kind === "cast" && parentParent ? parentParent : parent;
|
|
2762
|
-
const breakLookupNodes = [
|
|
2824
|
+
const breakLookupNodes = [
|
|
2825
|
+
"propertylookup",
|
|
2826
|
+
"nullsafepropertylookup",
|
|
2827
|
+
"staticlookup",
|
|
2828
|
+
];
|
|
2763
2829
|
const breakClosingParens = breakLookupNodes.includes(pureParent.kind);
|
|
2764
2830
|
|
|
2765
2831
|
const printedTest = path.call(print, "test");
|
package/src/util.js
CHANGED