-
Notifications
You must be signed in to change notification settings - Fork 42
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 check for print statement #150
base: master
Are you sure you want to change the base?
Conversation
49820af
to
b8e49e4
Compare
@Rechi I have used regex to find the print statement and I have tested this with the following content in a file.
and the output was |
b8e49e4
to
3b2113a
Compare
The following isn't detected.
|
3b2113a
to
efffedf
Compare
|
@Rechi That would just make it's difficult to catch because if I remove the |
Doing the search for print with reg-ex is the wrong approach. You have to use some parsers which correctly understands the python syntax. |
@Rechi I did try with AST but again that didn't covered all the cases |
@Rechi So I tried again with the ast and I figured it out. So Now it should report any print statement ignoring the docstrings and comments. |
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.
README.md
update is missing.
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.
updating README.md
is missing
kodi_addon_checker/check_files.py
Outdated
if os.path.splitext(file["name"])[1] == '.py': | ||
file = os.path.join(file["path"], file["name"]) | ||
|
||
with open(file, 'r', encoding="utf-8") as f: |
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.
open
may raise a UnicodeDecodeError
.
kodi_addon_checker/check_files.py
Outdated
|
||
if node.value.func.id == "print": | ||
report.add(Record(WARNING, "%s has a print statement on line %s" % | ||
(relative_path(str(file)), node.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.
node.line
is wrong, is may not exist. Correct is node.lineno
.
363fc82
to
57f1800
Compare
@Rechi agreed. Also not for any file containing |
Yes test should be ignored too, but not explicit by this check. |
@Rechi Why are we ignoring the test files? I mean the @MartijnKaijser comment about people using print statement in unit test make sense. |
Your second sentence already answers the question. In unit tests one can't use |
13b1ba9
to
e187c8e
Compare
Fixes #19