Skip to content

Commit 801a6c2

Browse files
author
Vincent Langlet
committed
✨ Add fixer for CommaSpacingSniff
1 parent 7c9ba0e commit 801a6c2

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

Symfony3Custom/Sniffs/WhiteSpace/CommaSpacingSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4545
if ($tokens[$stackPtr + 1]['line'] === $line
4646
&& $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE
4747
) {
48-
$phpcsFile->addError(
48+
$fix = $phpcsFile->addFixableError(
4949
'Add a single space after each comma delimiter',
5050
$stackPtr,
5151
'Invalid'
5252
);
53+
54+
if ($fix) {
55+
$phpcsFile->fixer->addContent($stackPtr, ' ');
56+
}
5357
}
5458

5559
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
testFunction(args1, args2);
4+
testFunction(args1,args2);
5+
6+
$array = [$a, $b,$c];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
testFunction(args1, args2);
4+
testFunction(args1, args2);
5+
6+
$array = [$a, $b, $c];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* Unit test class for the CommaSpacing sniff.
5+
*
6+
* A sniff unit test checks a .inc file for expected violations of a single
7+
* coding standard. Expected errors and warnings are stored in this class.
8+
*/
9+
class Symfony3Custom_Tests_WhiteSpace_CommaSpacingUnitTest
10+
extends AbstractSniffUnitTest
11+
{
12+
/**
13+
* Returns the lines where errors should occur.
14+
*
15+
* The key of the array should represent the line number and the value
16+
* should represent the number of errors that should occur on that line.
17+
*
18+
* @return array<int, int>
19+
*/
20+
public function getErrorList()
21+
{
22+
return array(
23+
4 => 1,
24+
6 => 1,
25+
);
26+
}
27+
28+
/**
29+
* Returns the lines where warnings should occur.
30+
*
31+
* The key of the array should represent the line number and the value
32+
* should represent the number of warnings that should occur on that line.
33+
*
34+
* @return array(int => int)
35+
*/
36+
protected function getWarningList()
37+
{
38+
return array();
39+
}
40+
}

0 commit comments

Comments
 (0)