Skip to content
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

Add support for warnings #18

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ class Pyflakes(PythonLinter):
defaults = {
'selector': 'source.python'
}
warning_msg_regex = r'''(?x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warning_msg_regex = r'''(?x)
warning_msg_regex = r'''(?x)
warning_msg_regex = re.compile(r'''(?x)

We want to compile exactly once because the regex is static. Doing so in __init__ would still compile per linter run. You can do this either here as a class member or just in the global scope. Anyway, after that overriding __init__ should not be needed anymore.

\b(?:
used|
unused|
redefines|
shadowed|
(may\sbe)
)\b
'''

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.warning_msg_regex = re.compile(self.warning_msg_regex, 0)

def split_match(self, match):
# mark properly the type error message
Copy link
Contributor

@kaste kaste Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment as it's clear what we're doing here. The comment is also not a sentence. 😁


error = super().split_match(match)
if self.warning_msg_regex.search(error['message']):
error['error_type'] = 'warning'
else:
error['error_type'] = 'error'

return error

def reposition_match(self, line, col, match, vv):
if 'imported but unused' in match.message:
Expand Down