8000 Whitespace/AssignmentSpacing: make the error auto-fixable (#169) · djoos/Symfony-coding-standard@f5b7f6a · GitHub
[go: up one dir, main page]

Skip to content

Commit f5b7f6a

Browse files
jrfnldjoos
authored andcommitted
Whitespace/AssignmentSpacing: make the error auto-fixable (#169)
* Whitespace/AssignmentSpacing: make the error auto-fixable Not sure if the non-autofixable was intentional, but it seemed like an easy sniff to enable auto-fixing for. Includes `.fixed` file to test the fixer. * Travis: fix _ant is no longer installed by default_ Looks like you've gotten switched from the `trusty` environment to the `xenial` environment in which `ant` is no longer installed by default. Also, it's not much use displaying the Travis native PHPUnit version, when in actual fact you will be using the version installed via Composer.
1 parent fde0732 commit f5b7f6a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ php:
88
- 7.3 # security support until 06/12/2021
99
- nightly
1010

11+
addons:
12+
apt:
13+
packages:
14+
ant
15+
1116
before_script:
1217
- stable='^[0-9\.]+$'; if [[ "$TRAVIS_PHP_VERSION" =~ $stable ]]; then phpenv config-rm xdebug.ini; fi
1318
- export PATH="$HOME/.composer/vendor/bin:$PATH"
14-
- phpunit --version
1519

1620
script:
1721
- ant test -Dcomposer.path=composer

Symfony/Sniffs/Whitespace/AssignmentSpacingSniff.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,24 @@ public function process(File $phpcsFile, $stackPtr)
7070
|| $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE)
7171
&& $tokens[$stackPtr - 1]['content'] !== 'strict_types'
7272
) {
73-
$phpcsFile->addError(
73+
$fix = $phpcsFile->addFixableError(
7474
'Add a single space around assignment operators',
7575
$stackPtr,
7676
'Invalid'
7777
);
78+
79+
if ($fix === true) {
80+
$replacement = $tokens[$stackPtr]['content'];
81+
if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
82+
$replacement = ' '.$replacement;
83+
}
84+
85+
if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
86+
$replacement .= ' ';
87+
}
88+
89+
$phpcsFile->fixer->replaceToken($stackPtr, $replacement);
90+
}
7891
}
7992
}
8093
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php strict_types=1
2+
3+
$a = 'foo';
4+
5+
$b = 'foo';
6+
$c = 'foo';
7+
8+
$d = 'bar';

0 commit comments

Comments
 (0)
0