-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||||
from __future__ import division | ||||||||
|
||||||||
from warnings import warn | ||||||||
import os | ||||||||
import re | ||||||||
|
||||||||
from .utils_badge import Badge | ||||||||
|
@@ -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.*") | ||||||||
SOURCE_MATCH = re.compile(r"([^:]+):\d+:\d+:\s+.*") | ||||||||
|
||||||||
|
||||||||
def parse_flake8_stats(stats_txt # type: str | ||||||||
|
@@ -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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 ! |
||||||||
if smatch: | ||||||||
source = smatch.group(1) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if not os.path.exists(source): | ||||||||
warn("Source report line does not refer to file: %r" %line) | ||||||||
else: | ||||||||
# warn on lines that do not match stats or source report. | ||||||||
warn("Line in Flake8 statistics report does not match template and will be ignored: %r" % line) | ||||||||
else: | ||||||||
nb, code = match.groups() | ||||||||
stats.add(int(nb), code) | ||||||||
|
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.
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.
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