From d10474c38d58bdc676e64336769dc2e00cdfa8ed Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 23 Aug 2020 22:48:19 +0200 Subject: lint: formatting: Gracefully handle relative file names. Fixes . Reported by Jack Hill . * guix/lint.scm (check-formatting): Always return a list (previously we would return #f when 'search-path' returns #f). Check whether LOCATION's file is a relative file name. Return a warning if not. * tests/guix-lint.sh: Add test. --- guix/lint.scm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'guix/lint.scm') diff --git a/guix/lint.scm b/guix/lint.scm index 4a6abe4275..ec43a4dcad 100644 --- a/guix/lint.scm +++ b/guix/lint.scm @@ -1355,12 +1355,20 @@ them for PACKAGE." "Check the formatting of the source code of PACKAGE." (let ((location (package-location package))) (if location - (and=> (search-path %load-path (location-file location)) - (lambda (file) - ;; Report issues starting from the line before the 'package' - ;; form, which usually contains the 'define' form. - (report-formatting-issues package file - (- (location-line location) 1)))) + ;; Report issues starting from the line before the 'package' + ;; form, which usually contains the 'define' form. + (let ((line (- (location-line location) 1))) + (match (search-path %load-path (location-file location)) + ((? string? file) + (report-formatting-issues package file line)) + (#f + ;; It could be that LOCATION lists a "true" relative file + ;; name--i.e., not relative to an element of %LOAD-PATH. + (let ((file (location-file location))) + (if (file-exists? file) + (report-formatting-issues package file line) + (list (make-warning package + (G_ "source file not found")))))))) '()))) -- cgit v1.2.3