New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add rules for trailing commas in function calls and closure use
#270
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,7 @@ jobs: | |
matrix: | ||
php-version: | ||
- "7.2" | ||
- "7.3" | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
diff --git a/tests/expected_report.txt b/tests/expected_report.txt | ||
index 1d5a7d3..fae9e70 100644 | ||
--- a/tests/expected_report.txt | ||
+++ b/tests/expected_report.txt | ||
@@ -39,6 +39,7 @@ tests/input/strings.php 1 0 | ||
tests/input/superfluous-naming.php 11 0 | ||
tests/input/test-case.php 8 0 | ||
tests/input/trailing_comma_on_array.php 1 0 | ||
+tests/input/TrailingCommaOnFunctions.php 2 0 | ||
tests/input/traits-uses.php 11 0 | ||
tests/input/type-hints.php 7 0 | ||
tests/input/UnusedVariables.php 1 0 | ||
@@ -46,9 +47,9 @@ tests/input/use-ordering.php 1 0 | ||
tests/input/useless-semicolon.php 2 0 | ||
tests/input/UselessConditions.php 20 0 | ||
---------------------------------------------------------------------- | ||
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES | ||
+A TOTAL OF 383 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES | ||
---------------------------------------------------------------------- | ||
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY | ||
+PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY | ||
---------------------------------------------------------------------- | ||
|
||
|
||
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php | ||
index f3ffa91..67173b3 100644 | ||
--- a/tests/fixed/TrailingCommaOnFunctions.php | ||
+++ b/tests/fixed/TrailingCommaOnFunctions.php | ||
@@ -37,8 +37,9 @@ class TrailingCommaOnFunctions | ||
|
||
$class = new TrailingCommaOnFunctions(); | ||
|
||
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma | ||
$class->a(1); | ||
|
||
$class->a( | ||
- 1 | ||
+ 1, | ||
); | ||
diff --git a/tests/fixed/arrow-functions-format.php b/tests/fixed/arrow-functions-format.php | ||
index a45074f..4da39b8 100644 | ||
--- a/tests/fixed/arrow-functions-format.php | ||
+++ b/tests/fixed/arrow-functions-format.php | ||
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass(); | ||
|
||
$multiLineArrowFunctions = Collection::from([1, 2]) | ||
->map( | ||
- static fn (int $v): int => $v * 2 | ||
+ static fn (int $v): int => $v * 2, | ||
) | ||
->reduce( | ||
- static fn (int $tmp, int $v): int => $tmp + $v | ||
+ static fn (int $tmp, int $v): int => $tmp + $v, | ||
); | ||
|
||
$thisIsNotAnArrowFunction = [$this->fn => 'value']; | ||
diff --git a/tests/fixed/namespaces-spacing.php b/tests/fixed/namespaces-spacing.php | ||
index d42bbfe..36cbae2 100644 | ||
--- a/tests/fixed/namespaces-spacing.php | ||
+++ b/tests/fixed/namespaces-spacing.php | ||
@@ -16,5 +16,5 @@ use const DATE_RFC3339; | ||
strrev( | ||
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC'))) | ||
->sub(new DateInterval('P1D')) | ||
- ->format(DATE_RFC3339) | ||
+ ->format(DATE_RFC3339), | ||
); | ||
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php | ||
index f3ffa91..8adcedf 100644 | ||
--- a/tests/input/TrailingCommaOnFunctions.php | ||
+++ b/tests/input/TrailingCommaOnFunctions.php | ||
@@ -37,7 +37,8 @@ class TrailingCommaOnFunctions | ||
|
||
$class = new TrailingCommaOnFunctions(); | ||
|
||
-$class->a(1); | ||
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma | ||
+$class->a(1,); | ||
|
||
$class->a( | ||
1 | ||
diff --git a/tests/input/arrow-functions-format.php b/tests/input/arrow-functions-format.php | ||
index 8a358e8..d3903ff 100644 | ||
--- a/tests/input/arrow-functions-format.php | ||
+++ b/tests/input/arrow-functions-format.php | ||
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass(); | ||
|
||
$multiLineArrowFunctions = Collection::from([1, 2]) | ||
->map( | ||
- static fn (int $v): int => $v * 2 | ||
+ static fn (int $v): int => $v * 2, | ||
) | ||
->reduce( | ||
- static fn (int $tmp, int $v): int => $tmp + $v | ||
+ static fn (int $tmp, int $v): int => $tmp + $v, | ||
); | ||
|
||
$thisIsNotAnArrowFunction = [$this->fn => 'value']; | ||
diff --git a/tests/input/namespaces-spacing.php b/tests/input/namespaces-spacing.php | ||
index e1ab639..e7be018 100644 | ||
--- a/tests/input/namespaces-spacing.php | ||
+++ b/tests/input/namespaces-spacing.php | ||
@@ -11,5 +11,5 @@ use const DATE_RFC3339; | ||
strrev( | ||
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC'))) | ||
->sub(new DateInterval('P1D')) | ||
- ->format(DATE_RFC3339) | ||
+ ->format(DATE_RFC3339), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need these? They are EOL and abandoned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maintenance is kind of burden. I basically have to patch test inputs and outputs for each php version so I can add tests for new sniffs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I was suggesting to drop support overall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that was an agreement from my side :D
but as discussed #268 (comment)