Skip to content

Commit

Permalink
Fixed bug #1095 : Generic LineEndings sniff replaces tabs with spaces…
Browse files Browse the repository at this point in the history
… with --tab-width is set
  • Loading branch information
gsherwood committed Aug 1, 2016
1 parent cd29ed2 commit 5668c5e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|| $tokens[($i + 1)]['line'] > $tokens[$i]['line']
) {
// Token is the last on a line.
$newContent = rtrim($tokens[$i]['content'], "\r\n");
if (isset($tokens[$i]['orig_content']) === true) {
$tokenContent = $tokens[$i]['orig_content'];
} else {
$tokenContent = $tokens[$i]['content'];
}

$newContent = rtrim($tokenContent, "\r\n");
$newContent .= $eolChar;
$phpcsFile->fixer->replaceToken($i, $newContent);
}
Expand Down
10 changes: 10 additions & 0 deletions CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ echo 'hi';
<?php
echo 'hi';
?>

<?php
function foo()
{
$query->group('a.id,
uc.name,
ag.title,
ua.name'
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

<?php
echo 'hi';
?>

<?php
echo 'hi';
?>

<?php
function foo()
{
$query->group('a.id,
uc.name,
ag.title,
ua.name'
);
}
15 changes: 15 additions & 0 deletions CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ class Generic_Tests_Files_LineEndingsUnitTest extends AbstractSniffUnitTest
{


/**
* Get a list of CLI values to set befor the file is tested.
*
* @param string $testFile The name of the file being tested.
*
* @return array
*/
public function getCliValues($testFile)
{
// Tab width setting is only needed for the tabbed file.
return array('--tab-width=4');

}//end getCliValues()


/**
* Returns the lines where errors should occur.
*
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1072 : Squiz.SelfMemberReference.NotUsed not detected if leading namespace separator is used
- Fixed bug #1089 : Rulesets cannot be loaded if the path contains urlencoded characters
- Fixed bug #1091 : PEAR and Squiz FunctionComment sniffs throw errors for some invalid @param line formats
- Fixed bug #1095 : Generic LineEndings sniff replaces tabs with spaces with --tab-width is set
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -627,6 +628,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
</file>
<file baseinstalldir="PHP" name="LineEndingsUnitTest.css" role="test" />
<file baseinstalldir="PHP" name="LineEndingsUnitTest.inc" role="test" />
<file baseinstalldir="PHP" name="LineEndingsUnitTest.inc.fixed" role="test" />
<file baseinstalldir="PHP" name="LineEndingsUnitTest.js" role="test" />
<file baseinstalldir="PHP" name="LineEndingsUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
Expand Down

0 comments on commit 5668c5e

Please sign in to comment.