addon-check icon indicating copy to clipboard operation
addon-check copied to clipboard

Add check for print statement

Open mzfr opened this issue 6 years ago • 12 comments

Fixes #19

mzfr avatar Dec 10 '18 18:12 mzfr

@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

mzfr avatar Jan 19 '19 08:01 mzfr

The following isn't detected.

def printThat(that):
    print(that)

Rechi avatar Jan 21 '19 12:01 Rechi

if True: print('ABC') isn't detected.

Rechi avatar Jan 22 '19 12:01 Rechi

@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

mzfr avatar Feb 13 '19 14:02 mzfr

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 avatar Feb 13 '19 15:02 Rechi

@Rechi I did try with AST but again that didn't covered all the cases

mzfr avatar Feb 13 '19 18:02 mzfr

@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.

mzfr avatar Mar 22 '19 08:03 mzfr

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 avatar Aug 06 '19 09:08 Rechi

@Rechi agreed. Also not for any file containing test or within a test folder.

enen92 avatar Aug 06 '19 10:08 enen92

Yes test should be ignored too, but not explicit by this check. handle_files.create_file_index shouldn't return test files.

Rechi avatar Aug 06 '19 16:08 Rechi

@Rechi Why are we ignoring the test files? I mean the @MartijnKaijser comment about people using print statement in unit test make sense.

mzfr avatar Aug 23 '19 06:08 mzfr

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.

Rechi avatar Aug 24 '19 07:08 Rechi