From b4972e78ac25e514ee00e143fd7a4b85132fea84 Mon Sep 17 00:00:00 2001
From: Klaus Purer <klaus.purer@protonmail.ch>
Date: Sun, 1 Sep 2024 11:56:13 +0200
Subject: [PATCH] fix(InlineComment): Fix cspell ignore detection (#/3424914)

---
 .../Drupal/Sniffs/Commenting/InlineCommentSniff.php    |  2 +-
 tests/Drupal/Commenting/InlineCommentUnitTest.inc      | 10 ++++++++++
 .../Drupal/Commenting/InlineCommentUnitTest.inc.fixed  | 10 ++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php
index 161ee994..990a059f 100644
--- a/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php
+++ b/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php
@@ -351,7 +351,7 @@ class InlineCommentSniff implements Sniff
         // Also, when the comment starts with cspell: don't check the end of the
         // comment.
         if (preg_match('/^\p{L}/u', $commentText) === 1
-            && strpos($commentText, 'cspell:') !== 0
+            && preg_match('/(cspell|spell\-checker):ignore/i', $commentText) === 0
         ) {
             $commentCloser   = $commentText[(strlen($commentText) - 1)];
             $acceptedClosers = [
diff --git a/tests/Drupal/Commenting/InlineCommentUnitTest.inc b/tests/Drupal/Commenting/InlineCommentUnitTest.inc
index 1b0188cc..401d02fc 100644
--- a/tests/Drupal/Commenting/InlineCommentUnitTest.inc
+++ b/tests/Drupal/Commenting/InlineCommentUnitTest.inc
@@ -116,3 +116,13 @@ function test2() {
 
   return $x;
 }
+
+// Allow all the cspell comment variants.
+// cspell:ignore bananarama
+$x = 1;
+// With some comment before it.
+// cSpell:ignore bananarama
+$x = 2;
+// And here as well.
+// spell-checker:ignore bananarama
+$x = 3;
diff --git a/tests/Drupal/Commenting/InlineCommentUnitTest.inc.fixed b/tests/Drupal/Commenting/InlineCommentUnitTest.inc.fixed
index 901d3f56..fabc368f 100644
--- a/tests/Drupal/Commenting/InlineCommentUnitTest.inc.fixed
+++ b/tests/Drupal/Commenting/InlineCommentUnitTest.inc.fixed
@@ -115,3 +115,13 @@ function test2() {
 
   return $x;
 }
+
+// Allow all the cspell comment variants.
+// cspell:ignore bananarama
+$x = 1;
+// With some comment before it.
+// cSpell:ignore bananarama
+$x = 2;
+// And here as well.
+// spell-checker:ignore bananarama
+$x = 3;
-- 
GitLab