@prettier/plugin-php 0.19.0 → 0.19.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/README.md +11 -11
- package/package.json +7 -7
- package/src/options.js +3 -2
- package/src/printer.js +22 -11
- package/standalone.js +1 -1
package/README.md
CHANGED
|
@@ -165,17 +165,17 @@ prettier.format(YOUR_CODE, {
|
|
|
165
165
|
|
|
166
166
|
Prettier for PHP supports the following options. We recommend that all users set the `phpVersion` option.
|
|
167
167
|
|
|
168
|
-
| Name | Default
|
|
169
|
-
| ------------------
|
|
170
|
-
| `phpVersion` | `"5.4"`
|
|
171
|
-
| `printWidth` | `80`
|
|
172
|
-
| `tabWidth` | `4`
|
|
173
|
-
| `useTabs` | `false`
|
|
174
|
-
| `singleQuote` | `false`
|
|
175
|
-
| `trailingCommaPHP` | `true`
|
|
176
|
-
| `braceStyle` | `"
|
|
177
|
-
| `requirePragma` | `false`
|
|
178
|
-
| `insertPragma` | `false`
|
|
168
|
+
| Name | Default | Description |
|
|
169
|
+
| ------------------ |------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
170
|
+
| `phpVersion` | `"5.4"` | Allows specifying the PHP version you're using. If you're using PHP 7.1 or later, setting this option will make use of modern language features in the printed output. If you're using PHP 5.3 or lower, you'll have to set this option or Prettier will generate incompatible code. |
|
|
171
|
+
| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) |
|
|
172
|
+
| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. |
|
|
173
|
+
| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) |
|
|
174
|
+
| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. |
|
|
175
|
+
| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible. <br> If set to `false`, no trailing commas are printed. |
|
|
176
|
+
| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line. <br> If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. |
|
|
177
|
+
| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) |
|
|
178
|
+
| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) |
|
|
179
179
|
|
|
180
180
|
## Ignoring code
|
|
181
181
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prettier/plugin-php",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.2",
|
|
4
4
|
"description": "Prettier PHP Plugin",
|
|
5
5
|
"repository": "prettier/prettier-php",
|
|
6
6
|
"author": "Lucas Azzola <@azz>",
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"linguist-languages": "^7.21.0",
|
|
15
15
|
"mem": "^8.0.0",
|
|
16
|
-
"php-parser": "3.1.
|
|
16
|
+
"php-parser": "^3.1.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/preset-env": "^7.
|
|
19
|
+
"@babel/preset-env": "^7.19.4",
|
|
20
20
|
"codecov": "3.8.3",
|
|
21
21
|
"cross-env": "^7.0.2",
|
|
22
|
-
"eslint": "8.
|
|
22
|
+
"eslint": "8.26.0",
|
|
23
23
|
"eslint-config-prettier": "8.5.0",
|
|
24
24
|
"eslint-plugin-import": "2.26.0",
|
|
25
|
-
"eslint-plugin-jest": "27.
|
|
25
|
+
"eslint-plugin-jest": "27.1.3",
|
|
26
26
|
"eslint-plugin-prettier": "4.2.1",
|
|
27
|
-
"jest": "29.
|
|
28
|
-
"jest-environment-jsdom": "29.
|
|
27
|
+
"jest": "29.2.2",
|
|
28
|
+
"jest-environment-jsdom": "29.2.2",
|
|
29
29
|
"jest-runner-eslint": "1.1.0",
|
|
30
30
|
"jest-snapshot-serializer-raw": "^1.1.0",
|
|
31
31
|
"prettier": "2.1.2",
|
package/src/options.js
CHANGED
|
@@ -37,11 +37,12 @@ module.exports = {
|
|
|
37
37
|
since: "0.10.0",
|
|
38
38
|
category: CATEGORY_PHP,
|
|
39
39
|
type: "choice",
|
|
40
|
-
default: "
|
|
40
|
+
default: "per-cs",
|
|
41
41
|
description:
|
|
42
42
|
"Print one space or newline for code blocks (classes and functions).",
|
|
43
43
|
choices: [
|
|
44
|
-
{ value: "psr-2", description: "Use
|
|
44
|
+
{ value: "psr-2", description: "(deprecated) Use per-cs" },
|
|
45
|
+
{ value: "per-cs", description: "Use the PER Coding Style brace style." },
|
|
45
46
|
{ value: "1tbs", description: "Use 1tbs brace style." },
|
|
46
47
|
],
|
|
47
48
|
},
|
package/src/printer.js
CHANGED
|
@@ -76,6 +76,7 @@ function shouldPrintHardlineForOpenBrace(options) {
|
|
|
76
76
|
case "1tbs":
|
|
77
77
|
return false;
|
|
78
78
|
case "psr-2":
|
|
79
|
+
case "per-cs":
|
|
79
80
|
default:
|
|
80
81
|
return true;
|
|
81
82
|
}
|
|
@@ -1369,9 +1370,10 @@ function printClass(path, options, print) {
|
|
|
1369
1370
|
|
|
1370
1371
|
function printFunction(path, options, print) {
|
|
1371
1372
|
const node = path.getValue();
|
|
1372
|
-
const
|
|
1373
|
-
|
|
1374
|
-
|
|
1373
|
+
const declAttrs = printAttrs(path, options, print, {
|
|
1374
|
+
inline: node.kind === "closure",
|
|
1375
|
+
});
|
|
1376
|
+
const declaration = [];
|
|
1375
1377
|
|
|
1376
1378
|
if (node.isFinal) {
|
|
1377
1379
|
declaration.push("final ");
|
|
@@ -1430,7 +1432,7 @@ function printFunction(path, options, print) {
|
|
|
1430
1432
|
const printedDeclaration = concat(declaration);
|
|
1431
1433
|
|
|
1432
1434
|
if (!node.body) {
|
|
1433
|
-
return printedDeclaration;
|
|
1435
|
+
return concat([...declAttrs, printedDeclaration]);
|
|
1434
1436
|
}
|
|
1435
1437
|
|
|
1436
1438
|
const isClosure = node.kind === "closure";
|
|
@@ -1444,11 +1446,12 @@ function printFunction(path, options, print) {
|
|
|
1444
1446
|
]);
|
|
1445
1447
|
|
|
1446
1448
|
if (isClosure) {
|
|
1447
|
-
return concat([printedDeclaration, " ", printedBody]);
|
|
1449
|
+
return concat([...declAttrs, printedDeclaration, " ", printedBody]);
|
|
1448
1450
|
}
|
|
1449
1451
|
|
|
1450
1452
|
if (node.arguments.length === 0) {
|
|
1451
1453
|
return concat([
|
|
1454
|
+
...declAttrs,
|
|
1452
1455
|
printedDeclaration,
|
|
1453
1456
|
shouldPrintHardlineForOpenBrace(options) ? hardline : " ",
|
|
1454
1457
|
printedBody,
|
|
@@ -1461,13 +1464,16 @@ function printFunction(path, options, print) {
|
|
|
1461
1464
|
return concat([printedDeclaration, " ", printedBody]);
|
|
1462
1465
|
}
|
|
1463
1466
|
|
|
1464
|
-
return
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1467
|
+
return concat([
|
|
1468
|
+
...declAttrs,
|
|
1469
|
+
conditionalGroup([
|
|
1470
|
+
concat([
|
|
1471
|
+
printedDeclaration,
|
|
1472
|
+
shouldPrintHardlineForOpenBrace(options) ? hardline : " ",
|
|
1473
|
+
printedBody,
|
|
1474
|
+
]),
|
|
1475
|
+
concat([printedDeclaration, " ", printedBody]),
|
|
1469
1476
|
]),
|
|
1470
|
-
concat([printedDeclaration, " ", printedBody]),
|
|
1471
1477
|
]);
|
|
1472
1478
|
}
|
|
1473
1479
|
|
|
@@ -1811,6 +1817,7 @@ function printNode(path, options, print) {
|
|
|
1811
1817
|
return printFunction(path, options, print);
|
|
1812
1818
|
case "arrowfunc":
|
|
1813
1819
|
return concat([
|
|
1820
|
+
node.parenthesizedExpression ? "(" : "",
|
|
1814
1821
|
...printAttrs(path, options, print, { inline: true }),
|
|
1815
1822
|
node.isStatic ? "static " : "",
|
|
1816
1823
|
"fn",
|
|
@@ -1820,6 +1827,7 @@ function printNode(path, options, print) {
|
|
|
1820
1827
|
: "",
|
|
1821
1828
|
" => ",
|
|
1822
1829
|
path.call(print, "body"),
|
|
1830
|
+
node.parenthesizedExpression ? ")" : "",
|
|
1823
1831
|
]);
|
|
1824
1832
|
case "parameter": {
|
|
1825
1833
|
let promoted = "";
|
|
@@ -2256,8 +2264,11 @@ function printNode(path, options, print) {
|
|
|
2256
2264
|
group(path.call(print, "what"))
|
|
2257
2265
|
);
|
|
2258
2266
|
} else {
|
|
2267
|
+
const isExpression = ["call", "offsetlookup"].includes(node.what.kind);
|
|
2259
2268
|
const printed = concat([
|
|
2269
|
+
isExpression ? "(" : "",
|
|
2260
2270
|
path.call(print, "what"),
|
|
2271
|
+
isExpression ? ")" : "",
|
|
2261
2272
|
printArgumentsList(path, options, print),
|
|
2262
2273
|
]);
|
|
2263
2274
|
|