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.
This commit is contained in:
parent
c04b82ffce
commit
574e847b8e
|
@ -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,18 +77,42 @@
|
|||
(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)))
|
||||
(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
|
||||
(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)))))))
|
||||
(unless (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
|
||||
;; native inputs.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
;;; GNU Guix --- Functional package management for GNU
|
||||
;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com>
|
||||
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
|
||||
;;;
|
||||
;;; This file is part of GNU Guix.
|
||||
;;;
|
||||
|
@ -53,6 +54,34 @@
|
|||
(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 "description: end-of-sentence detection with abbreviations"
|
||||
(not
|
||||
(string-contains (call-with-warnings
|
||||
(lambda ()
|
||||
(let ((pkg (dummy-package "x"
|
||||
(description
|
||||
"E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD)."))))
|
||||
(check-description-style pkg))))
|
||||
"sentences in description should be followed by two spaces")))
|
||||
|
||||
(test-assert "synopsis: not empty"
|
||||
(->bool
|
||||
(string-contains (call-with-warnings
|
||||
(lambda ()
|
||||
(let ((pkg (dummy-package "x"
|
||||
(synopsis ""))))
|
||||
(check-synopsis-style pkg))))
|
||||
"synopsis should not be empty")))
|
||||
|
||||
(test-assert "synopsis: does not start with an upper-case letter"
|
||||
(->bool
|
||||
(string-contains (call-with-warnings
|
||||
|
|
Loading…
Reference in New Issue