qntm / greenery

Regular expression manipulation library
http://qntm.org/greenery
MIT License
311 stars 40 forks source link

lint: fix up strict-ish flake8/pycodestyle formatting #79

Closed rwe closed 1 year ago

rwe commented 1 year ago

NOTE: #80 is based on this branch, and if that merges, this will auto-close.

This consistent-ifies some of the formatting with typical Python styling, incrementally fixing each of the flake8/pycodestyle warnings until none are left, passing with "all rules on". (The one remaining suppression of W503 is disabled-by-default and is required to be disabled for subsequent black autoformatting).

This is a lead-in to https://github.com/qntm/greenery/compare/main...rwe:greenery:black which builds on this to introduce fully-automated formatting and https://github.com/qntm/greenery/compare/main...rwe:greenery:pylint which introduces stricter pylint linting.

With one small exception, this PR touches only formatting and not logic, structure, or names. The small exception is this change:

- f"Could not parse '{string}' beyond index {str(i)}"
+ f"Could not parse {string!r} beyond index {i}"

which, via the !rrepr format specifier, now escapes strings as 'foo\nbar' for a string containing a newline, versus previously including such characters in the message literally.

rwe commented 1 year ago

Man these package versions need pinning:

ValueError: Error code '#' supplied to 'ignore' option does not match '^[A-Z]{1,3}[0-9]{0,3}$'

No error for me on flake8 5.0.4 but who knows what CI's running…I'll fix.

rwe commented 1 year ago

And by "who knows" I mean it's right there in the logs as 6.0.0.

qntm commented 1 year ago

Why do flake8 and black disagree about where line breaks should be relative to binary operators? Since they are in conflict, why are we using both of them at once? Shouldn't we just use one or the other?

rwe commented 1 year ago

Why do flake8 and black disagree about where line breaks should be relative to binary operators?

There are two things here:

Those two suppressions are described here: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#configuration

Since they are in conflict, why are we using both of them at once? Shouldn't we just use one or the other?

black is an auto-formatter (in the vein of prettier) and flake8 is a linter (in the vein, maybe, of ~eslint) which includes rules about formatting. The formatting rules of flake8, which actually come from pycodestyle, are mostly redundant with black, but: