@prettier/plugin-php 0.22.4 → 0.23.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/README.md CHANGED
@@ -8,26 +8,23 @@
8
8
  <h2 align="center">Prettier PHP Plugin</h2>
9
9
 
10
10
  <p align="center">
11
- <a href="https://github.com/prettier/plugin-php/actions">
12
- <img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/prettier/plugin-php/Node CI?style=flat-square">
11
+ <a href="https://github.com/prettier/plugin-php/actions?query=branch%3Amain">
12
+ <img alt="CI Status" src="https://img.shields.io/github/actions/workflow/status/prettier/plugin-php/nodejs.yml?style=flat-square&label=CI&branch=main">
13
13
  </a>
14
14
  <a href="https://www.npmjs.com/package/@prettier/plugin-php">
15
15
  <img alt="npm version" src="https://img.shields.io/npm/v/@prettier/plugin-php.svg?style=flat-square">
16
16
  </a>
17
17
  <a href="https://codecov.io/gh/prettier/plugin-php">
18
- <img alt="Codecov Coverage Status" src="https://img.shields.io/codecov/c/github/prettier/plugin-php.svg?style=flat-square">
18
+ <img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/prettier/plugin-php.svg?style=flat-square">
19
19
  </a>
20
20
  <!-- <a href="https://www.npmjs.com/package/@prettier/plugin-php">
21
21
  <img alt="monthly downloads" src="https://img.shields.io/npm/dm/@prettier/plugin-php.svg?style=flat-square">
22
22
  </a> -->
23
- <a href="#badge">
23
+ <a href="https://github.com/prettier/prettier#badge">
24
24
  <img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square">
25
25
  </a>
26
- <a href="https://gitter.im/jlongster/prettier">
27
- <img alt="Gitter" src="https://img.shields.io/gitter/room/jlongster/prettier.svg?style=flat-square">
28
- </a>
29
- <a href="https://twitter.com/PrettierCode">
30
- <img alt="Follow+Prettier+on+Twitter" src="https://img.shields.io/twitter/follow/prettiercode.svg?label=follow+prettier&style=flat-square">
26
+ <a href="https://x.com/intent/follow?screen_name=PrettierCode">
27
+ <img alt="Follow Prettier on X" src="https://img.shields.io/badge/%40PrettierCode-9f9f9f?style=flat-square&logo=x&labelColor=555">
31
28
  </a>
32
29
  </p>
33
30
 
