Sun, 02 Mar 2025 16:59:50 +0100
Corrected the usage of the 'pycodestyle' checker.
src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py | file | annotate | diff | comparison | revisions |
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Sat Mar 01 17:31:44 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Sun Mar 02 16:59:50 2025 +0100 @@ -54,7 +54,7 @@ class CodeStyleCheckerReport(pycodestyle.BaseReport): """ - Class implementing a special report to be used with our dialog. + Class implementing a special 'pycodestyle' report to be used with our checker. """ def __init__(self, options): @@ -87,9 +87,10 @@ @rtype str """ code = text.split(None, 1)[0] + if self._ignore_code(code): + return None + errorCode = code[0] + "-" + code[1:] - if self._ignore_code(errorCode): - return None if errorCode in self.counters: self.counters[errorCode] += 1 @@ -449,13 +450,13 @@ if not errors: if includeMessages: - select = [s.strip() for s in includeMessages.split(",") if s.strip()] + selected = [s.strip() for s in includeMessages.split(",") if s.strip()] else: - select = [] + selected = [] if excludeMessages: - ignore = [i.strip() for i in excludeMessages.split(",") if i.strip()] + ignored = [i.strip() for i in excludeMessages.split(",") if i.strip()] else: - ignore = [] + ignored = [] syntaxError, syntaxStats, tree = __checkSyntax(filename, source) @@ -468,33 +469,42 @@ enabledCategories.add(category) # check coding style - pycodestyle.BLANK_LINES_CONFIG = { - # Top level class and function. - "top_level": blankLines[0], - # Methods and nested class and function. - "method": blankLines[1], - } - styleGuide = pycodestyle.StyleGuide( - reporter=CodeStyleCheckerReport, - repeat=repeatMessages, - select=[], - ignore=[x for x in ignore if x.startswith(("E", "W"))], - max_line_length=maxLineLength, - max_doc_length=maxDocLineLength, - hang_closing=hangClosing, - ) - report = styleGuide.options.report - styleGuide.input_file(filename, lines=source) - stats.update(report.counters) - errors += report.errors + if "E" in enabledCategories or "W" in enabledCategories: + pycodestyle.BLANK_LINES_CONFIG = { + # Top level class and function. + "top_level": blankLines[0], + # Methods and nested class and function. + "method": blankLines[1], + } + styleGuide = pycodestyle.StyleGuide( + reporter=CodeStyleCheckerReport, + repeat=repeatMessages, + select=[ + x.replace("-", "", 1) # change to pycodestyle error codes + for x in selected + if x.startswith(("E-", "W-")) + ], + ignore=[ + x.replace("-", "", 1) # change to pycodestyle error codes + for x in ignored + if x.startswith(("E-", "W-")) + ], + max_line_length=maxLineLength, + max_doc_length=maxDocLineLength, + hang_closing=hangClosing, + ) + report = styleGuide.options.report + styleGuide.input_file(filename, lines=source) + stats.update(report.counters) + errors += report.errors # check documentation style if DocStyleChecker.Category in enabledCategories: docStyleChecker = DocStyleChecker( source, filename, - select, - ignore, + selected, + ignored, [], repeatMessages, maxLineLength=maxDocLineLength, @@ -510,8 +520,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, miscellaneousArgs, @@ -523,7 +533,7 @@ # check code complexity if ComplexityChecker.Category in enabledCategories: complexityChecker = ComplexityChecker( - source, filename, tree, select, ignore, codeComplexityArgs + source, filename, tree, selected, ignored, codeComplexityArgs ) complexityChecker.run() stats.update(complexityChecker.counters) @@ -535,8 +545,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, annotationArgs, @@ -551,8 +561,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, securityArgs, @@ -564,7 +574,7 @@ # check for pathlib usage if PathlibChecker.Category in enabledCategories: pathlibChecker = PathlibChecker( - source, filename, tree, select, ignore, [], repeatMessages + source, filename, tree, selected, ignored, [], repeatMessages ) pathlibChecker.run() stats.update(pathlibChecker.counters) @@ -573,7 +583,7 @@ # check for code simplifications if SimplifyChecker.Category in enabledCategories: simplifyChecker = SimplifyChecker( - source, filename, tree, select, ignore, [], repeatMessages + source, filename, tree, selected, ignored, [], repeatMessages ) simplifyChecker.run() stats.update(simplifyChecker.counters) @@ -585,8 +595,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, importsArgs, @@ -601,8 +611,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, {}, # no arguments yet @@ -617,8 +627,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, nameOrderArgs, @@ -633,8 +643,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, unusedArgs, @@ -649,8 +659,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, {}, # no arguments yet @@ -665,8 +675,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, {}, # no arguments yet @@ -681,8 +691,8 @@ source, filename, tree, - select, - ignore, + selected, + ignored, [], repeatMessages, {}, # no arguments yet