From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wLU4EEab6WKkEAAAbAwnHQ (envelope-from ) for ; Tue, 02 Aug 2022 23:46:46 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id EF0UEEab6WKjLgEAauVa8A (envelope-from ) for ; Tue, 02 Aug 2022 23:46:46 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D4F328CDA for ; Tue, 2 Aug 2022 23:46:45 +0200 (CEST) Received: from localhost ([::1]:59440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIziu-0002ot-Js for larch@yhetil.org; Tue, 02 Aug 2022 17:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzhK-0001ym-KL for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzhK-0006Qw-AH for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oIzhK-0003AV-6e for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:06 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56898] [PATCH 10/13] style: Add '--whole-file' option. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 02 Aug 2022 21:45:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56898 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56898@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 56898-submit@debbugs.gnu.org id=B56898.165947668612046 (code B ref 56898); Tue, 02 Aug 2022 21:45:06 +0000 Received: (at 56898) by debbugs.gnu.org; 2 Aug 2022 21:44:46 +0000 Received: from localhost ([127.0.0.1]:45299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzh0-000387-41 for submit@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59584) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgs-00035f-PR for 56898@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzgn-0006AK-HY; Tue, 02 Aug 2022 17:44:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=lICy7ikDnNXAQqEhUrt1/u23uLZqJUt02xKAqLjvbzM=; b=om0KsIQ+NylynuGMeQjM M4EZBAnLdQnVhAGo8urCsdlSPaJ0zvwtslruHk2/Q/ZBNR+YzVJBVKgCNE3sN16j+3jsdwr/w0fDT 8fMa7fyf5KF4IsY6HKQhNYe/vHKiJY/8NjV4F4MJg3+oR9OWjrVyPZJEMIZCTJzuA0tOTn0TnKG7j lbtOhRkxwiksgJcHnKaElDCz0O+Ma3BEM3qFZoLR3CQn5rJV5wTDIe2fx88mcDj3AiHchoEtFJ+ma 6zHrh43JFAkiOlqhZ1ebF84QwowrXNiHBuXx4e/yVNSyqW46BX0gpGSRj7zysP1UUyhqY/CJx1y9O HAWZnPoOyqbaNA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:52235 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzgn-0006W4-4d; Tue, 02 Aug 2022 17:44:33 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 2 Aug 2022 23:44:16 +0200 Message-Id: <20220802214419.19013-10-ludo@gnu.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220802214419.19013-1-ludo@gnu.org> References: <20220802214419.19013-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659476806; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=U3JPV1AtVM59b+XMgegnCjsioW6nchad2hUmEIwz+Kc=; b=IuLI6X1AfmKxSSfgbtHdxLygNXnZbQPCWmhq5zxYOIx49+m/5tKajEIMXhtyLMgrYjCi7q IoE+PCqTtJUb9nBQG0NXE2yDjUGAZAqXBCT9EnondH1VTBoVycAU5uwKyf+2Q1WIr5tO/9 8OS6XTR8c3BfhOk9KR2hGIlQbjvNmYO8FwRGyd6nOvJctT8qTxFZp7pIvzZt6pGWcsLfy2 D6BODEC4JjvXW+Y6700FuLj1Wbu+yediTFyFBYB7PIdgRJhIMsp2i8p3FC2J/pVuAOulfT qvR6t5UmXaBqWtEBI+QwUk06VUyXcavFXPdxTxX7zjvBlDunCr/GWA0ZRurHZg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659476806; a=rsa-sha256; cv=none; b=oBsIu68M2EZ72CR1LJLEkjX5/Oepk4hHLtl9AIMkW8+aCnyxFDxdK27lMav/dtnbxOGDtp 3TxhhJhnBwjWHC9wdVlmZhUOYLmXeBWdWL9eD1BVssN1TBtc4pGLNUbLBy0UOunthbri/j 42e4dla1YWo3cW3WP65lMeRlpO+IS/GLL8oz8lcZVHKjcaAjAFUcwRsEwzom443TYbDaMz xD3dZ/j1v0iFsXZ90r1OkF4OJw4oxdjhPa9dpDRKMXdpYRxkYtUzrDnO1C4uK71AHWddBg 3Kdr697tMZBkZwORVeyQCnlhek3ZQdaL/niDsos+Znqxcy/ywLkXDa4qSF6IlA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=om0KsIQ+; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=om0KsIQ+; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: D4F328CDA X-Spam-Score: -3.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: M9y37MOtJGlW * guix/scripts/style.scm (format-whole-file): New procedure. (%options, show-help): Add '--whole-file'. (guix-style): Honor it. * tests/guix-style.sh: New file. * Makefile.am (SH_TESTS): Add it. * doc/guix.texi (Invoking guix style): Document it. --- Makefile.am | 1 + doc/guix.texi | 28 +++++++++++++-- guix/scripts/style.scm | 65 ++++++++++++++++++++++++---------- tests/guix-style.sh | 80 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 21 deletions(-) create mode 100644 tests/guix-style.sh diff --git a/Makefile.am b/Makefile.am index 2cda20e61c..f7c42e8153 100644 --- a/Makefile.am +++ b/Makefile.am @@ -580,6 +580,7 @@ SH_TESTS = \ tests/guix-package.sh \ tests/guix-package-aliases.sh \ tests/guix-package-net.sh \ + tests/guix-style.sh \ tests/guix-system.sh \ tests/guix-home.sh \ tests/guix-archive.sh \ diff --git a/doc/guix.texi b/doc/guix.texi index fc6f477c9a..8dd1e306de 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14058,9 +14058,12 @@ otherwise. @node Invoking guix style @section Invoking @command{guix style} -The @command{guix style} command helps packagers style their package -definitions according to the latest fashionable trends. The command -currently provides the following styling rules: +The @command{guix style} command helps users and packagers alike style +their package definitions and configuration files according to the +latest fashionable trends. It can either reformat whole files, with the +@option{--whole-file} option, or apply specific @dfn{styling rules} to +individual package definitions. The command currently provides the +following styling rules: @itemize @item @@ -14115,6 +14118,12 @@ the packages. The @option{--styling} or @option{-S} option allows you to select the style rule, the default rule being @code{format}---see below. +To reformat entire source files, the syntax is: + +@example +guix style --whole-file @var{file}@dots{} +@end example + The available options are listed below. @table @code @@ -14122,6 +14131,19 @@ The available options are listed below. @itemx -n Show source file locations that would be edited but do not modify them. +@item --whole-file +@itemx -f +Reformat the given files in their entirety. In that case, subsequent +arguments are interpreted as file names (rather than package names), and +the @option{--styling} option has no effect. + +As an example, here is how you might reformat your operating system +configuration (you need write permissions for the file): + +@example +guix style -f /etc/config.scm +@end example + @item --styling=@var{rule} @itemx -S @var{rule} Apply @var{rule}, one of the following styling rules: diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index 2e14bc68fd..c0b9ea1a28 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -328,6 +328,21 @@ (define (package-locationpackage spec)) - (('expression . str) - (read/eval str)) - (_ #f)) - opts)) (edit (if (assoc-ref opts 'dry-run?) edit-expression/dry-run edit-expression)) (style (assoc-ref opts 'styling-procedure)) (policy (assoc-ref opts 'input-simplification-policy))) (with-error-handling - (for-each (lambda (package) - (style package #:policy policy - #:edit-expression edit)) - ;; Sort package by source code location so that we start editing - ;; files from the bottom and going upward. That way, the - ;; 'location' field of records is not invalidated as - ;; we modify files. - (sort (if (null? packages) - (fold-packages cons '() #:select? (const #t)) - packages) - (negate package-locationpackage spec)) + (('expression . str) + (read/eval str)) + (_ #f)) + opts))) + (for-each (lambda (package) + (style package #:policy policy + #:edit-expression edit)) + ;; Sort package by source code location so that we start + ;; editing files from the bottom and going upward. That + ;; way, the 'location' field of records is not + ;; invalidated as we modify files. + (sort (if (null? packages) + (fold-packages cons '() #:select? (const #t)) + packages) + (negate package-location +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Guix is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Guix. If not, see . + +# +# Test 'guix style'. +# + +set -e + +guix style --version + +tmpdir="guix-style-$$" +trap 'rm -r "$tmpdir"' EXIT + +tmpfile="$tmpdir/os.scm" +mkdir "$tmpdir" +cat > "$tmpfile" <