[PATCH] scripts/checkpatch.pl: use \b{wb} for misspellings boundaries

From: Dominique Martinet
Date: Tue Aug 27 2024 - 00:47:36 EST


Perl v5.22 (2015/6) added an expression for word boundary that can
replace our custom boundary check.

In particular, this fix detecting of typos for languages which do not
rely on spaces as much such as Japanese ("テストtest" will properly
match "\b{wb}test\b{wb}")

Note that this does not regress on commit 7da07c31b1df ("checkpatch:
fix TYPO_SPELLING check for words with apostrophe"), e.g. `doesn't` still
does not match `doesn'` (but that one just now did, as expected).
Start and end of lines also still properly match.

Link: https://perldoc.perl.org/perlrebackslash#%5Cb%7B%7D%2C-%5Cb%2C-%5CB%7B%7D%2C-%5CB
Signed-off-by: Dominique Martinet <dominique.martinet@xxxxxxxxxxxxxxxxx>
---

Hi,

we're using checkpatch out of tree with a mix of japanese and english,
and the current regex doesn't work well for us.
I wouldn't mind keeping this as a local patch but this hopefully will
work for everyone, so might as well share.

scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 39032224d504..d08f884a3966 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3496,7 +3496,7 @@ sub process {
# Check for various typo / spelling mistakes
if (defined($misspellings) &&
($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
- while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+ while ($rawline =~ /\b{wb}($misspellings)\b{wb}/gi) {
my $typo = $1;
my $blank = copy_spacing($rawline);
my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
--
2.39.2