Skip to content

Commit b4972e7

Browse files
authored
fix(InlineComment): Fix cspell ignore detection (#/3424914)
1 parent 8739103 commit b4972e7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function process(File $phpcsFile, $stackPtr)
351351
// Also, when the comment starts with cspell: don't check the end of the
352352
// comment.
353353
if (preg_match('/^\p{L}/u', $commentText) === 1
354-
&& strpos($commentText, 'cspell:') !== 0
354+
&& preg_match('/(cspell|spell\-checker):ignore/i', $commentText) === 0
355355
) {
356356
$commentCloser = $commentText[(strlen($commentText) - 1)];
357357
$acceptedClosers = [

tests/Drupal/Commenting/InlineCommentUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@ function test2() {
116116

117117
return $x;
118118
}
119+
120+
// Allow all the cspell comment variants.
121+
// cspell:ignore bananarama
122+
$x = 1;
123+
// With some comment before it.
124+
// cSpell:ignore bananarama
125+
$x = 2;
126+
// And here as well.
127+
// spell-checker:ignore bananarama
128+
$x = 3;

tests/Drupal/Commenting/InlineCommentUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ function test2() {
115115

116116
return $x;
117117
}
118+
119+
// Allow all the cspell comment variants.
120+
// cspell:ignore bananarama
121+
$x = 1;
122+
// With some comment before it.
123+
// cSpell:ignore bananarama
124+
$x = 2;
125+
// And here as well.
126+
// spell-checker:ignore bananarama
127+
$x = 3;

0 commit comments

Comments
 (0)