Skip to content

Commit

Permalink
feat: add rules for trailing commas in function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jun 19, 2022
1 parent 05e593b commit 27054ef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ruleset.xml
Expand Up @@ -284,6 +284,14 @@
<property name="spacesCountAfterArrow" value="1"/>
</properties>
</rule>
<!-- Disallow trailing commas in single line function declarations -->
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration">
<properties>
<property name="onlySingleLine" value="true" />
</properties>
</rule>
<!-- Require trailing commas in multiline function declarations -->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<!-- Require closures not referencing $this be static -->
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
<!-- Forbid unused variables passed to closures via `use` -->
Expand Down
17 changes: 17 additions & 0 deletions tests/fixed/TralingCommaOnFunctions.php
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Doctrine;

class TralingCommaOnFunctions
{
public function a(int $arg): void
{
}

public function b(
int $arg
): void {
}
}
17 changes: 17 additions & 0 deletions tests/input/TralingCommaOnFunctions.php
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Doctrine;

class TralingCommaOnFunctions
{
public function a(int $arg): void
{
}

public function b(
int $arg
): void {
}
}

0 comments on commit 27054ef

Please sign in to comment.