Skip to content
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

Add attribute sniffs #298

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "^7.2 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
"slevomat/coding-standard": "^8.5.1",
"slevomat/coding-standard": "^8.6",
"squizlabs/php_codesniffer": "^3.7"
},
"config": {
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
<type>error</type>
</rule>
<!-- Disallow multiple attributes inside one #[] -->
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
<!-- Require only one attribute per line -->
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
<!-- Attributes should be adjoined to the PHP element they belong to -->
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/>
<!-- Require PHPDoc always before attributes -->
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
<!-- Require that single line arrays have the correct spacing: no space around brackets and one space after comma -->
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
<!-- Require comma after last element in multi-line array -->
Expand Down
5 changes: 3 additions & 2 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FILE ERRORS WARNINGS
tests/input/array_indentation.php 10 0
tests/input/arrow-functions-format.php 10 0
tests/input/assignment-operators.php 4 0
tests/input/attributes.php 15 0
tests/input/binary_operators.php 9 0
tests/input/class-references.php 10 0
tests/input/ClassPropertySpacing.php 2 0
Expand Down Expand Up @@ -51,9 +52,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
A TOTAL OF 437 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
A TOTAL OF 452 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


32 changes: 32 additions & 0 deletions tests/fixed/attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

#[Attribute1]
#[Attribute2]
#[Attribute3]
class TestClass
{
}

#[Attribute1]
#[Attribute2]
#[Attribute3]
class TestClass2
{
}

#[Attribute1]
#[Attribute2]
#[Attribute3]
class TestClass3
{
}

/** @internal */
#[Attribute1]
#[Attribute2]
#[Attribute3]
class TestClass4
{
}
31 changes: 31 additions & 0 deletions tests/input/attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

#[Attribute1] #[Attribute2]
#[Attribute3]
class TestClass
{
}

#[Attribute1,Attribute2]
#[Attribute3]
class TestClass2
{
}

#[Attribute1]
#[Attribute2]
#[Attribute3]

class TestClass3
{
}

#[Attribute1]
#[Attribute2]
#[Attribute3]
/** @internal */
class TestClass4
{
}
14 changes: 7 additions & 7 deletions tests/php72-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 151bce4..0afca8c 100644
index 9e34caa..ea3b611 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -14,26 +14,23 @@ tests/input/constants-var.php 7 0
@@ -16,26 +16,23 @@ tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -37,7 +37,7 @@ index 151bce4..0afca8c 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -42,17 +39,16 @@ tests/input/strings.php 1 0
@@ -44,17 +41,16 @@ 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
Expand All @@ -51,11 +51,11 @@ index 151bce4..0afca8c 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 437 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
+A TOTAL OF 390 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
-A TOTAL OF 452 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 405 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 323 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 327 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
14 changes: 7 additions & 7 deletions tests/php73-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 151bce4..94718eb 100644
index 9e34caa..c5062cb 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -14,26 +14,23 @@ tests/input/constants-var.php 7 0
@@ -16,26 +16,23 @@ tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -37,7 +37,7 @@ index 151bce4..94718eb 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -42,17 +39,17 @@ tests/input/strings.php 1 0
@@ -44,17 +41,17 @@ 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
Expand All @@ -52,11 +52,11 @@ index 151bce4..94718eb 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 437 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
+A TOTAL OF 392 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
-A TOTAL OF 452 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 407 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 325 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 329 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
14 changes: 7 additions & 7 deletions tests/php74-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 151bce4..08a098f 100644
index 9e34caa..ed67841 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -14,26 +14,23 @@ tests/input/constants-var.php 7 0
@@ -16,26 +16,23 @@ tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -35,7 +35,7 @@ index 151bce4..08a098f 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -42,17 +39,17 @@ tests/input/strings.php 1 0
@@ -44,17 +41,17 @@ 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
Expand All @@ -50,11 +50,11 @@ index 151bce4..08a098f 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 437 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
+A TOTAL OF 401 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
-A TOTAL OF 452 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 416 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 334 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 338 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
16 changes: 8 additions & 8 deletions tests/php80-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 151bce4..873691d 100644
index 9e34caa..71022c4 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -16,7 +16,6 @@ tests/input/doc-comment-spacing.php 11 0
@@ -18,7 +18,6 @@ tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 7 0
tests/input/example-class.php 47 0
-tests/input/ExampleBackedEnum.php 3 0
tests/input/Exceptions.php 1 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
@@ -31,7 +30,7 @@ tests/input/null_coalesce_equal_operator.php 5 0
@@ -33,7 +32,7 @@ tests/input/null_coalesce_equal_operator.php 5 0
tests/input/null_coalesce_operator.php 3 0
tests/input/null_safe_operator.php 1 0
tests/input/optimized-functions.php 1 0
Expand All @@ -19,15 +19,15 @@ index 151bce4..873691d 100644
tests/input/return_type_on_closures.php 26 0
tests/input/return_type_on_methods.php 22 0
tests/input/semicolon_spacing.php 3 0
@@ -50,9 +49,9 @@ tests/input/use-ordering.php 1 0
@@ -52,9 +51,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-A TOTAL OF 437 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
+A TOTAL OF 431 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
-A TOTAL OF 452 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 446 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 364 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 368 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down