https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90118

--- Comment #8 from Roland Illig <roland.illig at gmx dot de> ---
(In reply to Christophe Lyon from comment #7)
> Do you mean something like that?
>
>                      if p.startswith('-'):
>                          if len(p) >= 2 and (p[1].isalpha() and p != '-INF'):
> -                            print('%s: %s' % (origin, text))
> +                            reason = 'Illegal string after "-"'
> +                            print('%s: %s: %s' % (origin, reason, text))

Almost. The guidelines recommend to say _why_ something is wrong. It could also
be more specific by additionally providing the information that this diagnostic
is meant to match command line arguments.

In my current local version of the linter, the code is:

        if part.startswith('-'):
            if len(part) >= 2 and part[1].isalpha() and part != '-INF':
                warn(msg, 'command line option outside %<quotes%>')

>                      elif p.startswith('__builtin_'):
> -                        print('%s: %s' % (origin, text))
> +                        reason = 'Starts with _builtin_'
> +                        print('%s: %s: %s' % (origin, reason, text))

And why is that bad? I chose the following diagnostic:

        elif part.startswith('__builtin_'):
            warn(msg, 'builtin function outside %<quotes%>')

>                      if re.search("[^%]'", p):
> -                        print('%s: %s' % (origin, text))
> +                        reason = 'Illegal single quote'
> +                        print('%s: %s: %s' % (origin, reason, text))

    if re.search("[^%]'", msgid):
        warn(msg, 'apostrophe without leading %')

>                      # %< should not be preceded by a non-punctuation
>                      # %character.
>                      if re.search("[a-zA-Z0-9]%<", p):
> -                        print('%s: %s' % (origin, text))
> +                        reason = 'Illegal character before %<'
> +                        print('%s: %s: %s' % (origin, reason, text))

    # from bug 90118: Missing space between words
    if re.search("[a-zA-Z0-9]%<", msgid):
        warn(msg, '%< directly following a letter or digit')

See bug 90119 and bug 90176 for my versions of the linter from today's
afternoon. I've added some more changes since then.

Of course it would be even nicer if the linter would also offer an explanation,
like I did in https://github.com/rillig/pkglint, or like the MIPSPro compiler
has with its separate explain(1) utility. That could be the next step.

Reply via email to