guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#35790] [PATCH] scripts: lint: Handle warnings with a record type.


From: Christopher Baines
Subject: [bug#35790] [PATCH] scripts: lint: Handle warnings with a record type.
Date: Sat, 01 Jun 2019 20:09:02 +0100
User-agent: mu4e 1.2.0; emacs 26.2

Ludovic Courtès <address@hidden> writes:

> Hello!
>
> Christopher Baines <address@hidden> skribis:
>
>> Rather than emiting warnings directly to a port, have the checkers return the
>> warning or warnings.
>>
>> This makes it easier to use the warnings in different ways, for example,
>> loading the data in to a database, as you can work with the <lint-warning>
>> records directly, rather than having to parse the output to determine the
>> package and location.
>
> Yay!
>
>> +            <lint-warning>
>
> As a rule of thumb, it’s best to not export the record type descriptor
> (RTD) because then anything could happen.  In this case, I think the
> tests would be just as readable if we used ‘lint-warning-message’ &
> co. instead of matching on the record.
>
> WDYT?

Interesting. I've now adjusted the tests accordingly and sent an updated
patch.

I've stuck with using match, as this gives much better error messages
than using car, or lint-warning-message without checking the thing your
working with is actually a list with a single warning. I've wrapped this
up as a single-lint-warning-message that many of the tests use.

>> +(define* (make-warning package message
>> +                       #:key field location)
>> +  (make-lint-warning
>> +   package
>> +   message
>
> In practice MESSAGE is already translated.  I think it would be more
> flexible if it were not; ‘lint-warning-message’ would always return the
> English message, and it’d be up to the user to call ‘gettext’ on it,
> like we do for package descriptions.
>
> To achieve this, you’d need a little trick so that ‘xgettext’ can still
> extract the messages, like:
>
>
>   (define-syntax-rule make-warning
>     (syntax-rule (G_)
>       ((_ package (G_ message) rest ...)
>        (%make-warning package message rest ...))))
>
> where ‘%make-warning’ is the procedure you define above.
>
> Then you need an explicit call to ‘G_’ at the point where messages are
> displayed.
>
> Does that make sense?

Yes, but I'm unsure it'll work for all the messages.

Some of them it translates a format string first, then uses that format
string, and that becomes the message, e.g.

  (format #f (G_ "invalid description: ~s") description)

Given that you'd be trying to get the translation for "invalid
description: guile" for example, I'm not sure you can defer the
translation without also defering customising the message, if that makes
sense?

I haven't actually tried this yet, so I could be wrong.

>> +(define (append-warnings . args)
>> +  (fold (lambda (arg warnings)
>> +          (cond
>> +           ((list? arg)
>> +            (append warnings
>> +                    (filter lint-warning?
>> +                            arg)))
>> +           ((lint-warning? arg)
>> +            (append warnings
>> +                    (list arg)))
>> +           (else warnings)))
>> +        '()
>> +        args))
>
> I always feel that we should have procedures that operate on lists of
> anything, like ‘append’, and thus ‘append-warnings’ looks like an
> anti-pattern to me.
>
> What about simply ensuring that every checker returns a list of
> <lint-warning>s?  That way, we wouldn’t have to do such things, I think.

I did consider that initially, but it involved restructuring the code
even more, so I put it off. In this latest patch though, I have adjusted
it so all the checkers return lists of warnings.

Thanks for taking a look :)

Chris

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]