diff options
Diffstat (limited to 'guix/scripts/lint.scm')
-rw-r--r-- | guix/scripts/lint.scm | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm index ee3de51fb1..86ff5cf1c0 100644 --- a/guix/scripts/lint.scm +++ b/guix/scripts/lint.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net> ;;; Copyright © 2019, 2020 Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> +;;; Copyright © 2024 Herman Rimm <herman@rimm.ee> ;;; ;;; This file is part of GNU Guix. ;;; @@ -28,8 +29,10 @@ ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. (define-module (guix scripts lint) + #:use-module (guix diagnostics) #:use-module (guix packages) #:use-module (guix lint) + #:use-module (guix modules) #:use-module (guix ui) #:use-module (guix store) #:use-module (guix scripts) @@ -115,6 +118,9 @@ run the checkers on all packages.\n")) -L, --load-path=DIR prepend DIR to the package module search path")) (newline) (display (G_ " + -f, --whole-file lint the entire contents of the given file(s)")) + (newline) + (display (G_ " -h, --help display this help and exit")) (display (G_ " -l, --list-checkers display the list of available lint checkers")) @@ -161,6 +167,9 @@ run the checkers on all packages.\n")) (lambda args (leave-on-EPIPE (show-help)) (exit 0))) + (option '(#\f "whole-file") #f #f + (lambda (opt name arg result) + (alist-cons 'whole-file? #t result))) (option '(#\l "list-checkers") #f #f (lambda (opt name arg result) (alist-cons 'list? #t result))) @@ -187,12 +196,17 @@ run the checkers on all packages.\n")) #:build-options? #f)) (let* ((opts (parse-options)) - (args (filter-map (match-lambda - (('argument . spec) - (specification->package spec)) - (('expression . exp) - (read/eval-package-expression exp)) - (_ #f)) + (whole-file? (assoc-ref opts 'whole-file?)) + (args (filter-map (if whole-file? + (match-lambda + (('argument . file) file) + (_ #f)) + (match-lambda + (('argument . spec) + (specification->package spec)) + (('expression . exp) + (read/eval-package-expression exp)) + (_ #f))) (reverse opts))) (no-checkers (or (assoc-ref opts 'exclude) '())) (the-checkers (filter (lambda (checker) @@ -221,6 +235,35 @@ run the checkers on all packages.\n")) (call-maybe-with-store (lambda (store) (cond + (whole-file? + (when (null? args) + (warning (G_ "no files specified, nothing to do~%"))) + (for-each + (lambda (file) + (load* file) + (let* ((module (resolve-interface + (file-name->module-name file))) + (packages (sort (fold-packages cons '() + (list module)) + package-location<?))) + (fold (lambda (package previous) + (let ((line (location-line + (package-location package))) + (text "breaks from alphabetical order") + (name (package-name package))) + (run-checkers package checkers + #:store store) + (and (string< name previous) + (emit-warnings + (list (lint-warning + (package package) + (location + (location file line 0)) + (message-text (G_ text)) + (message-data '()))))) + name)) + "" packages))) + args)) ((null? args) (fold-packages (lambda (p r) (run-checkers p checkers #:store store)) '())) |