diff mbox series

[bug#74459,6/8] guix: lint: Ignore initials from double space check.

Message ID bdbu7esmeykn6tts7pnwjvnymdpnlpwfelewu6myxupk33jgsd@3qlccb2yc65u
State New
Headers show
Series Linter improvements (eliminate false positives) | expand

Commit Message

Gabriel Wicki Nov. 21, 2024, 12:48 p.m. UTC
Prevent false positives in initials as the are commonly used in names, e.g.
Margaret E. Hamilton - which obviously do not end sentences.  Check whether a
period character `.' is preceded by at least two characters.  This should save
us from false positives when linting.

* guix/lint.scm(check-description-style)[check-end-of-sentence-space] Add
condition.
* tests/lint.scm: Add test case.

Change-Id: I42a1365aaaed2afc7308b88ebd4b0720ad362761
---
 guix/lint.scm  | 15 ++++++++++-----
 tests/lint.scm |  2 +-
 2 files changed, 11 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/guix/lint.scm b/guix/lint.scm
index 6122a9c8e3..f2e8e95e61 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -463,11 +463,16 @@  (define (check-description-style package)
            (reverse (fold-matches
                      "\\. [A-Z]" description '()
                      (lambda (m r)
-                       ;; Filter out matches of common abbreviations.
-                       (if (find (lambda (s)
-                                   (string-suffix-ci? s (match:prefix m)))
-                                 '("i.e" "e.g" "a.k.a" "resp"))
-                           r (cons (match:start m) r)))))))
+                       ;; Filter out matches of common abbreviations and
+                       ;; initials.
+                       (let ((pre (match:prefix m)))
+                         (if (or
+                              (string-match "[A-Z]$" pre) ;; Initial found
+                              (find (lambda (s)
+                                      (string-suffix-ci? s pre))
+                                    '("i.e" "e.g" "a.k.a" "resp")))
+                             r
+                             (cons (match:start m) r))))))))
       (if (null? infractions)
           '()
           (list
diff --git a/tests/lint.scm b/tests/lint.scm
index 47e31a69bf..09be160f5d 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -173,7 +173,7 @@  (define (warning-contains? str warnings)
   '()
   (let ((pkg (dummy-package "x"
                             (description
-                             "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD)."))))
+                             "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD).  Name O. Person"))))
     (check-description-style pkg)))
 
 (test-equal "description: may not contain trademark signs: ™"