lint: formatting: Reporters return #f or a warning.

* guix/lint.scm (report-tabulations, report-trailing-white-space)
(report-long-line, report-lone-parentheses): Return #f instead
of *unspecified* when there are no warnings.
(report-formatting-issues): Use 'filter-map' instead of 'map' + 'filter'.
master
Ludovic Courtès 2019-08-29 12:15:09 +02:00
parent ac9cd78ea9
commit 7d09f2e85f
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 29 additions and 31 deletions

View File

@ -1031,7 +1031,7 @@ the NIST server non-fatal."
(define (report-tabulations package line line-number) (define (report-tabulations package line line-number)
"Warn about tabulations found in LINE." "Warn about tabulations found in LINE."
(match (string-index line #\tab) (match (string-index line #\tab)
(#f #t) (#f #f)
(index (index
(make-warning package (make-warning package
(G_ "tabulation on line ~a, column ~a") (G_ "tabulation on line ~a, column ~a")
@ -1043,44 +1043,44 @@ the NIST server non-fatal."
(define (report-trailing-white-space package line line-number) (define (report-trailing-white-space package line line-number)
"Warn about trailing white space in LINE." "Warn about trailing white space in LINE."
(unless (or (string=? line (string-trim-right line)) (and (not (or (string=? line (string-trim-right line))
(string=? line (string #\page))) (string=? line (string #\page))))
(make-warning package (make-warning package
(G_ "trailing white space on line ~a") (G_ "trailing white space on line ~a")
(list line-number) (list line-number)
#:location #:location
(location (package-file package) (location (package-file package)
line-number line-number
0)))) 0))))
(define (report-long-line package line line-number) (define (report-long-line package line line-number)
"Emit a warning if LINE is too long." "Emit a warning if LINE is too long."
;; Note: We don't warn at 80 characters because sometimes hashes and URLs ;; Note: We don't warn at 80 characters because sometimes hashes and URLs
;; make it hard to fit within that limit and we want to avoid making too ;; make it hard to fit within that limit and we want to avoid making too
;; much noise. ;; much noise.
(when (> (string-length line) 90) (and (> (string-length line) 90)
(make-warning package (make-warning package
(G_ "line ~a is way too long (~a characters)") (G_ "line ~a is way too long (~a characters)")
(list line-number (string-length line)) (list line-number (string-length line))
#:location #:location
(location (package-file package) (location (package-file package)
line-number line-number
0)))) 0))))
(define %hanging-paren-rx (define %hanging-paren-rx
(make-regexp "^[[:blank:]]*[()]+[[:blank:]]*$")) (make-regexp "^[[:blank:]]*[()]+[[:blank:]]*$"))
(define (report-lone-parentheses package line line-number) (define (report-lone-parentheses package line line-number)
"Emit a warning if LINE contains hanging parentheses." "Emit a warning if LINE contains hanging parentheses."
(when (regexp-exec %hanging-paren-rx line) (and (regexp-exec %hanging-paren-rx line)
(make-warning package (make-warning package
(G_ "parentheses feel lonely, \ (G_ "parentheses feel lonely, \
move to the previous or next line") move to the previous or next line")
(list line-number) (list line-number)
#:location #:location
(location (package-file package) (location (package-file package)
line-number line-number
0)))) 0))))
(define %formatting-reporters (define %formatting-reporters
;; List of procedures that report formatting issues. These are not separate ;; List of procedures that report formatting issues. These are not separate
@ -1130,11 +1130,9 @@ them for PACKAGE."
warnings warnings
(if (< line-number starting-line) (if (< line-number starting-line)
'() '()
(filter (filter-map (lambda (report)
lint-warning? (report package line line-number))
(map (lambda (report) reporters)))))))))))
(report package line line-number))
reporters))))))))))))
(define (check-formatting package) (define (check-formatting package)
"Check the formatting of the source code of PACKAGE." "Check the formatting of the source code of PACKAGE."