Trying to improve the flake8 parser in bbresults

32 views
Skip to first unread message

Johan Larsson

unread,
Oct 7, 2021, 4:14:54 PM10/7/21
to BBEdit Talk
I have just discovered the utility bbresults thanks to Patrick at Bare Bones. As the manual page suggests, using it as processor of flake8 output is really useful. One little drawback of the current built-in parser is that the actual ID of an error or warning is consumed by the built-in flake8 regular expression. So why do I see this as a drawback? Depending on your coding style, preferences and/or the problem the code is trying to solve, you may want to prohibit flake8 from pointing out certain errors or violations.

Bild 2021-10-03 kl. 21.19.jpg

So I tried to improve the built-in regular expression as documented in the man page.

Not being an regex expert myself, I failed to include the warning or error ID in the type group and somehow tack it on later for the msg part… Here is my go at it, which only slightly improves the situation by including the numerical part of the ID in the msg.

'(?P<file>.+?):(?P<line>\d+):(?P<col>\d+):\s+(?P<type>[EWF](?=\d+))(?P<msg>.*)$'

Bild 2021-10-03 kl. 21.32.jpg

It’s far from ideal, but at least you know that if a violation is an Error, you stick an ’E’ in front of the numerical ID to get the complete code, ’W’ for a warning, and most likely an ’F’ for a note.

Another option is of course to fall back to using the default parser in bbresults, but the resulting output is a bit bleak as all entries are now notes:

Bild 2021-10-03 kl. 21.39.jpg

Anyone out there with a better idea?

Best regards,
Johan

jj

unread,
Oct 8, 2021, 4:24:20 AM10/8/21
to BBEdit Talk
Hi Johan,

You could try this:

flake8 foobar.py | sed -E 's/([FEW][0-9]+)/\1 \1:/g' | bbresults --pattern flake8

Piping through sed will repeat the 'type' twice so it appears at the start of the message.

HTH

Jean Jourdain

Johan Larsson

unread,
Oct 9, 2021, 2:42:31 PM10/9/21
to BBEdit Talk

That's truly clever! Good old sed to the rescue.

Many thanks,
Johan
Reply all
Reply to author
Forward
0 new messages