Skip to content

Commit

Permalink
Squiz/BlockComment: add fixer for LastLineIndent error
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Feb 27, 2018
1 parent 5ea5103 commit c24f544
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,21 @@ public function process(File $phpcsFile, $stackPtr)
];

$error = 'Last line of comment aligned incorrectly; expected %s but found %s';
$phpcsFile->addError($error, $commentLines[$lastIndex], 'LastLineIndent', $data);
}
$fix = $phpcsFile->addFixableError($error, $commentLines[$lastIndex], 'LastLineIndent', $data);
if ($fix === true) {
if (isset($tokens[$line]['orig_content']) === true
&& $tokens[$line]['orig_content'][0] === "\t"
) {
// Line is indented using tabs.
$padding = str_repeat("\t", floor($expected / $this->tabWidth));
$padding .= str_repeat(' ', ($expected % $this->tabWidth));
} else {
$padding = str_repeat(' ', $expected);
}

$phpcsFile->fixer->replaceToken($commentLines[$lastIndex], $padding.$commentText);
}
}//end if
}//end if

// Check that the lines before and after this comment are blank.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ $code = 'should not be here';

/*
Closing comment not aligned
*/
*/

/*
Closing comment not aligned
*/
*/

// Not allowed

Expand Down Expand Up @@ -91,7 +91,7 @@ function func()
/*
Test
here
*/
*/

}//end func()

Expand Down

0 comments on commit c24f544

Please sign in to comment.