From 5261b4fb91d8ee6640daaf977816a2050a0dd767 Mon Sep 17 00:00:00 2001 From: "Gabriel R. Barbosa" Date: Thu, 4 Sep 2025 16:37:35 -0300 Subject: [PATCH 1/2] fix: Implemented whole word matching in ProfanityAnalyser class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example in portuguese: 'Colar de pérola' would get incorrectly flagged as profanity because it contains the last 4 chars that is a bad word in pt_BR config. --- src/ProfanityAnalyser.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ProfanityAnalyser.php b/src/ProfanityAnalyser.php index 563a556..eef3626 100644 --- a/src/ProfanityAnalyser.php +++ b/src/ProfanityAnalyser.php @@ -56,15 +56,13 @@ public static function analyse(string $file, array $excludingWords = [], array $ $foundProfanity = []; foreach ($words as $word) { - if (preg_match('/\b'.preg_quote($word, '/').'\b/i', $fileContents) === 1) { - foreach ($lines as $lineNumber => $line) { - $key = $lineNumber.'-'.$word; - if (preg_match('/\b'.preg_quote($word, '/').'\b/i', $line) === 1 && ! isset($foundProfanity[$key])) { - // Skip reporting profanity if the line contains the ignore annotation - if (! str_contains($line, '@pest-ignore-profanity')) { - $errors[] = new Error($file, $lineNumber + 1, $word); - $foundProfanity[$key] = true; - } + foreach ($lines as $lineNumber => $line) { + $key = $lineNumber.'-'.$word; + if (preg_match('/(? Date: Tue, 9 Sep 2025 16:03:53 -0300 Subject: [PATCH 2/2] style: fix not_operator_with_successor_space --- src/ProfanityAnalyser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProfanityAnalyser.php b/src/ProfanityAnalyser.php index eef3626..f3349b8 100644 --- a/src/ProfanityAnalyser.php +++ b/src/ProfanityAnalyser.php @@ -58,9 +58,9 @@ public static function analyse(string $file, array $excludingWords = [], array $ foreach ($words as $word) { foreach ($lines as $lineNumber => $line) { $key = $lineNumber.'-'.$word; - if (preg_match('/(?