addon-check
addon-check copied to clipboard
Add check for print statement
Fixes #19
@Rechi I have used regex to find the print statement and I have tested this with the following content in a file.
"""
This is docstings and here is the print("testing")
"""
print("testing separately")
someclasss.print("with some function") # comment with print("in a comment")
# comment with print("in a comment separately")
and the output was print("testing separately") only
The following isn't detected.
def printThat(that):
print(that)
if True: print('ABC') isn't detected.
@Rechi That would just make it's difficult to catch because if I remove the ^ from the regex pattern then it would start counting all the print statements including the comments etc
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.
IMO print statements shouldn't be reported for script.module add-ons, as most of those are not specifically coded for Kodi.
@enen92 @Razzeee what's your opinion?
@Rechi agreed. Also not for any file containing test or within a test folder.
Yes test should be ignored too, but not explicit by this check. handle_files.create_file_index shouldn't return test files.
@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 xbmc.log(...), because they aren't from inside Kodi. If tests aren't ignored you could get lot of print used reports for those.