From f3cd3a42d982df3f4be38541bf081c01d19ebbdb Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sun, 19 Jun 2022 18:42:51 +0300 Subject: [PATCH] feat: add rules for trailing commas in function declarations --- Makefile | 4 +- lib/Doctrine/ruleset.xml | 8 ++ tests/fixed/TralingCommaOnFunctions.php | 17 ++++ tests/input/TralingCommaOnFunctions.php | 17 ++++ tests/php80-compatibility.patch | 125 +++++++++++++++++++++++- 5 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 tests/fixed/TralingCommaOnFunctions.php create mode 100644 tests/input/TralingCommaOnFunctions.php diff --git a/Makefile b/Makefile index 7c6c5c69..95c866ff 100644 --- a/Makefile +++ b/Makefile @@ -21,14 +21,14 @@ update-compatibility-patch-74: @git apply tests/php74-compatibility.patch @printf "Please open your editor and apply your changes\n" @until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved= - @git diff -- tests/expected_report.txt tests/fixed > .tmp-patch && mv .tmp-patch tests/php74-compatibility.patch && git apply -R tests/php74-compatibility.patch + @git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php74-compatibility.patch && git apply -R tests/php74-compatibility.patch @git commit -m 'Update compatibility patch' tests/php74-compatibility.patch update-compatibility-patch-80: @git apply tests/php80-compatibility.patch @printf "Please open your editor and apply your changes\n" @until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved= - @git diff -- tests/expected_report.txt tests/fixed > .tmp-patch-80 && mv .tmp-patch-80 tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch + @git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch-80 && mv .tmp-patch-80 tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch @git commit -m 'Update compatibility patch' tests/php80-compatibility.patch vendor: composer.json diff --git a/lib/Doctrine/ruleset.xml b/lib/Doctrine/ruleset.xml index ae7ca301..b4a65632 100644 --- a/lib/Doctrine/ruleset.xml +++ b/lib/Doctrine/ruleset.xml @@ -284,6 +284,14 @@ + + + + + + + + diff --git a/tests/fixed/TralingCommaOnFunctions.php b/tests/fixed/TralingCommaOnFunctions.php new file mode 100644 index 00000000..ed304c9f --- /dev/null +++ b/tests/fixed/TralingCommaOnFunctions.php @@ -0,0 +1,17 @@ +property; +$var = $object?->property; +diff --git a/tests/fixed/return_type_on_closures.php b/tests/fixed/return_type_on_closures.php +index 134bade..80ad413 100644 +--- a/tests/fixed/return_type_on_closures.php ++++ b/tests/fixed/return_type_on_closures.php +@@ -22,7 +22,7 @@ static function ( + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -31,7 +31,7 @@ static function ( + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -40,7 +40,7 @@ static function ( + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -49,7 +49,7 @@ static function ( + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -58,6 +58,6 @@ static function ( + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } +diff --git a/tests/fixed/return_type_on_methods.php b/tests/fixed/return_type_on_methods.php +index 8e2c6f7..0c897ae 100644 +--- a/tests/fixed/return_type_on_methods.php ++++ b/tests/fixed/return_type_on_methods.php +@@ -31,7 +31,7 @@ class Test + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -40,7 +40,7 @@ class Test + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -49,7 +49,7 @@ class Test + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -58,7 +58,7 @@ class Test + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + +@@ -67,7 +67,7 @@ class Test + int $c, + int $d, + int $e, +- int $b ++ int $b, + ): void { + } + } diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php -index 6033eca..5e26ed8 100644 +index 10e6f34..5e26ed8 100644 --- a/tests/fixed/type-hints.php +++ b/tests/fixed/type-hints.php @@ -10,7 +10,7 @@ use Traversable; @@ -226,3 +336,16 @@ index 6033eca..5e26ed8 100644 - private $x = 1; + private int|string|null $x = 1; } +diff --git a/tests/input/TralingCommaOnFunctions.php b/tests/input/TralingCommaOnFunctions.php +index ed304c9..e383ee2 100644 +--- a/tests/input/TralingCommaOnFunctions.php ++++ b/tests/input/TralingCommaOnFunctions.php +@@ -6,7 +6,7 @@ namespace Doctrine; + + class TralingCommaOnFunctions + { +- public function a(int $arg): void ++ public function a(int $arg,): void + { + } +