Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9c04ccb
update parser to @jorgsowa/php-parser
jorgsowa Jan 11, 2026
c2e38c1
update GH actions
jorgsowa Jan 11, 2026
a68feaa
build(deps-dev): bump @rollup/plugin-node-resolve from 15.3.1 to 16.0.3
dependabot[bot] Jan 11, 2026
b35fa5a
feat: propertyhooks
jorgsowa Jan 11, 2026
40192f3
Merge pull request #10 from jorgsowa/dependabot/npm_and_yarn/rollup/p…
jorgsowa Jan 11, 2026
b6eb2ae
build(deps-dev): bump strip-ansi from 7.1.0 to 7.1.2
dependabot[bot] Jan 11, 2026
3a55060
Merge pull request #11 from jorgsowa/feat/format-property-hook
jorgsowa Jan 11, 2026
bac1f89
build(deps-dev): bump jest-light-runner from 0.7.9 to 0.7.10
dependabot[bot] Jan 11, 2026
6625886
build(deps-dev): bump eslint-plugin-prettier from 5.1.3 to 5.5.4
dependabot[bot] Jan 11, 2026
10ede0f
build(deps-dev): bump @babel/preset-env from 7.27.2 to 7.28.5
dependabot[bot] Jan 11, 2026
2f0a410
build(deps): bump linguist-languages from 8.0.0 to 9.2.0
dependabot[bot] Jan 11, 2026
fb6a26f
Merge pull request #9 from jorgsowa/dependabot/npm_and_yarn/strip-ans…
jorgsowa Jan 11, 2026
46f2369
Merge pull request #5 from jorgsowa/dependabot/npm_and_yarn/jest-ligh…
jorgsowa Jan 11, 2026
0fc0e79
Merge pull request #2 from jorgsowa/dependabot/npm_and_yarn/eslint-pl…
jorgsowa Jan 11, 2026
e78b769
build(deps-dev): bump rollup from 3.29.5 to 4.55.1
dependabot[bot] Jan 11, 2026
490cc49
Merge pull request #8 from jorgsowa/dependabot/npm_and_yarn/rollup-4.…
jorgsowa Jan 11, 2026
f3c1664
Merge pull request #6 from jorgsowa/dependabot/npm_and_yarn/linguist-…
jorgsowa Jan 11, 2026
9452982
Merge pull request #7 from jorgsowa/dependabot/npm_and_yarn/babel/pre…
jorgsowa Jan 11, 2026
ab9fabc
removed console.log
jorgsowa Jan 11, 2026
e4ae4a1
update deps
jorgsowa Jan 11, 2026
4bf8b2b
update version to 0.24.0-1
jorgsowa Jan 11, 2026
a669c1d
build(deps-dev): bump @rollup/plugin-babel from 6.0.4 to 6.1.0
dependabot[bot] Jan 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
cache: "yarn"
- run: yarn install --frozen-lockfile
Expand All @@ -37,15 +37,16 @@ jobs:
AST_COMPARE: true

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: yarn c8 yarn test:node
- uses: codecov/codecov-action@v5
if: false
with:
fail_ci_if_error: true
disable_search: true
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@prettier/plugin-php",
"version": "0.24.0",
"name": "@jorgsowa/prettier-plugin-php",
"version": "0.24.0-1",
"description": "Prettier PHP Plugin",
"repository": "prettier/prettier-php",
"repository": "jorgsowa/plugin-php",
"author": "Lucas Azzola <@azz>",
"license": "MIT",
"unpkg": "./standalone.js",
Expand All @@ -26,8 +26,8 @@
"index.d.ts"
],
"dependencies": {
"linguist-languages": "^8.0.0",
"php-parser": "^3.2.5"
"@jorgsowa/php-parser": "3.2.5-7",
"linguist-languages": "^9.2.0"
},
"devDependencies": {
"@babel/preset-env": "^7.27.2",
Expand All @@ -36,7 +36,7 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.3",
"c8": "^10.1.3",
Expand All @@ -45,14 +45,14 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "27.6.3",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-prettier": "5.5.4",
"eslint-plugin-prettier-doc": "^1.1.0",
"jest": "30.0.3",
"jest-environment-jsdom": "30.0.2",
"jest-light-runner": "^0.7.9",
"jest-snapshot-serializer-raw": "^2.0.0",
"prettier": "^3.6.1",
"rollup": "^3.28.1",
"rollup": "^4.55.1",
"strip-ansi": "^7.1.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/parser.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import engine from "php-parser";
import engine from "@jorgsowa/php-parser";
import { LATEST_SUPPORTED_PHP_VERSION } from "./options.mjs";
import { resolvePhpVersion } from "./options.mjs";

Expand Down
66 changes: 66 additions & 0 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,39 @@ function printAttrs(path, options, print, { inline = false } = {}) {
return [...allAttrs, inline ? "" : hardline];
}

function printPropertyHook(path, options, print, hook) {
const parts = [];
if (hook.byref) {
parts.push("&");
}
if (hook.visibility) {
parts.push(hook.visibility, " ");
}
if (hook.isFinal) {
parts.push("final ");
}
parts.push(hook.name);

if (hook.parameter) {
path.call((parameterPath) => {
parts.push("(", print(parameterPath), ")");
}, "parameter");
}

if (hook.body) {
if (hook.body.kind === "block") {
parts.push(" ", "{", indent([line, path.call(print, "body")]), line, "}");
} else {
parts.push(
" => ",
path.call((p) => print(p), "body"),
";"
);
}
}
return group(parts);
}

function printClass(path, options, print) {
const { node } = path;
const isAnonymousClass = node.kind === "class" && node.isAnonymous;
Expand Down Expand Up @@ -1782,6 +1815,7 @@ function printNode(path, options, print) {
case "variadic":
return ["...", print("what")];
case "property":
const isInterface = getAncestorNode(path, "interface");
return group([
node.readonly ? "readonly " : "",
node.type ? [node.nullable ? "?" : "", print("type"), " "] : "",
Expand All @@ -1799,6 +1833,38 @@ function printNode(path, options, print) {
),
]
: "",
node.hooks && node.hooks.length > 0 && options.phpVersion >= 8.4
? isInterface
? [
" { ",
join(
" ",
path.map(
(p) => [
printPropertyHook(p, options, print, p.node),
p.node.body ? "" : ";",
],
"hooks"
)
),
" }",
]
: [
" {",
indent([
hardline,
join(
[hardline, hardline],
path.map(
(p) => printPropertyHook(p, options, print, p.node),
"hooks"
)
),
]),
hardline,
"}",
]
: "",
]);
case "propertystatement": {
const attrs = [];
Expand Down
6 changes: 6 additions & 0 deletions src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ function lineShouldEndWithSemicolon(path) {
return true;
}
}
if (
node.kind === "propertystatement" &&
node.properties.some((p) => p.hooks && p.hooks.length > 0)
) {
return false;
}
return [
"expressionstatement",
"do",
Expand Down
59 changes: 59 additions & 0 deletions tests/class/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,37 @@ class Bar extends Foo {
public const ?int J = null;
}

class B
{
public string $bar {
get {
return $this->bar;
}
}

public string $bar2 {
get => $this->bar2;
}

public string $foo {
set => $this->foo = $value;
}

public string $foo2 {
set(string $value2) {
{
$this->bar = $value2;
$this->foo2 = 'something';
}
}
}
}

interface ABC {
public string $foo { get; }
public string $bar { set; }
}

=====================================output=====================================
<?php

Expand Down Expand Up @@ -1423,5 +1454,33 @@ class Bar extends Foo
public const ?int J = null;
}

class B
{
public string $bar {
get { return $this->bar; }
}

public string $bar2 {
get => $this->bar2;
}

public string $foo {
set => ($this->foo = $value);
}

public string $foo2 {
set(string $value2) {
$this->bar = $value2;
$this->foo2 = "something";
}
}
}

interface ABC
{
public string $foo { get; }
public string $bar { set; }
}

================================================================================
`;
31 changes: 31 additions & 0 deletions tests/class/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,34 @@ class Bar extends Foo {
public const int|null I = null;
public const ?int J = null;
}

class B
{
public string $bar {
get {
return $this->bar;
}
}

public string $bar2 {
get => $this->bar2;
}

public string $foo {
set => $this->foo = $value;
}

public string $foo2 {
set(string $value2) {
{
$this->bar = $value2;
$this->foo2 = 'something';
}
}
}
}

interface ABC {
public string $foo { get; }
public string $bar { set; }
}
46 changes: 46 additions & 0 deletions tests/property/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ string
string' . 'string
string
string';

public $string3 { get => 'string'; }
public $string13 { &get => 'string'; }
public $string4 { get => $this->string4; }
public $string5 { final get => $this->string5; }
public $string6 { set => $this->string6 = $value; }
public $string7 { set => $this->string7 = $value; }
public string $string8 { set(string $value) => $this->string8 = $value; }
public string $string9 { set(string $value) { $this->string9 = $value; }}
public string $string10 { set { $this->string10 = $value; }}
public $string11 { final set => $this->string11 = $value; }
public $string12 { get { return $this->string12; } }
}

=====================================output=====================================
Expand Down Expand Up @@ -99,6 +111,40 @@ string' .
'string
string
string';

public $string3 {
get => "string";
}
public $string13 {
&get => "string";
}
public $string4 {
get => $this->string4;
}
public $string5 {
final get => $this->string5;
}
public $string6 {
set => ($this->string6 = $value);
}
public $string7 {
set => ($this->string7 = $value);
}
public string $string8 {
set(string $value) => ($this->string8 = $value);
}
public string $string9 {
set(string $value) { $this->string9 = $value; }
}
public string $string10 {
set { $this->string10 = $value; }
}
public $string11 {
final set => ($this->string11 = $value);
}
public $string12 {
get { return $this->string12; }
}
}

================================================================================
Expand Down
12 changes: 12 additions & 0 deletions tests/property/property.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ class Foo
string' . 'string
string
string';

public $string3 { get => 'string'; }
public $string13 { &get => 'string'; }
public $string4 { get => $this->string4; }
public $string5 { final get => $this->string5; }
public $string6 { set => $this->string6 = $value; }
public $string7 { set => $this->string7 = $value; }
public string $string8 { set(string $value) => $this->string8 = $value; }
public string $string9 { set(string $value) { $this->string9 = $value; }}
public string $string10 { set { $this->string10 = $value; }}
public $string11 { final set => $this->string11 = $value; }
public $string12 { get { return $this->string12; } }
}
Loading