[libvirt] [PATCH 01/11] cfg.mk: fix comment detection for python semicolon check

Daniel P. Berrangé berrange at redhat.com
Thu Sep 5 14:05:59 UTC 2019


On Thu, Sep 05, 2019 at 08:57:43AM -0500, Eric Blake wrote:
> On 9/5/19 5:21 AM, Daniel P. Berrangé wrote:
> > The pattern
> > 
> >     ^[^#].*\;$$
> > 
> > Was attempting to detect any trailing ';' in python code
> > which was not in a comment. This does not allow for the
> > comment '#' character to be indented with whitespace.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> > ---
> >  cfg.mk | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/cfg.mk b/cfg.mk
> > index 1f29729949..d10dfa16a1 100644
> > --- a/cfg.mk
> > +++ b/cfg.mk
> > @@ -815,7 +815,7 @@ sc_require_enum_last_marker:
> >  
> >  # In Python files we don't want to end lines with a semicolon like in C
> >  sc_prohibit_semicolon_at_eol_in_python:
> > -	@prohibit='^[^#].*\;$$' \
> > +	@prohibit='^[^#]*\;$$' \
> 
> But this new pattern does not prohibit:
> 
>  ch = '#';
> 
> I think you want:
> 
> '^[ \t]*[^#].*\;$$'
> 
> to flag all lines that have any amount of leading whitespace, where the
> first non-whitespace is not #, and which end in ;.

Unfortunately this doesn't work when face with a line

      #  foo();

The '[ \t]*' matches 0 times. '[^#]' matches on the first leading
whitespace character. '.*' then matches '     # foo()'. So we get a
bogus warning.

This does make me realize how to fix it though - we need to force
the '[ \t]*' to always be matched against leading space with:

 '^[ \t]*[^# \t].*\;$$'

This will still give a bogus warning though if the comment is
following after a valid statement eg

    some call  # foo();

Luckily we don't have any examples of this pattern, so I could
leave it to some other sucker to fix when they need that.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list