Skip to content

Commit

Permalink
Configure sniffs for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicwortel committed Jun 15, 2023
1 parent 5c5888a commit 1b0e67b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NicWortel/ruleset.xml
Expand Up @@ -83,6 +83,10 @@
</properties>
</rule>

<!-- Force attributes to be directly above their target and disallow multiple attributes on 1 line -->
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/>
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>

<!-- Disallow commented out code -->
<rule ref="Squiz.PHP.CommentedOutCode"/>
</ruleset>
12 changes: 12 additions & 0 deletions tests/correct/attributes.php
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Foo;

class Bar
{
#[Attribute1]
#[Attribute2]
private string $foo;
}
2 changes: 2 additions & 0 deletions tests/expected.csv
@@ -1,5 +1,7 @@
"tests/incorrect/arrays.php",10,5,error,"Multi-line arrays must have a trailing comma after the last element.",SlevomatCodingStandard.Arrays.TrailingArrayComma.MissingTrailingComma,5,1
"tests/incorrect/arrays.php",5,20,error,"Short array syntax must be used to define arrays",Generic.Arrays.DisallowLongArraySyntax.Found,5,1
"tests/incorrect/attributes.php",11,19,error,"Multiple attributes per line are disallowed.",SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine.DisallowedMultipleAttributesPerLine,5,1
"tests/incorrect/attributes.php",9,5,error,"Expected 0 blank lines between attribute and its target, both are on same line.",SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing.IncorrectLinesCountBetweenAttributeAndTarget,5,1
"tests/incorrect/class-constant-visibility.php",9,5,error,"Visibility must be declared on all constants if your project supports PHP 7.1 or later",PSR12.Properties.ConstantVisibility.NotFound,5,0
"tests/incorrect/commented-out-code.php",5,1,warning,"This comment is 50% valid code; is this commented out code?",Squiz.PHP.CommentedOutCode.Found,5,0
"tests/incorrect/commenting.php",10,4,error,"Use of annotation @version is forbidden.",SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden,5,1
Expand Down
13 changes: 13 additions & 0 deletions tests/incorrect/attributes.php
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Foo;

class Bar
{
#[Attribute] private string $foo;

#[Attribute1] #[Attribute2]
private bool $bar;
}

0 comments on commit 1b0e67b

Please sign in to comment.