@@ -227,10 +224,6 @@ matrix(
227
224
 
228
225
  ## Editor integration
229
226
 
230
- ### Atom
231
-
232
- The official [prettier plugin for atom](https://github.com/prettier/prettier-atom) supports plugins.
233
-
234
227
  ### Visual Studio Code
235
228
 
236
229
  The official [prettier plugin for vscode](https://github.com/prettier/prettier-vscode) supports plugins since Version 1.10.0. To enable it, install the extension and make sure the plugin is installed _locally_ (in your project folder).
@@ -276,6 +269,10 @@ Sublime Text support is available through Package Control and the [JsPrettier](h
276
269
 
277
270
  The official [prettier plugin for vim](https://github.com/prettier/vim-prettier) has built-in support for plugin-php since 1.0.
278
271
 
272
+ ### Nova
273
+
274
+ The [Prettier⁺ Extension](https://extensions.panic.com/extensions/stonerl/stonerl.prettier/) has built-in support for plugin-php.
275
+
279
276
  #### ALE
280
277
 
281
278
  The linting plugin ALE has built-in support for prettier and its plugins. Just add prettier to your [list of fixers](https://github.com/w0rp/ale#2ii-fixing). For example:
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "prettier";
2
+
3
+ declare const plugin: Plugin;
4
+ export default plugin;
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
1
  {
2
2
  "name": "@prettier/plugin-php",
3
- "version": "0.22.4",
3
+ "version": "0.23.0",
4
4
  "description": "Prettier PHP Plugin",
5
5
  "repository": "prettier/prettier-php",
6
6
  "author": "Lucas Azzola <@azz>",
7
7
  "license": "MIT",
8
8
  "unpkg": "./standalone.js",
9
9
  "browser": "./standalone.js",
10
+ "types": "./index.d.ts",
10
11
  "exports": {
11
12
  ".": {
13
+ "types": "./index.d.ts",
12
14
  "browser": "./standalone.js",
13
15
  "default": "./src/index.mjs"
14
16
  },
15
- "./standalone": "./standalone.js",
17
+ "./standalone": {
18
+ "types": "./index.d.ts",
19
+ "default": "./standalone.js"
20
+ },
16
21
  "./package.json": "./package.json"
17
22
  },
18
23
  "files": [
19
24
  "src",
20
- "standalone.js"
25
+ "standalone.js",
26
+ "index.d.ts"
21
27
  ],
22
28
  "dependencies": {
23
- "linguist-languages": "^7.27.0",
24
- "php-parser": "^3.1.5"
29
+ "linguist-languages": "^8.0.0",
30
+ "php-parser": "^3.2.5"
25
31
  },
26
32
  "devDependencies": {
27
- "@babel/preset-env": "^7.23.6",
33
+ "@babel/preset-env": "^7.27.2",
28
34
  "@rollup/plugin-alias": "^5.1.0",
29
35
  "@rollup/plugin-babel": "^6.0.3",
30
36
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -33,7 +39,7 @@
33
39
  "@rollup/plugin-node-resolve": "^15.2.1",
34
40
  "@rollup/plugin-replace": "^5.0.5",
35
41
  "@rollup/plugin-terser": "^0.4.3",
36
- "c8": "^9.1.0",
42
+ "c8": "^10.1.3",
37
43
  "cross-env": "^7.0.2",
38
44
  "eslint": "8.57.0",
39
45
  "eslint-config-prettier": "9.1.0",
@@ -41,11 +47,11 @@
41
47
  "eslint-plugin-jest": "27.6.3",
42
48
  "eslint-plugin-prettier": "5.1.3",
43
49
  "eslint-plugin-prettier-doc": "^1.1.0",
44
- "jest": "29.7.0",
45
- "jest-environment-jsdom": "29.7.0",
46
- "jest-light-runner": "^0.6.0",
50
+ "jest": "30.0.3",
51
+ "jest-environment-jsdom": "30.0.2",
52
+ "jest-light-runner": "^0.7.9",
47
53
  "jest-snapshot-serializer-raw": "^2.0.0",
48
- "prettier": "^3.0.1",
54
+ "prettier": "^3.6.1",
49
55
  "rollup": "^3.28.1",
50
56
  "strip-ansi": "^7.1.0"
51
57
  },
package/src/index.mjs CHANGED
@@ -1,8 +1,6 @@
1
1
  import { doc } from "prettier";
2
- import {
3
- LINGUIST_LANGUAGES_PHP,
4
- LINGUIST_LANGUAGES_HTML_PHP,
5
- } from "./linguist-languages.cjs";
2
+ import LINGUIST_LANGUAGES_PHP from "linguist-languages/data/PHP";
3
+ import LINGUIST_LANGUAGES_HTML_PHP from "linguist-languages/data/HTML_2b_PHP";
6
4
  import parse from "./parser.mjs";
7
5
  import print from "./printer.mjs";
8
6
  import clean from "./clean.mjs";
@@ -1,6 +1,11 @@
1
- import { getPrecedence, shouldFlatten, isBitwiseOperator } from "./util.mjs";
2
-
3
- function needsParens(path) {
1
+ import {
2
+ getPrecedence,
3
+ shouldFlatten,
4
+ isBitwiseOperator,
5
+ isMinVersion,
6
+ } from "./util.mjs";
7
+
8
+ function needsParens(path, options) {
4
9
  const { parent } = path;
5
10
 
6
11
  if (!parent) {
@@ -128,13 +133,16 @@ function needsParens(path) {
128
133
  }
129
134
  case "clone":
130
135
  case "new": {
136
+ const requiresParens =
137
+ node.kind === "clone" ||
138
+ (node.kind === "new" && !isMinVersion(options.phpVersion, "8.4"));
131
139
  switch (parent.kind) {
132
140
  case "propertylookup":
133
141
  case "nullsafepropertylookup":
134
142
  case "staticlookup":
135
143
  case "offsetlookup":
136
144
  case "call":
137
- return key === "what";
145
+ return key === "what" && requiresParens;
138
146
  default:
139
147
  return false;
140
148
  }
package/src/options.mjs CHANGED
@@ -23,6 +23,8 @@ export default {
23
23
  { value: "8.0" },
24
24
  { value: "8.1" },
25
25
  { value: "8.2" },
26
+ { value: "8.3" },
27
+ { value: "8.4" },
26
28
  ],
27
29
  },
28
30
  trailingCommaPHP: {
package/src/parser.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import engine from "php-parser";
2
+ import options from "./options.mjs";
2
3
 
3
4
  function parse(text, opts) {
4
5
  const inMarkdown = opts && opts.parentParser === "markdown";
@@ -10,10 +11,15 @@ function parse(text, opts) {
10
11
  // Todo https://github.com/glayzzle/php-parser/issues/170
11
12
  text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___<?");
12
13
 
14
+ const latestSupportedPhpVersion = Math.max(
15
+ ...options.phpVersion.choices.map((c) => parseFloat(c.value))
16
+ );
17
+
13
18
  // initialize a new parser instance
14
19
  const parser = new engine({
15
20
  parser: {
16
21
  extractDoc: true,
22
+ version: `${latestSupportedPhpVersion}`,
17
23
  },
18
24
  ast: {
19
25
  withPositions: true,
package/src/printer.mjs CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  isReferenceLikeNode,
38
38
  normalizeMagicMethodName,
39
39
  isSimpleCallArgument,
40
+ isMinVersion,
40
41
  } from "./util.mjs";
41
42
 
42
43
  const {
@@ -65,10 +66,6 @@ const {
65
66
  isPreviousLineEmpty,
66
67
  } = prettierUtil;
67
68
 
68
- function isMinVersion(actualVersion, requiredVersion) {
69
- return parseFloat(actualVersion) >= parseFloat(requiredVersion);
70
- }
71
-
72
69
  function shouldPrintComma(options, requiredVersion) {
73
70
  if (!options.trailingCommaPHP) {
74
71
  return false;
@@ -2308,6 +2305,7 @@ function printNode(path, options, print) {
2308
2305
  node.final ? "final " : "",
2309
2306
  node.visibility ? [node.visibility, " "] : "",
2310
2307
  "const",
2308
+ node.type ? [node.nullable ? " ?" : " ", print("type")] : "",
2311
2309
  firstVariable ? [" ", firstVariable] : "",
2312
2310
  indent(printed.slice(1).map((p) => [",", hardline, p])),
2313
2311
  ]);
package/src/util.mjs CHANGED
@@ -709,6 +709,10 @@ function memoize(fn) {
709
709
  };
710
710
  }
711
711
 
712
+ function isMinVersion(actualVersion, requiredVersion) {
713
+ return parseFloat(actualVersion) >= parseFloat(requiredVersion);
714
+ }
715
+
712
716
  export {
713
717
  printNumber,
714
718
  getPrecedence,
@@ -740,4 +744,5 @@ export {
740
744
  normalizeMagicMethodName,
741
745
  isSimpleCallArgument,
742
746
  memoize,
747
+ isMinVersion,
743
748
  };