⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

# Tests
.phpunit.result.cache

# Code coverage report
html-coverage
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"scripts": {
"parallel-lint": "parallel-lint . --exclude vendor",
"phpcs": "phpcs -p -s",
"phpunit": "phpunit",
"phpunit": "php -d extension=pcov.so -d pcov.enabled=1 -d pcov.directory=. vendor/bin/phpunit",
"lint": [
"@parallel-lint",
"@phpcs"
Expand Down
10 changes: 10 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
<directory>./src/Tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src/Sniffs</directory>
</include>
</source>
<coverage includeUncoveredFiles="true">
<report>
<html outputDirectory="html-coverage" />
</report>
</coverage>
</phpunit>
14 changes: 8 additions & 6 deletions src/Sniffs/Attributes/AttributeAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ public function process( File $phpcsFile, $stackPtr ) {
);
}

// Clear all of the other whitespace tokens before the attribute; this
// works for both cases because if the attribute was the start of the
// line then $iii will start at $stackPtr and the loop never runs
for ( $iii = $targetLineStart; $iii < $stackPtr - 1; $iii++ ) {
$phpcsFile->fixer->replaceToken( $iii, '' );
}
// Apparently we don't need to worry about the other whitespace tokens
// that came before the stack pointer, I could not figure out a way to
// trigger needing to remove them, so the code for that was removed
// since it was untested and potentially unneeded.

$phpcsFile->fixer->endChangeset();
}
Expand All @@ -117,7 +115,11 @@ private function getLineStart( File $phpcsFile, int $stackPtr ): int|false {
true
);
if ( $prevNonWhitespace === false ) {
// There were no tokens before this in the file, should be
// impossible
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}
$tokens = $phpcsFile->getTokens();
$stackPtrLine = $tokens[$stackPtr]['line'];
Expand Down
14 changes: 11 additions & 3 deletions src/Tests/data/AttributeAlignment/wrong.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare( strict_types = 1 );

// phpcs:disable MediaWiki.Commenting
// phpcs:disable MediaWiki.Commenting,Squiz.WhiteSpace.FunctionSpacing.Before
// phpcs:disable MediaWiki.Files.ClassMatchesFilename
// phpcs:disable Generic.WhiteSpace.ScopeIndent

Expand Down Expand Up @@ -49,14 +49,22 @@ function demo4() {
#[First]
#[Second]
function demo5() {
}

#[TwoSpaces]
function demo6() {
}

// Not fixable
#[MyAttribute]

/* ignored */ function demo6() {
/* ignored */ function demo7() {
}

/* not fixable */ #[MyAttribute]
function demo8() {
}

// Not covered
#[MyAttribute] function demo7() {
#[MyAttribute] function demo9() {
}
14 changes: 11 additions & 3 deletions src/Tests/data/AttributeAlignment/wrong.php.fixed
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare( strict_types = 1 );

// phpcs:disable MediaWiki.Commenting
// phpcs:disable MediaWiki.Commenting,Squiz.WhiteSpace.FunctionSpacing.Before
// phpcs:disable MediaWiki.Files.ClassMatchesFilename
// phpcs:disable Generic.WhiteSpace.ScopeIndent

Expand Down Expand Up @@ -51,12 +51,20 @@ function demo4() {
function demo5() {
}

#[TwoSpaces]
function demo6() {
}

// Not fixable
#[MyAttribute]

/* ignored */ function demo6() {
/* ignored */ function demo7() {
}

/* not fixable */ #[MyAttribute]
function demo8() {
}

// Not covered
#[MyAttribute] function demo7() {
#[MyAttribute] function demo9() {
}
10 changes: 7 additions & 3 deletions src/Tests/data/AttributeAlignment/wrong.report
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FILE: {dir}/data/AttributeAlignment/wrong.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 14 WARNINGS AFFECTING 14 LINES
FOUND 0 ERRORS AND 16 WARNINGS AFFECTING 16 LINES
--------------------------------------------------------------------------------
8 | WARNING | [x] Attributes should be aligned with their targets
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
Expand Down Expand Up @@ -28,8 +28,12 @@ FOUND 0 ERRORS AND 14 WARNINGS AFFECTING 14 LINES
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
50 | WARNING | [x] Attributes should be aligned with their targets
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
55 | WARNING | [ ] Attributes should be aligned with their targets
54 | WARNING | [x] Attributes should be aligned with their targets
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
59 | WARNING | [ ] Attributes should be aligned with their targets
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
64 | WARNING | [ ] Attributes should be aligned with their targets
| | (CommonPhpcs.Attributes.AttributeAlignment.NotAligned)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 13 MARKED SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX THE 14 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------