Subject: [bug#71697] [PATCH v5 3/3] scripts: lint: Add hint for checker typo.

From: Maxim Cournoyer <[email-masked]>
Date: Fri, 26 Jul 2024 11:26:42 +0900

Hi,

Simon Tournier <[email-masked]> writes:

>
> Change-Id: I432c5b0570d2f413b59c2296666f3a4e5fb8c64c
> ---
>  guix/scripts/lint.scm | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
> index 2df0cba948..f4aa394686 100644
> --- a/guix/scripts/lint.scm
> +++ b/guix/scripts/lint.scm
> @@ -31,6 +31,7 @@ (define-module (guix scripts lint)
>    #:use-module (guix packages)
>    #:use-module (guix lint)
>    #:use-module (guix ui)
> +  #:use-module ((guix utils) #:select (string-closest))
>    #:use-module (guix store)
>    #:use-module (guix scripts)
>    #:use-module (guix scripts build)
> @@ -147,7 +148,15 @@ (define (option-checker short-long)
>                                                   ((short long) long)))))
>                (for-each (lambda (c)
>                            (unless (memq c checker-names)
> -                            (leave (G_ "~a: invalid checker~%") c)))
> +                            (let* ((name (symbol->string c))
> +                                   (checkers (map symbol->string checker-names))
> +                                   (hint (string-closest name checkers
> +                                                         #:threshold 3)))
> +                              (report-error (G_ "~a: invalid checker~%") name)
> +                              (when hint
> +                                (display-hint
> +                                 (format #f (G_ "Did you mean @code{~a}?~%") hint)))
> +                              (exit 1))))
>                          names)
>                (alist-cons option-name
>                            (filter (lambda (checker)

Patch 1 and 3 LGTM.  Patch 2 I'd rather wait to see if we can think
about a better option to match the original use case (exclude the
archival checker from 'guix lint' for privately developed packages). I
remember that perhaps the simplest thing for that would be to add a
nonfree license to (guix licenses); Guix users developing nonfree
software (ugh) could mark it as such and the lint code could disable
archival for such licensed packages (or maybe more generally if the
license used is unknown to Guix).

-- 
Thanks,
Maxim