From 658facff0919b5cd5685b85d3184adc44dd031b2 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 1 Sep 2024 11:52:03 +0200 Subject: [PATCH] fix(InlineComment): Fix cspell ignore detection --- .../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 @@ public function process(File $phpcsFile, $stackPtr) // 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;