From bca1539ee339805bca34b02bca7e8f603b0c1cef Mon Sep 17 00:00:00 2001 From: Mark Reidenbach Date: Mon, 12 Aug 2024 20:28:22 -0500 Subject: [PATCH 1/4] Add phpVersion to php-parser options --- src/parser.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parser.mjs b/src/parser.mjs index 343e4215a..03e862ab5 100644 --- a/src/parser.mjs +++ b/src/parser.mjs @@ -14,6 +14,7 @@ function parse(text, opts) { const parser = new engine({ parser: { extractDoc: true, + version: opts.phpVersion, }, ast: { withPositions: true, From e3f2fbba281bd53df438d06b1698e4cb44be30b1 Mon Sep 17 00:00:00 2001 From: Mark Reidenbach Date: Mon, 12 Aug 2024 20:29:51 -0500 Subject: [PATCH 2/4] Support PHP 8.3 typed constants. Depends on https://github.com/Kenneth-Sills/php-parser/pull/1 --- src/options.mjs | 1 + src/printer.mjs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/options.mjs b/src/options.mjs index 93fca45dc..b431fdf0d 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -23,6 +23,7 @@ export default { { value: "8.0" }, { value: "8.1" }, { value: "8.2" }, + { value: "8.3" }, ], }, trailingCommaPHP: { diff --git a/src/printer.mjs b/src/printer.mjs index 066b68f71..13fdbb7c9 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -2308,6 +2308,7 @@ function printNode(path, options, print) { node.final ? "final " : "", node.visibility ? [node.visibility, " "] : "", "const", + node.type ? [node.nullable ? " ?" : " ", print("type")] : "", firstVariable ? [" ", firstVariable] : "", indent(printed.slice(1).map((p) => [",", hardline, p])), ]); From 5f1de96ca0b81468ce550c49e3c4fec235cb81f4 Mon Sep 17 00:00:00 2001 From: Mark Reidenbach Date: Fri, 6 Dec 2024 09:50:28 -0600 Subject: [PATCH 3/4] Change default php version to 8.3 and remove config values for 5.x and 7.x. This matches the default php version used in the php-parser project and removes options for very old eol versions. PHP 5.6 eol in January 2019 and 7.4 in November 2022. --- src/options.mjs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/options.mjs b/src/options.mjs index b431fdf0d..3a0be86b9 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -5,25 +5,14 @@ export default { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: "7.0", + default: "8.3", description: "Minimum target PHP version.", choices: [ - { value: "5.0" }, - { value: "5.1" }, - { value: "5.2" }, - { value: "5.3" }, - { value: "5.4" }, - { value: "5.5" }, - { value: "5.6" }, - { value: "7.0" }, - { value: "7.1" }, - { value: "7.2" }, - { value: "7.3" }, - { value: "7.4" }, { value: "8.0" }, { value: "8.1" }, { value: "8.2" }, { value: "8.3" }, + { value: "8.4" }, ], }, trailingCommaPHP: { From eb508e14c2d38fec055316e45ee3e3c62f469ef4 Mon Sep 17 00:00:00 2001 From: Mark Reidenbach Date: Fri, 6 Dec 2024 10:01:36 -0600 Subject: [PATCH 4/4] Update README with default phpVersion set to 8.3 --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 34e179ebc..b8a3636cf 100644 --- a/README.md +++ b/README.md @@ -179,17 +179,17 @@ await prettier.format(YOUR_CODE, { Prettier for PHP supports the following options. We recommend that all users set the `phpVersion` option. -| Name | Default | Description | -| ------------------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `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. | -| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | -| `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. | -| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | -| `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"`. | -| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | -| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | -| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | -| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | +| Name | Default | Description | +| ------------------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `phpVersion` | `"8.3"` | Specifies the PHP version used. Setting this option will make use of modern language features in the printed output, but using a value higher than your PHP will cause Prettier to generate incompatible code. | +| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | +| `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. | +| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | +| `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"`. | +| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | +| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | +| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | +| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | ## Ignoring code