@prettier/plugin-php 0.19.1 → 0.19.3

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 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 | 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` | `"psr-2"` | If set to `"psr-2"`, 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)) |
168
+ | Name | Default | Description |
169
+ | ------------------ |------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
170
+ | `phpVersion` | `"7.0"` | 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 lower than 7.0, 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.1",
3
+ "version": "0.19.3",
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.1"
16
+ "php-parser": "^3.1.3"
17
17
  },
18
18
  "devDependencies": {
19
- "@babel/preset-env": "^7.18.6",
19
+ "@babel/preset-env": "^7.19.4",
20
20
  "codecov": "3.8.3",
21
21
  "cross-env": "^7.0.2",
22
- "eslint": "8.23.1",
23
- "eslint-config-prettier": "8.5.0",
24
- "eslint-plugin-import": "2.26.0",
25
- "eslint-plugin-jest": "27.0.4",
22
+ "eslint": "8.32.0",
23
+ "eslint-config-prettier": "8.6.0",
24
+ "eslint-plugin-import": "2.27.5",
25
+ "eslint-plugin-jest": "27.2.1",
26
26
  "eslint-plugin-prettier": "4.2.1",
27
- "jest": "29.0.3",
28
- "jest-environment-jsdom": "29.0.3",
27
+ "jest": "29.3.1",
28
+ "jest-environment-jsdom": "29.3.1",
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: "psr-2",
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 PSR-2 brace style." },
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
  }
@@ -1253,6 +1254,10 @@ function printClass(path, options, print) {
1253
1254
  const attrs = printAttrs(path, options, print, { inline: isAnonymousClass });
1254
1255
  const declaration = isAnonymousClass ? [] : [...attrs];
1255
1256
 
1257
+ if (node.isReadonly) {
1258
+ declaration.push("readonly ");
1259
+ }
1260
+
1256
1261
  if (node.isFinal) {
1257
1262
  declaration.push("final ");
1258
1263
  }
@@ -1369,9 +1374,10 @@ function printClass(path, options, print) {
1369
1374
 
1370
1375
  function printFunction(path, options, print) {
1371
1376
  const node = path.getValue();
1372
- const declaration = [
1373
- ...printAttrs(path, options, print, { inline: node.kind === "closure" }),
1374
- ];
1377
+ const declAttrs = printAttrs(path, options, print, {
1378
+ inline: node.kind === "closure",
1379
+ });
1380
+ const declaration = [];
1375
1381
 
1376
1382
  if (node.isFinal) {
1377
1383
  declaration.push("final ");
@@ -1430,7 +1436,7 @@ function printFunction(path, options, print) {
1430
1436
  const printedDeclaration = concat(declaration);
1431
1437
 
1432
1438
  if (!node.body) {
1433
- return printedDeclaration;
1439
+ return concat([...declAttrs, printedDeclaration]);
1434
1440
  }
1435
1441
 
1436
1442
  const isClosure = node.kind === "closure";
@@ -1444,11 +1450,12 @@ function printFunction(path, options, print) {
1444
1450
  ]);
1445
1451
 
1446
1452
  if (isClosure) {
1447
- return concat([printedDeclaration, " ", printedBody]);
1453
+ return concat([...declAttrs, printedDeclaration, " ", printedBody]);
1448
1454
  }
1449
1455
 
1450
1456
  if (node.arguments.length === 0) {
1451
1457
  return concat([
1458
+ ...declAttrs,
1452
1459
  printedDeclaration,
1453
1460
  shouldPrintHardlineForOpenBrace(options) ? hardline : " ",
1454
1461
  printedBody,
@@ -1461,13 +1468,16 @@ function printFunction(path, options, print) {
1461
1468
  return concat([printedDeclaration, " ", printedBody]);
1462
1469
  }
1463
1470
 
1464
- return conditionalGroup([
1465
- concat([
1466
- printedDeclaration,
1467
- shouldPrintHardlineForOpenBrace(options) ? hardline : " ",
1468
- printedBody,
1471
+ return concat([
1472
+ ...declAttrs,
1473
+ conditionalGroup([
1474
+ concat([
1475
+ printedDeclaration,
1476
+ shouldPrintHardlineForOpenBrace(options) ? hardline : " ",
1477
+ printedBody,
1478
+ ]),
1479
+ concat([printedDeclaration, " ", printedBody]),
1469
1480
  ]),
1470
- concat([printedDeclaration, " ", printedBody]),
1471
1481
  ]);
1472
1482
  }
1473
1483
 
@@ -2258,8 +2268,11 @@ function printNode(path, options, print) {
2258
2268
  group(path.call(print, "what"))
2259
2269
  );
2260
2270
  } else {
2271
+ const isExpression = ["call", "offsetlookup"].includes(node.what.kind);
2261
2272
  const printed = concat([
2273
+ isExpression ? "(" : "",
2262
2274
  path.call(print, "what"),
2275
+ isExpression ? ")" : "",
2263
2276
  printArgumentsList(path, options, print),
2264
2277
  ]);
2265
2278