Skip to content

Commit

Permalink
feat: make format compatible with "PER Coding Style 2.0" (#2269)
Browse files Browse the repository at this point in the history
* feat: make format compatible with phpcsfixer

* feat: add missing tests

* feat: add missing test case

* feat: move readonly modifier after abstract
  • Loading branch information
ferchoz authored Dec 16, 2023
1 parent 69a68d8 commit e3f8cba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,6 @@ function printClass(path, options, print) {
const attrs = printAttrs(path, options, print, { inline: isAnonymousClass });
const declaration = isAnonymousClass ? [] : [...attrs];

if (node.isReadonly) {
declaration.push("readonly ");
}

if (node.isFinal) {
declaration.push("final ");
}
Expand All @@ -1216,6 +1212,10 @@ function printClass(path, options, print) {
declaration.push("abstract ");
}

if (node.isReadonly) {
declaration.push("readonly ");
}

// `new` print `class` keyword with arguments
declaration.push(isAnonymousClass ? "" : node.kind);

Expand Down
24 changes: 24 additions & 0 deletions tests/class/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,18 @@ final class BaseClass {}
abstract class BaseClass {}
final readonly class BaseClass {}
readonly final class BaseClass {}
final class BaseClass extends MyOtherClass {}
abstract class BaseClass extends MyOtherClass {}
final readonly class BaseClass extends MyOtherClass {}
readonly final class BaseClass extends MyOtherClass {}
final class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass {}
abstract class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass {}
Expand Down Expand Up @@ -1398,6 +1406,14 @@ abstract class BaseClass
{
}
final readonly class BaseClass
{
}
final readonly class BaseClass
{
}
final class BaseClass extends MyOtherClass
{
}
Expand All @@ -1406,6 +1422,14 @@ abstract class BaseClass extends MyOtherClass
{
}
final readonly class BaseClass extends MyOtherClass
{
}
final readonly class BaseClass extends MyOtherClass
{
}
final class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass
{
}
Expand Down
8 changes: 8 additions & 0 deletions tests/class/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,18 @@ final class BaseClass {}

abstract class BaseClass {}

final readonly class BaseClass {}

readonly final class BaseClass {}

final class BaseClass extends MyOtherClass {}

abstract class BaseClass extends MyOtherClass {}

final readonly class BaseClass extends MyOtherClass {}

readonly final class BaseClass extends MyOtherClass {}

final class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVeryVeryLongClass {}

abstract class BaseClass extends MyOtherVeryVeryVeryVeVeryVeryVeryVVeryLongClass {}
Expand Down

0 comments on commit e3f8cba

Please sign in to comment.