all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH 3/5] guix: lint: Check for proper end-of-sentence space.
@ 2014-10-24  5:06 Eric Bavier
  2014-10-24 17:40 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Bavier @ 2014-10-24  5:06 UTC (permalink / raw)
  To: guix-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0003-guix-lint-Check-for-proper-end-of-sentence-space.patch --]
[-- Type: text/x-diff, Size: 4046 bytes --]

From 88d05ece4bf30bbed6de51f076cde0301c493123 Mon Sep 17 00:00:00 2001
From: Eric Bavier <bavier@member.fsf.org>
Date: Wed, 22 Oct 2014 13:47:01 -0500
Subject: [PATCH 3/5] guix: lint: Check for proper end-of-sentence space.

* guix/scripts/lint.scm (start-with-capital-letter?): Handle empty
  strings.
  (check-description-style): New check for end-of-sentence space.
* tests/lint.scm: Test it.
---
 guix/scripts/lint.scm |   42 ++++++++++++++++++++++++++++++++++--------
 tests/lint.scm        |    9 +++++++++
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 84d9fe9..e8cc853 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -25,6 +25,8 @@
   #:use-module (guix utils)
   #:use-module (gnu packages)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
+  #:use-module (ice-9 format)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-11)
@@ -75,17 +77,41 @@
   (exit 0))
 
 (define (start-with-capital-letter? s)
-  (char-set-contains? char-set:upper-case (string-ref s 0)))
+  (and (not (string-null? s))
+       (char-set-contains? char-set:upper-case (string-ref s 0))))
 
 (define (check-description-style package)
   ;; Emit a warning if stylistic issues are found in the description of PACKAGE.
- (let ((description (package-description package)))
-   (when (and (string? description)
-              (not (string-null? description))
-              (not (start-with-capital-letter? description)))
-     (emit-warning package
-                   "description should start with an upper-case letter"
-                   'description))))
+  (define (check-starts-with-upper-case description)
+    (unless (start-with-capital-letter? description)
+      (emit-warning package
+                    "description should start with an upper-case letter"
+                    'description)))
+
+  (define (check-end-of-sentence-space description)
+    "Check that an end-of-sentence period is followed by two spaces."
+    (let ((infractions (filter-map
+                        (lambda (m)
+                          (and (not
+                                ;; Filter out matches of common abbrevs.
+                                (find (lambda (s)
+                                        (string-suffix? s (match:prefix m)))
+                                      '("i.e" "e.g" "a.k.a" "resp")))
+                               (match:start m)))
+                        (list-matches "\\. [A-Z]" description))))
+     (when (not (null? infractions))
+       (emit-warning package
+                     (format #f "sentences in description should be followed ~
+by two spaces; possible infraction~p at ~{~a~^, ~}"
+                             (length infractions)
+                             infractions)
+                     'description))))
+
+  (let ((description (package-description package)))
+    (when (string? description)
+      (begin
+        (check-starts-with-upper-case description)
+        (check-end-of-sentence-space description)))))
 
 (define (check-inputs-should-be-native package)
   ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
diff --git a/tests/lint.scm b/tests/lint.scm
index 62a9df9..2c2a179 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -53,6 +53,15 @@
                           (check-description-style pkg))))
                     "description should start with an upper-case letter")))
 
+(test-assert "description: two spaces after end of sentence"
+  (->bool
+   (string-contains (call-with-warnings
+                      (lambda ()
+                        (let ((pkg (dummy-package "x"
+                                     (description "Bad. Quite bad."))))
+                          (check-description-style pkg))))
+                    "sentences in description should be followed by two spaces")))
+
 (test-assert "synopsis: does not start with an upper-case letter"
   (->bool
    (string-contains (call-with-warnings
-- 
1.7.9.5


[-- Attachment #2: Type: text/plain, Size: 17 bytes --]


-- 
Eric Bavier

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/5] guix: lint: Check for proper end-of-sentence space.
  2014-10-24  5:06 [PATCH 3/5] guix: lint: Check for proper end-of-sentence space Eric Bavier
@ 2014-10-24 17:40 ` Mark H Weaver
  0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2014-10-24 17:40 UTC (permalink / raw)
  To: Eric Bavier; +Cc: guix-devel

Eric Bavier <ericbavier@gmail.com> writes:

> From 88d05ece4bf30bbed6de51f076cde0301c493123 Mon Sep 17 00:00:00 2001
> From: Eric Bavier <bavier@member.fsf.org>
> Date: Wed, 22 Oct 2014 13:47:01 -0500
> Subject: [PATCH 3/5] guix: lint: Check for proper end-of-sentence space.
>
> * guix/scripts/lint.scm (start-with-capital-letter?): Handle empty
>   strings.
>   (check-description-style): New check for end-of-sentence space.
> * tests/lint.scm: Test it.
> ---
>  guix/scripts/lint.scm |   42 ++++++++++++++++++++++++++++++++++--------
>  tests/lint.scm        |    9 +++++++++
>  2 files changed, 43 insertions(+), 8 deletions(-)
>
> diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
> index 84d9fe9..e8cc853 100644
> --- a/guix/scripts/lint.scm
> +++ b/guix/scripts/lint.scm
> @@ -25,6 +25,8 @@
>    #:use-module (guix utils)
>    #:use-module (gnu packages)
>    #:use-module (ice-9 match)
> +  #:use-module (ice-9 regex)
> +  #:use-module (ice-9 format)
>    #:use-module (srfi srfi-1)
>    #:use-module (srfi srfi-9)
>    #:use-module (srfi srfi-11)
> @@ -75,17 +77,41 @@
>    (exit 0))
>  
>  (define (start-with-capital-letter? s)
> -  (char-set-contains? char-set:upper-case (string-ref s 0)))
> +  (and (not (string-null? s))
> +       (char-set-contains? char-set:upper-case (string-ref s 0))))
>  
>  (define (check-description-style package)
>    ;; Emit a warning if stylistic issues are found in the description of PACKAGE.
> - (let ((description (package-description package)))
> -   (when (and (string? description)
> -              (not (string-null? description))
> -              (not (start-with-capital-letter? description)))
> -     (emit-warning package
> -                   "description should start with an upper-case letter"
> -                   'description))))
> +  (define (check-starts-with-upper-case description)
> +    (unless (start-with-capital-letter? description)
> +      (emit-warning package
> +                    "description should start with an upper-case letter"
> +                    'description)))
> +
> +  (define (check-end-of-sentence-space description)
> +    "Check that an end-of-sentence period is followed by two spaces."
> +    (let ((infractions (filter-map
> +                        (lambda (m)
> +                          (and (not
> +                                ;; Filter out matches of common abbrevs.
> +                                (find (lambda (s)
> +                                        (string-suffix? s (match:prefix m)))
> +                                      '("i.e" "e.g" "a.k.a" "resp")))
> +                               (match:start m)))
> +                        (list-matches "\\. [A-Z]" description))))
> +     (when (not (null? infractions))

(unless (null? infractions)).  Also, this should be indented one more
column.

> +       (emit-warning package
> +                     (format #f "sentences in description should be followed ~
> +by two spaces; possible infraction~p at ~{~a~^, ~}"
> +                             (length infractions)
> +                             infractions)
> +                     'description))))
> +
> +  (let ((description (package-description package)))
> +    (when (string? description)
> +      (begin
> +        (check-starts-with-upper-case description)
> +        (check-end-of-sentence-space description)))))

'begin' is not needed here.  'when' and 'unless' include an implicit
'begin'.

>  
>  (define (check-inputs-should-be-native package)
>    ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
> diff --git a/tests/lint.scm b/tests/lint.scm
> index 62a9df9..2c2a179 100644
> --- a/tests/lint.scm
> +++ b/tests/lint.scm
> @@ -53,6 +53,15 @@
>                            (check-description-style pkg))))
>                      "description should start with an upper-case letter")))
>  
> +(test-assert "description: two spaces after end of sentence"
> +  (->bool
> +   (string-contains (call-with-warnings
> +                      (lambda ()
> +                        (let ((pkg (dummy-package "x"
> +                                     (description "Bad. Quite bad."))))
> +                          (check-description-style pkg))))
> +                    "sentences in description should be followed by two spaces")))
> +

It would be good to add some tests for the "common abbrevs" logic above.

Otherwise looks good to me, thanks!

      Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-24 17:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-24  5:06 [PATCH 3/5] guix: lint: Check for proper end-of-sentence space Eric Bavier
2014-10-24 17:40 ` Mark H Weaver

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.