-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flake8 Template Change to Reduce Warnings #21
base: main
Are you sure you want to change the base?
Conversation
Also ignore lines that are source file reports.
Fewer Warnings for Flake 8
@@ -104,7 +105,8 @@ def get_flake8_stats(flake8_stats_file): | |||
return parse_flake8_stats(flake8_stats_txt) | |||
|
|||
|
|||
RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+)\s.*") | |||
RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+):*\s.*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+):*\s.*") | |
# Note: the optional colon `:*` is to comply with some flake8 plugins, see PR #21 | |
RE_TO_MATCH = re.compile(r"([0-9]+)\s+([A-Z0-9]+):*\s.*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing this @smarie. I don't see why the very small patch related to the colon shouldn't be merged.
To be certain that this different format was the exception rather than some new format, I just did a quick review of the three plugins I found that have the colon:
flake8-comments 0.1.2 Was last updated 5 months ago, no comments or PRs.
flake8-type-annotations 0.4.0 Is active with a few comments and PRs.
To my surprise:
flake8-type-annotations 0.1.0 Is actually DEPRECATED, because the functionality was merged into flake8 under different rules, so I will stop using this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why the very small patch related to the colon shouldn't be merged.
It should ! The suggestion I made is about adding a comment above the line. For some reason github does not highlight the diff correctly.
Thanks for investigating this list of colon-creating plugins
Thanks a lot @rnickle for this submission (and for the kind words) ! I made a few minor suggestions. It would be great if you could add a test with an example such flake8 --output file. That would illustrate the lines and format you're referring to. I am wondering if the lines matching the source format should be ignored or should actually be parsed too. Indeed, the example you show above |
@@ -115,7 +117,14 @@ def parse_flake8_stats(stats_txt # type: str | |||
for line in stats_txt.splitlines(): | |||
match = RE_TO_MATCH.match(line) | |||
if not match: | |||
warn("Line in Flake8 statistics report does not match template and will be ignored: %r" % line) | |||
smatch = SOURCE_MATCH.match(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smatch = SOURCE_MATCH.match(line) | |
# Other supported lines formats ? | |
smatch = SOURCE_MATCH.match(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you @smarie, I did not realize that it wasn't being caught because I did not audit and verify the counts.
I have quite a few warnings from several flake8 plugins. I can organize the ones you don't already have into tests/reports/flake8/flake8stats.txt and cross-check the counts. I will report back on my findings, and if I introduce any changes to the code I will provide tests.
It seems to me that I should also provide tests for the ":" cases, so I will try testing against that also. I will try to turn this around over the next few days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great @rnickle ! My guess is that with one or two additional test files it should cover most of the variants, but I let you find investigate. Let me know !
@@ -115,7 +117,14 @@ def parse_flake8_stats(stats_txt # type: str | |||
for line in stats_txt.splitlines(): | |||
match = RE_TO_MATCH.match(line) | |||
if not match: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that there are several cases, it would probably be preferable to first handle the "match" (reverting the if). That would put the nominal case upfront.
Each case could start with a comment illustrating the kind of pattern.
For the nominal one for example # Nominal case, such as: "N400: Found backslash that is used for line breaking"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pardon me for the delay, I looked into it a little, and just had a chance to go back. I was concerned about a variety of things, including exactly how find_severity worked. I added my flake8stats.txt and modified the tests to make sure they could pass with it.
warn("Line in Flake8 statistics report does not match template and will be ignored: %r" % line) | ||
smatch = SOURCE_MATCH.match(line) | ||
if smatch: | ||
source = smatch.group(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source = smatch.group(1) | |
# Line with source file, such as "directory/sourcefile.py:139:33: Q000 Single quotes found but double quotes preferred" | |
source = smatch.group(1) |
Adding a very large selection of flake8 results from a project that had never been refactored. The following flake8 plugins were enabled: flake8-aaa flake8-blind-except flake8-broken-line flake8-builtins flake8-class-attributes-order flake8-commas flake8-comments flake8-comprehensions flake8-docstrings flake8-dunder-all flake8-expression-complexity flake8-html flake8-if-expr flake8-import-order flake8-logging-format flake8-module-imports flake8-module-name flake8-pep3101 flake8-plugin-utils flake8-polyfill flake8-quotes flake8-raise flake8-rst-docstrings flake8-secure-coding-standard flake8-simplify flake8-string-format flake8-tuple flake8-type-annotations flake8-typehinting flake8-typing-imports pep8-naming
Thank you for this excellent tool, which I am using on several projects.
When I run genbadge for flake8, I notice two things:
Thank you for considering this pull request, and please let me know if I can improve the submission.