From patchwork Sun May 5 17:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 64103 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8F0B927BBEC; Sun, 5 May 2024 18:27:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2EE9127BBE2 for ; Sun, 5 May 2024 18:27:07 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3fdN-0002xf-FO; Sun, 05 May 2024 13:26:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3fdL-0002x2-JB for guix-patches@gnu.org; Sun, 05 May 2024 13:26:43 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s3fdK-0001Yb-2R; Sun, 05 May 2024 13:26:43 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s3fde-00023b-N0; Sun, 05 May 2024 13:27:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70499] [PATCH v2 3/3] scripts: lint: Add 'whole-file' option with ordering lint. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, pelzflorian@pelzflorian.de, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 05 May 2024 17:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70499 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70499@debbugs.gnu.org Cc: Christopher Baines , Florian Pelz , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Florian Pelz , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70499-submit@debbugs.gnu.org id=B70499.17149299907879 (code B ref 70499); Sun, 05 May 2024 17:27:02 +0000 Received: (at 70499) by debbugs.gnu.org; 5 May 2024 17:26:30 +0000 Received: from localhost ([127.0.0.1]:60855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s3fd7-000230-Cn for submit@debbugs.gnu.org; Sun, 05 May 2024 13:26:29 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:43969 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s3fd3-00022P-TS for 70499@debbugs.gnu.org; Sun, 05 May 2024 13:26:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1714929949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Cr+L6bHUg0hBNqUqvAQB0GNpLBHU88ZIpSxYo5LK0I=; b=WRNy/rjTLR9b+VpRz5EEKbIneElq3vKjZZ9ao49Wr5ZnH44iuUvfKsvJ+K0aIwUOMpVrqi 8L/9vtOFyzDkbpp9Yhhl5G6QF9TUbtrcLd3r9irfCar6Tu103NdexhbcAQzr/spugBMRIG DQLRtI53AprRiCwIa1JXw/8fCCF6XUBpDSkiOJXybz2GT1cZfOg586ETTnTDR+ZPQL8A2l qV7XKLl2q1P5d2y8pOc9YY78t5qjbDEB4uw24352jfDSWUmUdT/Dx2lDtQ7YyYfOkrZYVN 20U/mdPe5Tt8q4qKDsBhUuLqYbbXGoyZ/Tj1Z2m0ygcTziqid5ccdbfWIpAiyA== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id bf9f10c3 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for <70499@debbugs.gnu.org>; Sun, 5 May 2024 17:25:49 +0000 (UTC) Date: Sun, 5 May 2024 19:25:35 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/lint.scm (show-help): Describe option. (%options): Add 'whole-file' option. (guix-lint): Lint (order of) packages in files. * doc/guix.texi (Invoking guix lint): Document option. Change-Id: I52b48a9a6982d0c4a03416e3d070887c64716485 --- doc/guix.texi | 23 ++++++++++++++++-- guix/scripts/lint.scm | 55 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1c1e0164e7..c68b62d475 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -15349,6 +15349,12 @@ Invoking guix lint @end example If no package is given on the command line, then all packages are checked. +To lint entire source files, the syntax is: + +@example +guix lint @var{options} --whole-file @var{file}@dots{} +@end example + The @var{options} may be zero or more of the following: @table @code @@ -15386,9 +15392,22 @@ Invoking guix lint Add @var{directory} to the front of the package module search path (@pxref{Package Modules}). -This allows users to define their own packages and make them visible to -the command-line tools. +@item --whole-file +@itemx -f +Lint the given files in their entirety. In that case, subsequent +arguments are interpreted as file names (rather than package names). +Also, an additional checker is enabled, which checks if a package +alphabetically succeeds the one above it. + +As an example, here is how you might quickly check if packages are in +alphabetical order: + +@example +guix lint -c name -f gnu/packages/matrix.scm +@end example +The previous two options allow users to define their own packages and +make them visible to the command-line tools. @end table @node Invoking guix size 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 ;;; Copyright © 2019, 2020 Simon Tournier ;;; Copyright © 2020 Brice Waegeneire +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; @@ -28,8 +29,10 @@ ;;; along with GNU Guix. If not, see . (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 @@ (define (show-help) -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 @@ (define %options (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 @@ (define-command (guix-lint . args) #: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 @@ (define-command (guix-lint . args) (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