1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
3 ;;; Copyright © 2014, 2015 Eric Bavier <bavier@member.fsf.org>
4 ;;; Copyright © 2013-2022 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
6 ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
7 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
8 ;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
9 ;;; Copyright © 2017, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
10 ;;; Copyright © 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
11 ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
12 ;;; Copyright © 2020 Chris Marusich <cmmarusich@gmail.com>
13 ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
14 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
15 ;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
16 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
18 ;;; This file is part of GNU Guix.
20 ;;; GNU Guix is free software; you can redistribute it and/or modify it
21 ;;; under the terms of the GNU General Public License as published by
22 ;;; the Free Software Foundation; either version 3 of the License, or (at
23 ;;; your option) any later version.
25 ;;; GNU Guix is distributed in the hope that it will be useful, but
26 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;;; GNU General Public License for more details.
30 ;;; You should have received a copy of the GNU General Public License
31 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
33 (define-module (guix lint)
34 #:use-module (guix store)
35 #:autoload (guix base16) (bytevector->base16-string)
36 #:use-module (guix base32)
37 #:autoload (guix base64) (base64-encode)
38 #:use-module (guix build-system)
39 #:use-module (guix diagnostics)
40 #:use-module (guix download)
41 #:use-module (guix ftp-client)
42 #:use-module (guix http-client)
43 #:use-module (guix packages)
44 #:use-module (guix i18n)
45 #:use-module ((guix gexp)
46 #:select (gexp? local-file? local-file-absolute-file-name
47 gexp->approximate-sexp))
48 #:use-module (guix licenses)
49 #:use-module (guix records)
50 #:use-module (guix grafts)
51 #:use-module (guix upstream)
52 #:use-module (guix utils)
53 #:use-module (guix memoization)
54 #:use-module (guix profiles)
55 #:use-module (guix monads)
56 #:use-module (guix scripts)
57 #:use-module ((guix ui) #:select (texi->plain-text fill-paragraph))
58 #:use-module (guix gnu-maintenance)
59 #:use-module (guix cve)
60 #:use-module ((guix swh) #:hide (origin?))
61 #:autoload (guix git-download) (git-reference?
62 git-reference-url git-reference-commit)
63 #:autoload (guix svn-download) (svn-reference?
65 svn-reference-user-name
66 svn-reference-password)
67 #:use-module (guix import stackage)
68 #:use-module (ice-9 match)
69 #:use-module (ice-9 regex)
70 #:use-module (ice-9 format)
71 #:autoload (rnrs bytevectors) (string->utf8)
72 #:use-module (web client)
73 #:use-module (web uri)
74 #:use-module ((guix build download)
75 #:select (maybe-expand-mirrors
76 (open-connection-for-uri
77 . guix:open-connection-for-uri)))
78 #:use-module (web request)
79 #:use-module (web response)
80 #:autoload (gnutls) (error->string)
81 #:use-module (srfi srfi-1)
82 #:use-module (srfi srfi-6) ;Unicode string ports
83 #:use-module (srfi srfi-9)
84 #:use-module (srfi srfi-11)
85 #:use-module (srfi srfi-26)
86 #:use-module (srfi srfi-34)
87 #:use-module (srfi srfi-35)
88 #:use-module (ice-9 rdelim)
89 #:export (check-description-style
90 check-inputs-should-be-native
91 check-inputs-should-not-be-an-input-at-all
94 check-patch-file-names
101 check-source-file-name
102 check-source-unstable-tarball
107 check-vulnerabilities
111 check-profile-collisions
112 check-haskell-stackage
119 lint-warning-message-text
120 lint-warning-message-data
121 lint-warning-location
124 %network-dependent-checkers
130 lint-checker-description
132 lint-checker-requires-store?))
139 (define-record-type* <lint-warning>
140 lint-warning make-lint-warning
142 (package lint-warning-package)
143 (message-text lint-warning-message-text)
144 (message-data lint-warning-message-data
146 (location lint-warning-location
149 (define (lint-warning-message warning)
151 (G_ (lint-warning-message-text warning))
152 (lint-warning-message-data warning)))
154 (define (package-file package)
156 (package-location package)))
158 (define* (%make-warning package message-text
159 #:optional (message-data '())
160 #:key field location)
166 (and field (package-field-location package field))
167 (package-location package))))
169 (define-syntax make-warning
171 ((_ package (G_ message) rest ...)
172 (%make-warning package message rest ...))))
176 ;;; Procedures for analysing Scheme code in package definitions
179 (define* (find-procedure-body expression found
180 #:key (not-found (const '())))
181 "Try to find the body of the procedure defined inline by EXPRESSION.
182 If it was found, call FOUND with its body. If it wasn't, call
183 the thunk NOT-FOUND."
185 (`(,(or 'let 'let*) . ,_)
186 (find-procedure-body (car (last-pair expression)) found
187 #:not-found not-found))
188 (`(,(or 'lambda 'lambda*) ,_ . ,code)
192 (define* (report-bogus-phase-deltas package bogus-deltas)
193 "Report a bogus invocation of ‘modify-phases’."
194 (list (make-warning package
195 ;; TRANSLATORS: 'modify-phases' is a Scheme syntax
196 ;; and should not be translated.
197 (G_ "incorrect call to ‘modify-phases’")
198 #:field 'arguments)))
200 (define* (find-phase-deltas package found
201 #:key (not-found (const '()))
203 (cut report-bogus-phase-deltas package <>)))
204 "Try to find the clauses of the ‘modify-phases’ form in the phases
205 specification of PACKAGE. If they were found, all FOUND with a list
206 of the clauses. If they weren't (e.g. because ‘modify-phases’ wasn't
207 used at all), call the thunk NOT-FOUND instead. If ‘modify-phases’
208 was used, but the clauses don't form a list, call BOGUS with the
210 (apply (lambda* (#:key phases #:allow-other-keys)
213 (gexp->approximate-sexp phases)
216 (`(modify-phases ,_ . ,changes)
217 ((if (list? changes) found bogus) changes))
219 (package-arguments package)))
221 (define (report-bogus-phase-procedure package)
222 "Report a syntactically-invalid phase clause."
223 (list (make-warning package
224 ;; TRANSLATORS: See ‘modify-phases’ in the manual.
225 (G_ "invalid phase clause")
226 #:field 'arguments)))
228 (define* (find-phase-procedure package expression found
229 #:key (not-found (const '()))
230 (bogus (cut report-bogus-phase-procedure
232 "Try to find the procedure in the phase clause EXPRESSION. If it was
233 found, call FOUND with the procedure expression. If EXPRESSION isn't
234 actually a phase clause, call the thunk BOGUS. If the phase form doesn't
235 have a procedure, call the thunk NOT-FOUND."
237 (('add-after before after proc-expr)
239 (('add-before after before proc-expr)
241 (('replace _ proc-expr)
243 (('delete _) (not-found))
251 (define-record-type* <lint-checker>
252 lint-checker make-lint-checker
254 ;; TODO: add a 'certainty' field that shows how confident we are in the
255 ;; checker. Then allow users to only run checkers that have a certain
256 ;; 'certainty' level.
257 (name lint-checker-name)
258 (description lint-checker-description)
259 (check lint-checker-check)
260 (requires-store? lint-checker-requires-store?
263 (define (check-name package)
264 "Check whether PACKAGE's name matches our guidelines."
265 (let ((name (package-name package)))
267 ;; Currently checks only whether the name is too short.
268 ((and (<= (string-length name) 1)
269 (not (string=? name "r"))) ; common-sense exception
271 (make-warning package
272 (G_ "name should be longer than a single character")
274 ((string-index name #\_)
276 (make-warning package
277 (G_ "name should use hyphens instead of underscores")
281 (define (check-tests-true package)
282 "Check whether PACKAGE explicitly requests to run tests, which is
283 superfluous when building natively and incorrect when cross-compiling."
284 (define (tests-explicitly-enabled?)
285 (apply (lambda* (#:key tests? #:allow-other-keys)
287 (package-arguments package)))
288 (if (and (tests-explicitly-enabled?)
289 ;; emacs-build-system sets #:tests? #f by default, therefore
290 ;; writing #:tests? #t in package definitions using
291 ;; emacs-build-system is reasonable. Likewise for
292 ;; texlive-build-system.
294 ;; Compare the name of the build system instead of the build system
295 ;; itself to avoid loading unnecessary modules when only a few
296 ;; modules are linted.
297 (not (memq (build-system-name (package-build-system package))
299 ;; Some packages, e.g. gnutls, set #:tests?
300 ;; differently depending on whether it is being
302 (parameterize ((%current-target-system "aarch64-linux-gnu"))
303 (tests-explicitly-enabled?)))
304 (list (make-warning package
305 ;; TRANSLATORS: #:tests? and #t are Scheme constants
306 ;; and must not be translated.
307 (G_ "#:tests? must not be explicitly set to #t")
311 (define (properly-starts-sentence? s)
312 (string-match "^[(\"'`[:upper:][:digit:]]" s))
314 (define (starts-with-abbreviation? s)
315 "Return #t if S starts with what looks like an abbreviation or acronym."
316 (string-match "^[A-Z][A-Z0-9]+\\>" s))
318 (define %quoted-identifier-rx
319 ;; A quoted identifier, like 'this'.
320 (make-regexp "['`][[:graph:]]+'"))
322 (define (check-description-style package)
323 ;; Emit a warning if stylistic issues are found in the description of PACKAGE.
324 (define (check-not-empty description)
325 (if (string-null? description)
327 (make-warning package
328 (G_ "description should not be empty")
329 #:field 'description))
332 (define (check-texinfo-markup description)
333 "Check that DESCRIPTION can be parsed as a Texinfo fragment. If the
334 markup is valid return a plain-text version of DESCRIPTION, otherwise #f."
336 (lambda () (texi->plain-text description))
337 (lambda (keys . args)
338 (make-warning package
339 (G_ "Texinfo markup in description is invalid")
340 #:field 'description))))
342 (define (check-description-typo description typo-corrections)
343 "Check that DESCRIPTION does not contain typo, with optional correction"
347 (if (string-contains description typo)
349 (make-warning package
352 "description contains typo '~a'~@[, should be '~a'~]"
357 (define (check-trademarks description)
358 "Check that DESCRIPTION does not contain '™' or '®' characters. See
359 http://www.gnu.org/prep/standards/html_node/Trademarks.html."
360 (match (string-index description (char-set #\™ #\®))
361 ((and (? number?) index)
363 (make-warning package
364 (G_ "description should not contain ~
365 trademark sign '~a' at ~d")
366 (list (string-ref description index) index)
367 #:field 'description)))
370 (define (check-quotes description)
371 "Check whether DESCRIPTION contains single quotes and suggest @code."
372 (if (regexp-exec %quoted-identifier-rx description)
374 (make-warning package
375 ;; TRANSLATORS: '@code' is Texinfo markup and must be kept
377 (G_ "use @code or similar ornament instead of quotes")
378 #:field 'description))
381 (define (check-proper-start description)
382 (if (or (string-null? description)
383 (properly-starts-sentence? description)
384 (string-prefix-ci? (package-name package) description))
389 (G_ "description should start with an upper-case letter or digit")
390 #:field 'description))))
392 (define (check-end-of-sentence-space description)
393 "Check that an end-of-sentence period is followed by two spaces."
395 (reverse (fold-matches
396 "\\. [A-Z]" description '()
398 ;; Filter out matches of common abbreviations.
399 (if (find (lambda (s)
400 (string-suffix-ci? s (match:prefix m)))
401 '("i.e" "e.g" "a.k.a" "resp"))
402 r (cons (match:start m) r)))))))
403 (if (null? infractions)
406 (make-warning package
407 (G_ "sentences in description should be followed ~
408 by two spaces; possible infraction~p at ~{~a~^, ~}")
409 (list (length infractions)
411 #:field 'description)))))
413 (define (check-no-leading-whitespace description)
414 "Check that DESCRIPTION doesn't have trailing whitespace."
415 (if (string-prefix? " " description)
417 (make-warning package
418 (G_ "description contains leading whitespace")
419 #:field 'description))
422 (define (check-no-trailing-whitespace description)
423 "Check that DESCRIPTION doesn't have trailing whitespace."
424 (if (string-suffix? " " description)
426 (make-warning package
427 (G_ "description contains trailing whitespace")
428 #:field 'description))
431 (let ((description (package-description package)))
432 (if (string? description)
434 (check-not-empty description)
435 (check-quotes description)
436 (check-trademarks description)
437 (check-description-typo description '(("This packages" . "This package")
438 ("This modules" . "This module")
440 ("permits to" . #f)))
441 ;; Use raw description for this because Texinfo rendering
442 ;; automatically fixes end of sentence space.
443 (check-end-of-sentence-space description)
444 (check-no-leading-whitespace description)
445 (check-no-trailing-whitespace description)
446 (match (check-texinfo-markup description)
447 ((and warning (? lint-warning?)) (list warning))
449 (check-proper-start plain-description))))
451 (make-warning package
452 (G_ "invalid description: ~s")
454 #:field 'description)))))
456 (define (package-input-intersection inputs-to-check input-names)
457 "Return the intersection between INPUTS-TO-CHECK, the list of input tuples
458 of a package, and INPUT-NAMES, a list of package specifications such as
460 (match inputs-to-check
461 (((labels packages . outputs) ...)
462 (filter-map (lambda (package output)
463 (and (package? package)
464 (let ((input (string-append
465 (package-name package)
466 (if (> (length output) 0)
467 (string-append ":" (car output))
469 (and (member input input-names)
473 (define (check-inputs-should-be-native package)
474 ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
476 (let ((inputs (append (package-inputs package)
477 (package-propagated-inputs package)))
487 "extra-cmake-modules"
491 "gobject-introspection"
511 "python-setuptools-scm"
518 "xorg-server-for-tests"
523 (G_ "'~a' should probably be a native input")
526 (package-input-intersection inputs input-names))))
528 (define (check-inputs-should-not-be-an-input-at-all package)
529 ;; Emit a warning if some inputs of PACKAGE are likely to should not be
531 (let ((input-names '("python-setuptools"
536 (G_ "'~a' should probably not be an input at all")
539 (package-input-intersection (package-direct-inputs package)
542 (define (check-input-labels package)
543 "Emit a warning for labels that differ from the corresponding package name."
544 (define (check input-kind package-inputs)
545 (define (warning label name)
546 (make-warning package
547 (G_ "label '~a' does not match package name '~a'")
551 (append-map (match-lambda
552 (((? string? label) (? package? dependency))
553 (if (string=? label (package-name dependency))
555 (list (warning label (package-name dependency)))))
556 (((? string? label) (? package? dependency) output)
557 (let ((expected (string-append (package-name dependency)
559 (if (string=? label expected)
561 (list (warning label expected)))))
564 (package-inputs package)))
566 (append-map (match-lambda
569 `((native-inputs ,package-native-inputs)
570 (inputs ,package-inputs)
571 (propagated-inputs ,package-propagated-inputs))))
573 (define (report-wrap-program-error package wrapper-name)
574 "Warn that \"bash-minimal\" is missing from 'inputs', while WRAPPER-NAME
576 (make-warning package
577 (G_ "\"bash-minimal\" should be in 'inputs' when '~a' is used")
578 (list wrapper-name)))
580 (define (check-wrapper-inputs package)
581 "Emit a warning if PACKAGE uses 'wrap-program' or similar, but \"bash\"
582 or \"bash-minimal\" is not in its inputs. 'wrap-script' is not supported."
583 (define input-names '("bash" "bash-minimal"))
584 (define has-bash-input?
585 (pair? (package-input-intersection (package-inputs package)
587 (define (check-procedure-body body)
589 ;; Explicitely setting an interpreter is acceptable.
590 (('wrap-program _ '#:sh . _) '())
591 (('wrap-program _ . _)
592 (list (report-wrap-program-error package 'wrap-program)))
593 ;; Wrapper of 'wrap-program' for Qt programs.
594 ;; TODO #:sh is not yet supported but probably will be.
595 (('wrap-qt-program _ '#:sh . _) '())
596 (('wrap-qt-program _ . _)
597 (list (report-wrap-program-error package 'wrap-qt-program)))
599 (append (check-procedure-body x) (check-procedure-body y)))
601 (define (check-phase-procedure expression)
602 (find-procedure-body expression check-procedure-body))
603 (define (check-delta expression)
604 (find-phase-procedure package expression check-phase-procedure))
605 (define (check-deltas deltas)
606 (append-map check-delta deltas))
608 ;; "bash" (or "bash-minimal") is in 'inputs', so everything seems ok.
610 ;; "bash" is not in 'inputs'. Verify 'wrap-program' and friends
612 (find-phase-deltas package check-deltas)))
614 (define (package-name-regexp package)
615 "Return a regexp that matches PACKAGE's name as a word at the beginning of a
617 (make-regexp (string-append "^" (regexp-quote (package-name package))
621 (define (check-synopsis-style package)
622 ;; Emit a warning if stylistic issues are found in the synopsis of PACKAGE.
623 (define (check-final-period synopsis)
624 ;; Synopsis should not end with a period, except for some special cases.
625 (if (and (string-suffix? "." synopsis)
626 (not (string-suffix? "etc." synopsis)))
628 (make-warning package
629 (G_ "no period allowed at the end of the synopsis")
633 (define check-start-article
634 ;; Skip this check for GNU packages, as suggested by Karl Berry's reply to
635 ;; <http://lists.gnu.org/archive/html/bug-womb/2014-11/msg00000.html>.
636 (if (false-if-exception (gnu-package? package))
639 (if (or (string-prefix-ci? "A " synopsis)
640 (string-prefix-ci? "An " synopsis))
642 (make-warning package
643 (G_ "no article allowed at the beginning of \
648 (define (check-synopsis-length synopsis)
649 (if (>= (string-length synopsis) 80)
651 (make-warning package
652 (G_ "synopsis should be less than 80 characters long")
656 (define (check-proper-start synopsis)
657 (if (properly-starts-sentence? synopsis)
660 (make-warning package
661 (G_ "synopsis should start with an upper-case letter or digit")
662 #:field 'synopsis))))
664 (define (check-start-with-package-name synopsis)
665 (if (and (regexp-exec (package-name-regexp package) synopsis)
666 (not (starts-with-abbreviation? synopsis)))
668 (make-warning package
669 (G_ "synopsis should not start with the package name")
673 (define (check-texinfo-markup synopsis)
674 "Check that SYNOPSIS can be parsed as a Texinfo fragment. If the
675 markup is valid return a plain-text version of SYNOPSIS, otherwise #f."
678 (texi->plain-text synopsis)
680 (lambda (keys . args)
682 (make-warning package
683 (G_ "Texinfo markup in synopsis is invalid")
684 #:field 'synopsis)))))
686 (define (check-no-trailing-whitespace synopsis)
687 "Check that SYNOPSIS doesn't have trailing whitespace."
688 (if (string-suffix? " " synopsis)
690 (make-warning package
691 (G_ "synopsis contains trailing whitespace")
696 (list check-proper-start
699 check-start-with-package-name
700 check-synopsis-length
702 check-no-trailing-whitespace))
704 (match (package-synopsis package)
707 (make-warning package
708 (G_ "synopsis should not be empty")
710 ((? string? synopsis)
717 (make-warning package
718 (G_ "invalid synopsis: ~s")
720 #:field 'synopsis)))))
722 (define* (probe-uri uri #:key timeout)
723 "Probe URI, a URI object, and return two values: a symbol denoting the
724 probing status, such as 'http-response' when we managed to get an HTTP
725 response from URI, and additional details, such as the actual HTTP response.
727 TIMEOUT is the maximum number of seconds (possibly an inexact number) to wait
728 for connections to complete; when TIMEOUT is #f, wait as long as needed."
730 `((User-Agent . "GNU Guile")
732 ,@(match (uri-userinfo uri)
733 ((? string? str) ;"basic authentication"
734 `((Authorization . ,(string-append "Basic "
736 (string->utf8 str))))))
741 (match (uri-scheme uri)
745 (let ((port (guix:open-connection-for-uri
746 uri #:timeout timeout))
747 (request (build-request uri #:headers headers)))
752 (write-request request port)
754 (read-response port))
758 (case (response-code response)
759 ((302 ; found (redirection)
761 307 ; temporary redirection
762 308) ; permanent redirection
763 (let ((location (response-location response)))
764 (if (or (not location) (member location visited))
765 (values 'http-response response)
766 (loop location (cons location visited))))) ;follow the redirect
767 ((301) ; moved permanently
768 (let ((location (response-location response)))
769 ;; Return RESPONSE, unless the final response as we follow
770 ;; redirects is not 200.
772 (let-values (((status response2)
773 (loop location (cons location visited))))
776 (values 'http-response
777 (if (= 200 (response-code response2))
781 (values status response2))))
782 (values 'http-response response)))) ;invalid redirect
784 (values 'http-response response)))))
787 ((bad-header bad-header-component)
788 ;; This can happen if the server returns an invalid HTTP header,
789 ;; as is the case with the 'Date' header at sqlite.org.
790 (values 'invalid-http-response #f))
791 ((getaddrinfo-error system-error
792 gnutls-error tls-certificate-error)
795 (apply throw key args))))))
799 (let ((conn (ftp-open (uri-host uri) #:timeout timeout)))
804 (ftp-chdir conn (dirname (uri-path uri)))
805 (ftp-size conn (basename (uri-path uri))))
808 (values 'ftp-response '(ok))))
812 (values 'ftp-response `(error ,@args)))
813 ((getaddrinfo-error system-error gnutls-error)
816 (apply throw key args))))))
818 (values 'unknown-protocol #f)))))
820 (define (call-with-networking-fail-safe message error-value proc)
821 "Call PROC catching any network-related errors. Upon a networking error,
822 display a message including MESSAGE and return ERROR-VALUE."
823 (guard (c ((http-get-error? c)
824 (warning (G_ "~a: HTTP GET error for ~a: ~a (~s)~%")
826 (uri->string (http-get-error-uri c))
827 (http-get-error-code c)
828 (http-get-error-reason c))
833 (('getaddrinfo-error errcode)
834 (warning (G_ "~a: host lookup failure: ~a~%")
836 (gai-strerror errcode))
838 (('tls-certificate-error args ...)
839 (warning (G_ "~a: TLS certificate error: ~a")
841 (tls-certificate-error-string args))
843 (('gnutls-error error function _ ...)
844 (warning (G_ "~a: TLS error in '~a': ~a~%")
846 function (error->string error))
848 ((and ('system-error _ ...) args)
849 (let ((errno (system-error-errno args)))
850 (if (member errno (list ECONNRESET ECONNABORTED ECONNREFUSED))
851 (let ((details (call-with-output-string
853 (print-exception port #f (car args)
855 (warning (G_ "~a: ~a~%") message details)
857 (apply throw args))))
859 (apply throw args))))))
861 (define-syntax-rule (with-networking-fail-safe message error-value exp ...)
862 (call-with-networking-fail-safe message error-value
863 (lambda () exp ...)))
865 (define (tls-certificate-error-string args)
866 "Return a string explaining the 'tls-certificate-error' arguments ARGS."
867 (call-with-output-string
869 (print-exception port #f
870 'tls-certificate-error args))))
872 (define (validate-uri uri package field)
873 "Return #t if the given URI can be reached, otherwise return a warning for
874 PACKAGE mentioning the FIELD."
875 (let-values (((status argument)
876 (probe-uri uri #:timeout 3))) ;wait at most 3 seconds
879 (cond ((= 200 (response-code argument))
880 (match (response-content-length argument)
882 ;; As of July 2016, SourceForge returns 200 (instead of 404)
883 ;; with a small HTML page upon failure. Attempt to detect
884 ;; such malicious behavior.
886 (make-warning package
887 (G_ "URI ~a returned \
888 suspiciously small file (~a bytes)")
889 (list (uri->string uri)
893 ((= 301 (response-code argument))
894 (if (response-location argument)
895 (make-warning package
896 (G_ "permanent redirect from ~a to ~a")
897 (list (uri->string uri)
899 (response-location argument)))
901 (make-warning package
902 (G_ "invalid permanent redirect \
904 (list (uri->string uri))
907 (make-warning package
908 (G_ "URI ~a not reachable: ~a (~s)")
909 (list (uri->string uri)
910 (response-code argument)
911 (response-reason-phrase argument))
916 (('error port command code message)
917 (make-warning package
918 (G_ "URI ~a not reachable: ~a (~s)")
919 (list (uri->string uri)
920 code (string-trim-both message))
923 (make-warning package
924 (G_ "URI ~a domain not found: ~a")
925 (list (uri->string uri)
926 (gai-strerror (car argument)))
929 (make-warning package
930 (G_ "URI ~a unreachable: ~a")
931 (list (uri->string uri)
934 (cons status argument))))
936 ((tls-certificate-error)
937 (make-warning package
938 (G_ "TLS certificate error: ~a")
939 (list (tls-certificate-error-string argument))
941 ((invalid-http-response gnutls-error)
942 ;; Probably a misbehaving server; ignore.
944 ((unknown-protocol) ;nothing we can do
947 (error "internal linter error" status)))))
949 (define (check-home-page package)
950 "Emit a warning if PACKAGE has an invalid 'home-page' field, or if that
951 'home-page' is not reachable."
952 (let ((uri (and=> (package-home-page package) string->uri)))
955 (match (validate-uri uri package 'home-page)
956 ((and (? lint-warning? warning) warning)
959 ((not (package-home-page package))
960 (if (or (string-contains (package-name package) "bootstrap")
961 (string=? (package-name package) "ld-wrapper"))
964 (make-warning package
965 (G_ "invalid value for home page")
966 #:field 'home-page))))
969 (make-warning package
970 (G_ "invalid home page URL: ~s")
971 (list (package-home-page package))
972 #:field 'home-page))))))
974 (define %distro-directory
976 (dirname (search-path %load-path "gnu.scm"))))
978 (define (check-patch-file-names package)
979 "Emit a warning if the patches requires by PACKAGE are badly named or if the
980 patch could not be found."
981 (guard (c ((formatted-message? c) ;raised by 'search-patch'
982 (list (%make-warning package
983 (formatted-message-string c)
984 (formatted-message-arguments c)
987 (match (package-source package)
988 ((? origin? origin) (origin-patches origin))
991 (define (starts-with-package-name? file-name)
992 (and=> (string-contains file-name (package-name package))
996 (if (every (match-lambda ;patch starts with package name?
998 (starts-with-package-name? (basename patch)))
1000 (starts-with-package-name? (origin-actual-file-name patch)))
1001 (_ #f)) ;must be some other file-like object
1007 (G_ "file names of patches should start with the package name")
1008 #:field 'patch-file-names)))
1010 ;; Check whether we're reaching tar's maximum file name length.
1011 (let ((prefix (string-length (%distro-directory)))
1012 ;; Margin approximating the largest path that "make dist" might
1013 ;; create, with a release candidate version, 123456 commits, and
1014 ;; git commit hash abcde0.
1015 (margin (string-length "guix-92.0.0rc3-123456-abcde0/"))
1016 ;; Tested maximum patch file length for ustar format.
1018 (filter-map (match-lambda
1020 (if (> (+ margin (if (string-prefix? (%distro-directory)
1022 (- (string-length patch) prefix)
1023 (string-length patch)))
1027 (G_ "~a: file name is too long, which may break 'make dist'")
1028 (list (basename patch))
1029 #:field 'patch-file-names)
1034 (define (check-patch-headers package)
1035 "Check that PACKAGE's patches start with a comment. Return a list of
1037 (define (blank? str)
1038 (string-every char-set:blank str))
1040 (define (patch-header-warnings patch)
1041 (call-with-input-file patch
1043 ;; Read from PORT until a non-blank line is found or EOF is reached.
1045 (let ((line (read-line port)))
1046 (cond ((eof-object? line)
1047 (list (make-warning package
1048 (G_ "~a: empty patch")
1049 (list (basename patch))
1053 ((or (string-prefix? "--- " line)
1054 (string-prefix? "+++ " line)
1055 (string-prefix? "diff --git " line))
1056 (list (make-warning package
1057 (G_ "~a: patch lacks comment and \
1059 (list (basename patch))
1064 (guard (c ((formatted-message? c) ;raised by 'search-patch'
1065 (list (%make-warning package
1066 (formatted-message-string c)
1067 (formatted-message-arguments c)
1069 (let ((patches (if (origin? (package-source package))
1070 (origin-patches (package-source package))
1072 (append-map (lambda (patch)
1073 ;; Dismiss PATCH if it's an origin or similar.
1074 (cond ((string? patch)
1075 (patch-header-warnings patch))
1076 ((local-file? patch)
1077 (patch-header-warnings
1078 (local-file-absolute-file-name patch)))
1083 (define (escape-quotes str)
1084 "Replace any quote character in STR by an escaped quote character."
1086 (string-fold-right (lambda (chr result)
1088 (#\" (cons* #\\ #\"result))
1089 (_ (cons chr result))))
1093 (define official-gnu-packages*
1095 "A memoizing version of 'official-gnu-packages' that returns the empty
1096 list when something goes wrong, such as a networking issue."
1097 (let ((gnus (false-if-exception (official-gnu-packages))))
1100 (define (check-gnu-synopsis+description package)
1101 "Make sure that, if PACKAGE is a GNU package, it uses the synopsis and
1102 descriptions maintained upstream."
1103 (match (find (lambda (descriptor)
1104 (string=? (gnu-package-name descriptor)
1105 (package-name package)))
1106 (official-gnu-packages*))
1107 (#f ;not a GNU package, so nothing to do
1109 (descriptor ;a genuine GNU package
1111 (let ((upstream (gnu-package-doc-summary descriptor))
1112 (downstream (package-synopsis package)))
1114 (or (not (string? downstream))
1115 (not (string=? upstream downstream))))
1117 (make-warning package
1118 (G_ "proposed synopsis: ~s~%")
1123 (let ((upstream (gnu-package-doc-description descriptor))
1124 (downstream (package-description package)))
1126 (or (not (string? downstream))
1127 (not (string=? (fill-paragraph upstream 100)
1128 (fill-paragraph downstream 100)))))
1132 (G_ "proposed description:~% \"~a\"~%")
1133 (list (fill-paragraph (escape-quotes upstream) 77 7))
1134 #:field 'description))
1137 (define (origin-uris origin)
1138 "Return the list of URIs (strings) for ORIGIN."
1139 (match (origin-uri origin)
1145 (define (svn-reference-uri-with-userinfo ref)
1146 "Return the URI of REF, an <svn-reference> object, but with an additional
1147 'userinfo' part corresponding to REF's user name and password, provided REF's
1148 URI is HTTP or HTTPS."
1149 (let ((uri (string->uri (svn-reference-url ref))))
1150 (if (and (svn-reference-user-name ref)
1151 (memq (uri-scheme uri) '(http https)))
1152 (build-uri (uri-scheme uri)
1154 (string-append (svn-reference-user-name ref)
1155 (if (svn-reference-password ref)
1157 ":" (svn-reference-password ref))
1159 #:host (uri-host uri)
1160 #:port (uri-port uri)
1161 #:query (uri-query uri)
1162 #:fragment (uri-fragment uri))
1165 (define (check-source package)
1166 "Emit a warning if PACKAGE has an invalid 'source' field, or if that
1167 'source' is not reachable."
1168 (define (warnings-for-uris uris)
1169 (let loop ((uris uris)
1175 (match (validate-uri uri package 'source)
1177 ;; We found a working URL, so stop right away.
1180 ;; Unsupported URL or other error, skip.
1181 (loop rest warnings))
1182 ((? lint-warning? warning)
1183 (loop rest (cons warning warnings))))))))
1185 (let ((origin (package-source package)))
1186 (if (origin? origin)
1188 ((eq? (origin-method origin) url-fetch)
1189 (let* ((uris (append-map (cut maybe-expand-mirrors <> %mirrors)
1190 (map string->uri (origin-uris origin))))
1191 (warnings (warnings-for-uris uris)))
1193 ;; Just make sure that at least one of the URIs is valid.
1194 (if (= (length uris) (length warnings))
1195 ;; When everything fails, report all of WARNINGS, otherwise don't
1198 ;; XXX: Ideally we'd still allow warnings to be raised if *some*
1199 ;; URIs are unreachable, but distinguish that from the error case
1200 ;; where *all* the URIs are unreachable.
1202 (make-warning package
1203 (G_ "all the source URIs are unreachable:")
1207 ((git-reference? (origin-uri origin))
1209 (list (string->uri (git-reference-url (origin-uri origin))))))
1210 ((svn-reference? (origin-uri origin))
1211 (let ((uri (svn-reference-uri-with-userinfo (origin-uri origin))))
1212 (if (memq (uri-scheme uri) '(http https))
1213 (warnings-for-uris (list uri))
1214 '()))) ;TODO: handle svn:// URLs
1219 (define (check-source-file-name package)
1220 "Emit a warning if PACKAGE's origin has no meaningful file name."
1221 (define (origin-file-name-valid? origin)
1222 ;; Return #f if the source file name contains only a version or is #f;
1223 ;; indicates that the origin needs a 'file-name' field.
1224 (let ((file-name (origin-actual-file-name origin))
1225 (version (package-version package)))
1227 ;; Common in many projects is for the filename to start
1228 ;; with a "v" followed by the version,
1229 ;; e.g. "v3.2.0.tar.gz".
1230 (not (string-match (string-append "^v?" version) file-name)))))
1232 (let ((origin (package-source package)))
1233 (if (or (not (origin? origin)) (origin-file-name-valid? origin))
1236 (make-warning package
1237 (G_ "the source file name should contain the package name")
1238 #:field 'source)))))
1240 (define (check-source-unstable-tarball package)
1241 "Emit a warning if PACKAGE's source is an autogenerated tarball."
1242 (define (check-source-uri uri)
1243 (if (and (string=? (uri-host (string->uri uri)) "github.com")
1244 (match (split-and-decode-uri-path
1245 (uri-path (string->uri uri)))
1246 ((_ _ "archive" _ ...) #t)
1248 (make-warning package
1249 (G_ "the source URI should not be an autogenerated tarball")
1253 (let ((origin (package-source package)))
1254 (if (and (origin? origin)
1255 (eqv? (origin-method origin) url-fetch))
1256 (filter-map check-source-uri
1257 (origin-uris origin))
1260 (define (check-mirror-url package)
1261 "Check whether PACKAGE uses source URLs that should be 'mirror://'."
1262 (define (check-mirror-uri uri)
1263 (define rewritten-uri
1264 (uri-mirror-rewrite uri))
1266 (and (not (string=? uri rewritten-uri))
1267 (make-warning package (G_ "URL should be '~a'")
1268 (list rewritten-uri)
1271 (let ((origin (package-source package)))
1272 (if (and (origin? origin)
1273 (eqv? (origin-method origin) url-fetch))
1274 (let ((uris (origin-uris origin)))
1275 (filter-map check-mirror-uri uris))
1278 (define* (check-github-url package #:key (timeout 3))
1279 "Check whether PACKAGE uses source URLs that redirect to GitHub."
1280 (define (follow-redirect url)
1281 (let* ((uri (string->uri url))
1282 (port (guix:open-connection-for-uri uri #:timeout timeout))
1283 (response (http-head uri #:port port)))
1285 (case (response-code response)
1287 (uri->string (assoc-ref (response-headers response) 'location)))
1290 (define (follow-redirects-to-github uri)
1292 ((string-prefix? "https://github.com/" uri) uri)
1293 ((string-prefix? "http" uri)
1294 (and=> (follow-redirect uri) follow-redirects-to-github))
1295 ;; Do not attempt to follow redirects on URIs other than http and https
1296 ;; (such as mirror, file)
1299 (let ((origin (package-source package)))
1300 (if (and (origin? origin)
1301 (eqv? (origin-method origin) url-fetch))
1304 (and=> (with-networking-fail-safe
1305 (format #f (G_ "while accessing '~a'") uri)
1307 (follow-redirects-to-github uri))
1308 (lambda (github-uri)
1309 (and (not (string=? github-uri uri))
1312 (G_ "URL should be '~a'")
1314 #:field 'source)))))
1315 (origin-uris origin))
1318 ;; Guile 3.0.0 does not export this predicate.
1319 (define exception-with-kind-and-args?
1320 (exception-predicate &exception-with-kind-and-args))
1322 (define (check-optional-tests package)
1323 "Emit a warning if the test suite is run unconditionally."
1324 (define (sexp-contains-atom? sexp atom)
1325 "Test if SEXP contains ATOM."
1327 (or (sexp-contains-atom? (car sexp) atom)
1328 (sexp-contains-atom? (cdr sexp) atom))
1330 (define (sexp-uses-tests?? sexp)
1331 "Test if SEXP contains the symbol 'tests?'."
1332 (sexp-contains-atom? sexp 'tests?))
1333 (define (check-procedure-body code)
1334 (if (sexp-uses-tests?? code)
1336 (list (make-warning package
1337 ;; TRANSLATORS: check and #:tests? are a
1338 ;; Scheme symbol and keyword respectively
1339 ;; and should not be translated.
1340 (G_ "the 'check' phase should respect #:tests?")
1341 #:field 'arguments))))
1342 (define (check-check-procedure expression)
1343 (find-procedure-body expression check-procedure-body))
1344 (define (check-phases-delta delta)
1346 (`(replace 'check ,expression)
1347 (check-check-procedure expression))
1349 (define (check-phases-deltas deltas)
1350 (append-map check-phases-delta deltas))
1351 (find-phase-deltas package check-phases-deltas))
1353 (define* (check-derivation package #:key store)
1354 "Emit a warning if we fail to compile PACKAGE to a derivation."
1355 (define (try store system)
1356 (guard (c ((store-protocol-error? c)
1357 (make-warning package
1358 (G_ "failed to create ~a derivation: ~a")
1360 (store-protocol-error-message c))))
1361 ((exception-with-kind-and-args? c)
1362 (make-warning package
1363 (G_ "failed to create ~a derivation: ~s")
1365 (cons (exception-kind c)
1366 (exception-args c)))))
1367 ((message-condition? c)
1368 (make-warning package
1369 (G_ "failed to create ~a derivation: ~a")
1371 (condition-message c))))
1372 ((formatted-message? c)
1373 (let ((str (apply format #f
1374 (formatted-message-string c)
1375 (formatted-message-arguments c))))
1376 (make-warning package
1377 (G_ "failed to create ~a derivation: ~a")
1378 (list system str))))
1380 (make-warning package
1381 (G_ "failed to create ~a derivation: ~a")
1383 (parameterize ((%graft? #f))
1384 (package-derivation store package system #:graft? #f)
1386 ;; If there's a replacement, make sure we can compute its
1388 (match (package-replacement package)
1391 (package-derivation store replacement system
1394 (define (check-with-store store)
1395 (filter lint-warning?
1396 (map (cut try store <>) (package-supported-systems package))))
1398 ;; For backwards compatability, don't rely on store being set
1399 (or (and=> store check-with-store)
1401 (check-with-store store))))
1403 (define* (check-profile-collisions package #:key store)
1404 "Check for collisions that would occur when installing PACKAGE as a result
1405 of the propagated inputs it pulls in."
1406 (define (do-check store)
1407 (guard (c ((profile-collision-error? c)
1408 (let ((first (profile-collision-error-entry c))
1409 (second (profile-collision-error-conflict c)))
1411 (if (string=? (manifest-entry-version first)
1412 (manifest-entry-version second))
1415 (string-append (manifest-entry-name entry) "@"
1416 (manifest-entry-version entry)))))
1418 (list (make-warning package
1419 (G_ "propagated inputs ~a and ~a collide")
1420 (list (format first)
1421 (format second)))))))
1422 ;; Disable grafts to avoid building PACKAGE and its dependencies.
1423 (parameterize ((%graft? #f))
1424 (run-with-store store
1425 (mbegin %store-monad
1426 (check-for-collisions (packages->manifest (list package))
1435 (define (check-license package)
1436 "Warn about type errors of the 'license' field of PACKAGE."
1437 (match (package-license package)
1443 (make-warning package (G_ "invalid license field")
1444 #:field 'license)))))
1446 (define (current-vulnerabilities*)
1447 "Like 'current-vulnerabilities', but return the empty list upon networking
1448 or HTTP errors. This allows network-less operation and makes problems with
1449 the NIST server non-fatal."
1450 (with-networking-fail-safe (G_ "while retrieving CVE vulnerabilities")
1452 (current-vulnerabilities #:timeout 4)))
1454 (define package-vulnerabilities
1455 (let ((lookup (delay (vulnerabilities->lookup-proc
1456 (current-vulnerabilities*)))))
1458 "Return a list of vulnerabilities affecting PACKAGE."
1459 ;; First we retrieve the Common Platform Enumeration (CPE) name and
1460 ;; version for PACKAGE, then we can pass them to LOOKUP.
1461 (let ((name (or (assoc-ref (package-properties package)
1463 (package-name package)))
1464 (version (or (assoc-ref (package-properties package)
1466 (package-version package))))
1467 ((force lookup) name version)))))
1469 (define* (check-vulnerabilities package
1470 #:optional (package-vulnerabilities
1471 package-vulnerabilities))
1472 "Check for known vulnerabilities for PACKAGE. Obtain the list of
1473 vulnerability records for PACKAGE by calling PACKAGE-VULNERABILITIES."
1474 (let ((package (or (package-replacement package) package)))
1475 (match (package-vulnerabilities package)
1478 ((vulnerabilities ...)
1479 (let* ((patched (package-patched-vulnerabilities package))
1480 (known-safe (or (assq-ref (package-properties package)
1483 (unpatched (remove (lambda (vuln)
1484 (let ((id (vulnerability-id vuln)))
1485 (or (member id patched)
1486 (member id known-safe))))
1488 (if (null? unpatched)
1493 (G_ "probably vulnerable to ~a")
1494 (list (string-join (map vulnerability-id unpatched)
1497 (define (check-for-updates package)
1498 "Check if there is an update available for PACKAGE."
1499 (match (lookup-updater package)
1501 (list (make-warning package (G_ "no updater for ~a")
1502 (list (package-name package))
1504 ((? upstream-updater? updater)
1505 (match (with-networking-fail-safe
1506 (format #f (G_ "while retrieving upstream info for '~a'")
1507 (package-name package))
1509 (package-latest-release package))
1510 ((? upstream-source? source)
1511 (if (version>? (upstream-source-version source)
1512 (package-version package))
1514 (make-warning package
1515 (G_ "can be upgraded to ~a")
1516 (list (upstream-source-version source))
1519 (#f ;cannot find upstream release
1520 (list (make-warning package
1521 (G_ "updater '~a' failed to find \
1523 (list (upstream-updater-name updater))
1524 #:field 'source)))))))
1527 (define (lookup-disarchive-spec hash)
1528 "If Disarchive mirrors have a spec for HASH, return the list of SWH
1529 directory identifiers the spec refers to. Otherwise return #f."
1530 (define (extract-swh-id spec)
1531 ;; Return the list of SWH directory identifiers SPEC refers to, where SPEC
1532 ;; is a Disarchive sexp. Instead of attempting to parse it, traverse it
1533 ;; in a pretty unintelligent fashion.
1534 (let loop ((sexp spec)
1538 (let ((prefix "swh:1:dir:"))
1539 (if (string-prefix? prefix str)
1540 (cons (string-drop str (string-length prefix)) ids)
1543 (loop tail (loop head ids)))
1546 (any (lambda (mirror)
1547 (with-networking-fail-safe
1548 (format #f (G_ "failed to access Disarchive database at ~a")
1551 (guard (c ((http-get-error? c) #f))
1552 (let* ((url (string-append mirror
1554 (content-hash-algorithm hash))
1556 (bytevector->base16-string
1557 (content-hash-value hash))))
1558 (port (http-fetch (string->uri url) #:text? #t))
1561 (extract-swh-id spec)))))
1562 %disarchive-mirrors))
1564 (define (check-archival package)
1565 "Check whether PACKAGE's source code is archived on Software Heritage. If
1566 it's not, and if its source code is a VCS snapshot, then send a \"save\"
1567 request to Software Heritage.
1569 Software Heritage imposes limits on the request rate per client IP address.
1570 This checker prints a notice and stops doing anything once that limit has been
1572 (define (response->warning url method response)
1573 (if (request-rate-limit-reached? url method)
1574 (list (make-warning package
1575 (G_ "Software Heritage rate limit reached; \
1578 (list (make-warning package
1579 (G_ "'~a' returned ~a")
1580 (list url (response-code response))
1583 (define skip-key (gensym "skip-archival-check"))
1585 (define (skip-when-limit-reached url method)
1586 (or (not (request-rate-limit-reached? url method))
1587 (throw skip-key #t)))
1589 (parameterize ((%allow-request? skip-when-limit-reached))
1592 (match (and (origin? (package-source package))
1593 (package-source package))
1596 ((= origin-uri (? git-reference? reference))
1598 (git-reference-url reference))
1600 (git-reference-commit reference))
1602 (match (if (commit-id? commit)
1603 (or (lookup-revision commit)
1604 (lookup-origin-revision url commit))
1605 (lookup-origin-revision url commit))
1606 ((? revision? revision)
1609 ;; Revision is missing from the archive, attempt to save it.
1612 (save-origin (git-reference-url reference) "git")
1615 ;; TRANSLATORS: "Software Heritage" is a proper noun
1616 ;; that must remain untranslated. See
1617 ;; <https://www.softwareheritage.org>.
1618 (G_ "scheduled Software Heritage archival")
1620 (lambda (key url method response . _)
1621 (cond ((= 429 (response-code response))
1624 (G_ "archival rate limit exceeded; \
1628 (response->warning url method response))))))))
1630 ;; Since "save" origins are not supported for non-VCS source, all
1631 ;; we can do is tell whether a given tarball is available or not.
1632 (if (and=> (origin-hash origin) ;XXX: for ungoogled-chromium
1633 content-hash-value) ;& icecat
1634 (let ((hash (origin-hash origin)))
1635 (match (lookup-content (content-hash-value hash)
1637 (content-hash-algorithm hash)))
1639 ;; If SWH doesn't have HASH as is, it may be because it's
1640 ;; a hand-crafted tarball. In that case, check whether
1641 ;; the Disarchive database has an entry for that tarball.
1642 (match (lookup-disarchive-spec hash)
1644 (list (make-warning package
1645 (G_ "source not archived on Software \
1646 Heritage and missing from the Disarchive database")
1649 (match (find (lambda (id)
1650 (not (lookup-directory id)))
1654 (list (make-warning package
1656 Disarchive entry refers to non-existent SWH directory '~a'")
1658 #:field 'source)))))))
1663 (list (make-warning package
1664 (G_ "unsupported source type")
1665 #:field 'source)))))
1667 (('swh-error url method response)
1668 (response->warning url method response))
1670 (if (eq? key skip-key)
1672 (with-networking-fail-safe
1673 (G_ "while connecting to Software Heritage")
1675 (apply throw key args))))))))
1677 (define (check-haskell-stackage package)
1678 "Check whether PACKAGE is a Haskell package ahead of the current
1679 Stackage LTS version."
1680 (match (with-networking-fail-safe
1681 (format #f (G_ "while retrieving upstream info for '~a'")
1682 (package-name package))
1684 (package-latest-release package (list %stackage-updater)))
1685 ((? upstream-source? source)
1686 (if (version>? (package-version package)
1687 (upstream-source-version source))
1689 (make-warning package
1690 (G_ "ahead of Stackage LTS version ~a")
1691 (list (upstream-source-version source))
1698 ;;; Source code formatting.
1701 (define (report-tabulations package line line-number)
1702 "Warn about tabulations found in LINE."
1703 (match (string-index line #\tab)
1706 (make-warning package
1707 (G_ "tabulation on line ~a, column ~a")
1708 (list line-number index)
1710 (location (package-file package)
1714 (define (report-trailing-white-space package line line-number)
1715 "Warn about trailing white space in LINE."
1716 (and (not (or (string=? line (string-trim-right line))
1717 (string=? line (string #\page))))
1718 (make-warning package
1719 (G_ "trailing white space on line ~a")
1722 (location (package-file package)
1726 (define (report-long-line package line line-number)
1727 "Emit a warning if LINE is too long."
1728 ;; Note: We don't warn at 80 characters because sometimes hashes and URLs
1729 ;; make it hard to fit within that limit and we want to avoid making too
1731 (and (> (string-length line) 90)
1732 (make-warning package
1733 (G_ "line ~a is way too long (~a characters)")
1734 (list line-number (string-length line))
1736 (location (package-file package)
1740 (define %hanging-paren-rx
1741 (make-regexp "^[[:blank:]]*[()]+[[:blank:]]*$"))
1743 (define (report-lone-parentheses package line line-number)
1744 "Emit a warning if LINE contains hanging parentheses."
1745 (and (regexp-exec %hanging-paren-rx line)
1746 (make-warning package
1747 (G_ "parentheses feel lonely, \
1748 move to the previous or next line")
1751 (location (package-file package)
1755 (define %formatting-reporters
1756 ;; List of procedures that report formatting issues. These are not separate
1757 ;; checkers because they would need to re-read the file.
1758 (list report-tabulations
1759 report-trailing-white-space
1761 report-lone-parentheses))
1763 (define* (report-formatting-issues package file starting-line
1764 #:key (reporters %formatting-reporters))
1765 "Report white-space issues in FILE starting from STARTING-LINE, and report
1767 (define (sexp-last-line port)
1768 ;; Return the last line of the sexp read from PORT or an estimate thereof.
1769 (define &failure (list 'failure))
1771 (let ((start (ftell port))
1772 (start-line (port-line port))
1773 (sexp (catch 'read-error
1774 (lambda () (read port))
1776 (let ((line (port-line port)))
1777 (seek port start SEEK_SET)
1778 (set-port-line! port start-line)
1779 (if (eq? sexp &failure)
1780 (+ start-line 60) ;conservative estimate
1783 (call-with-input-file file
1785 (let loop ((line-number 1)
1788 (let ((line (read-line port)))
1789 (if (or (eof-object? line)
1790 (and last-line (> line-number last-line)))
1792 (if (and (= line-number starting-line)
1794 (loop (+ 1 line-number)
1795 (+ 1 (sexp-last-line port))
1797 (loop (+ 1 line-number)
1801 (if (< line-number starting-line)
1803 (filter-map (lambda (report)
1804 (report package line line-number))
1805 reporters)))))))))))
1807 (define (check-formatting package)
1808 "Check the formatting of the source code of PACKAGE."
1809 (let ((location (package-location package)))
1811 ;; Report issues starting from the line before the 'package'
1812 ;; form, which usually contains the 'define' form.
1813 (let ((line (- (location-line location) 1)))
1814 (match (search-path %load-path (location-file location))
1816 (report-formatting-issues package file line))
1818 ;; It could be that LOCATION lists a "true" relative file
1819 ;; name--i.e., not relative to an element of %LOAD-PATH.
1820 (let ((file (location-file location)))
1821 (if (file-exists? file)
1822 (report-formatting-issues package file line)
1823 (list (make-warning package
1824 (G_ "source file not found"))))))))
1829 ;;; List of checkers.
1832 (define %local-checkers
1836 (description "Validate package names")
1840 (description "Check if tests are explicitly enabled")
1841 (check check-tests-true))
1844 (description "Validate package descriptions")
1845 (check check-description-style))
1847 (name 'inputs-should-be-native)
1848 (description "Identify inputs that should be native inputs")
1849 (check check-inputs-should-be-native))
1851 (name 'inputs-should-not-be-input)
1852 (description "Identify inputs that shouldn't be inputs at all")
1853 (check check-inputs-should-not-be-an-input-at-all))
1855 (name 'input-labels)
1856 (description "Identify input labels that do not match package names")
1857 (check check-input-labels))
1859 (name 'wrapper-inputs)
1860 (description "Make sure 'wrap-program' can finds its interpreter.")
1861 (check check-wrapper-inputs))
1864 ;; TRANSLATORS: <license> is the name of a data type and must not be
1866 (description "Make sure the 'license' field is a <license> \
1868 (check check-license))
1870 (name 'optional-tests)
1871 (description "Make sure tests are only run when requested")
1872 (check check-optional-tests))
1875 (description "Suggest 'mirror://' URLs")
1876 (check check-mirror-url))
1878 (name 'source-file-name)
1879 (description "Validate file names of sources")
1880 (check check-source-file-name))
1882 (name 'source-unstable-tarball)
1883 (description "Check for autogenerated tarballs")
1884 (check check-source-unstable-tarball))
1887 (description "Report failure to compile a package to a derivation")
1888 (check check-derivation)
1889 (requires-store? #t))
1891 (name 'profile-collisions)
1892 (description "Report collisions that would occur due to propagated inputs")
1893 (check check-profile-collisions)
1894 (requires-store? #t))
1896 (name 'patch-file-names)
1897 (description "Validate file names and availability of patches")
1898 (check check-patch-file-names))
1900 (name 'patch-headers)
1901 (description "Validate patch headers")
1902 (check check-patch-headers))
1905 (description "Look for formatting issues in the source")
1906 (check check-formatting))))
1908 (define %network-dependent-checkers
1912 (description "Validate package synopses")
1913 (check check-synopsis-style))
1915 (name 'gnu-description)
1916 (description "Validate synopsis & description of GNU packages")
1917 (check check-gnu-synopsis+description))
1920 (description "Validate home-page URLs")
1921 (check check-home-page))
1924 (description "Validate source URLs")
1925 (check check-source))
1928 (description "Suggest GitHub URLs")
1929 (check check-github-url))
1932 (description "Check the Common Vulnerabilities and Exposures\
1934 (check check-vulnerabilities))
1937 (description "Check the package for new upstream releases")
1938 (check check-for-updates))
1941 (description "Ensure source code archival on Software Heritage")
1942 (check check-archival))
1944 (name 'haskell-stackage)
1945 (description "Ensure Haskell packages use Stackage LTS versions")
1946 (check check-haskell-stackage))))
1948 (define %all-checkers
1949 (append %local-checkers
1950 %network-dependent-checkers))