jenkins-bot has submitted this change and it was merged.
Change subject: Handle multiple # comments in Space Before Comment
......................................................................
Handle multiple # comments in Space Before Comment
Handle comments beginning with multiple # in the sniff
SpaceBeforeSingleLineCommentSniff. Also, handle separater comments which
only contain #.
Bug: T114633
Change-Id: I11e953962026637bed95e1975bde97504fff83ea
---
M MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php
1 file changed, 31 insertions(+), 15 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php
b/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php
index 45ee61f..0fc373f 100644
--- a/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php
+++ b/MediaWiki/Sniffs/WhiteSpace/SpaceBeforeSingleLineCommentSniff.php
@@ -24,7 +24,11 @@
|| substr( $currToken['content'], 0, 3 ) ===
'///'
) {
return;
+ // Checking if it's a comment separator
+ } elseif ( preg_match( '/#*/', $currToken['content'] )
=== false ) {
+ return;
}
+
// Checking whether the comment is an empty one
if ( ( substr( $currToken['content'], 0, 2 ) === '//'
&& rtrim( $currToken['content'] ) ===
'//' )
@@ -38,7 +42,7 @@
// Checking whether there is a space between the
comment delimiter
// and the comment
} elseif ( substr( $currToken['content'], 0, 2 ) ===
'//'
- && substr( $currToken['content'], 2, 1 ) !== ' '
+ && $currToken['content'][2] !== ' '
) {
$error = 'Single space expected between "//"
and comment';
$fix = $phpcsFile->addFixableWarning( $error,
$stackPtr,
@@ -53,21 +57,33 @@
}
$phpcsFile->fixer->replaceToken(
$stackPtr, $newContent );
}
- } elseif ( substr( $currToken['content'], 0, 1 ) === '#'
- && substr( $currToken['content'], 1, 1 ) !== ' '
- ) {
- $error = 'Single space expected between "#" and
comment';
- $fix = $phpcsFile->addFixableWarning( $error,
$stackPtr,
- 'SingleSpaceBeforeSingleLineComment'
- );
- if ( $fix === true ) {
- $content = $currToken['content'];
- if ( substr( $content, 2, 1 ) === '\t'
) {
- $newContent = preg_replace(
'/^#\t/', '# ', $content );
- } else {
- $newContent = preg_replace(
'/^#/', '# ', $content );
+ // Finding what the comment delimiter is and checking
whether there is a space
+ // between the comment delimiter and the comment.
+ } elseif ( $currToken['content'][0] === '#' ) {
+ // Find number of `#` used.
+ $startComment = 0;
+ while ( $currToken['content'][$startComment]
=== '#' ) {
+ $startComment += 1;
+ }
+ if ( $currToken['content'][$startComment] !== '
' ) {
+ $error = 'Single space expected between
"#" and comment';
+ $fix = $phpcsFile->addFixableWarning(
$error, $stackPtr,
+
'SingleSpaceBeforeSingleLineComment'
+ );
+ if ( $fix === true ) {
+ $content =
$currToken['content'];
+ $delimiter = substr(
$currToken['content'], 0, $startComment );
+ if ( $content[$startComment+1]
=== '\t' ) {
+ $newContent =
preg_replace(
+ '/^' .
$delimiter . '\t/', $delimiter . ' ', $content
+ );
+ } else {
+ $newContent =
preg_replace(
+ '/^' .
$delimiter . '/', $delimiter . ' ', $content
+ );
+ }
+
$phpcsFile->fixer->replaceToken( $stackPtr, $newContent );
}
- $phpcsFile->fixer->replaceToken(
$stackPtr, $newContent );
}
}
}
--
To view, visit https://gerrit.wikimedia.org/r/243619
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I11e953962026637bed95e1975bde97504fff83ea
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: TasneemLo <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Polybuildr <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits