Skip to content

Commit

Permalink
feat: add rules for trailing commas in function calls and closure use
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jul 8, 2022
1 parent cd23eb3 commit 1e3c90e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Doctrine/ruleset.xml
Expand Up @@ -291,12 +291,28 @@
<property name="spacesCountAfterArrow" value="1"/>
</properties>
</rule>
<!-- Disallow trailing commas in single line function calls -->
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall">
<properties>
<property name="onlySingleLine" value="true" />
</properties>
</rule>
<!-- Disallow trailing commas in single line closure use -->
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse">
<properties>
<property name="onlySingleLine" value="true" />
</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 calls -->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<!-- Require trailing commas in multiline closure use -->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
<!-- Require trailing commas in multiline function declarations -->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<!-- Require closures not referencing $this be static -->
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -12,6 +12,7 @@

<!-- Show progress of the run -->
<arg value="p"/>
<arg value="s"/>

<rule ref="Doctrine"/>

Expand Down
27 changes: 27 additions & 0 deletions tests/fixed/TrailingCommaOnFunctions.php
Expand Up @@ -4,6 +4,10 @@

namespace Doctrine;

use function var_dump;

// phpcs:disable PSR1.Files.SideEffects

class TrailingCommaOnFunctions
{
public function a(int $arg): void
Expand All @@ -14,4 +18,27 @@ public function b(
int $arg
): void {
}

public function uses(): void
{
$var = null;

$singleLine = static function (int $arg) use ($var): void {
var_dump($var);
};

$multiLine = static function (int $arg) use (
$var
): void {
var_dump($var);
};
}
}

$class = new TrailingCommaOnFunctions();

$class->a(1);

$class->a(
1
);
28 changes: 28 additions & 0 deletions tests/input/TrailingCommaOnFunctions.php
Expand Up @@ -4,6 +4,10 @@

namespace Doctrine;

use function var_dump;

// phpcs:disable PSR1.Files.SideEffects

class TrailingCommaOnFunctions
{
public function a(int $arg): void
Expand All @@ -14,4 +18,28 @@ public function b(
int $arg
): void {
}

public function uses(): void
{
$var = null;

$singleLine = static function (int $arg) use ($var): void {
var_dump($var);
};

$multiLine = static function (int $arg) use (
$var
): void {
var_dump($var);
};
}
}

$class = new TrailingCommaOnFunctions();

$class->a(1);

$class->a(
1
);

0 comments on commit 1e3c90e

Please sign in to comment.