--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Sat Apr 03 15:09:56 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Sat Apr 03 16:02:33 2021 +0200 @@ -279,15 +279,16 @@ @type str @param source string containing the code to check @type str - @return tuple containing the error dictionary with syntax error details - and a statistics dictionary or a tuple containing two None - @rtype tuple of (dict, dict) or tuple of (None, None) + @return tuple containing the error dictionary with syntax error details, + a statistics dictionary and None or a tuple containing two None and + the generated AST tree + @rtype tuple of (dict, dict, None) or tuple of (None, None, ast.Module) """ src = "".join(source) try: - ast.parse(src, filename, 'exec') - return None, None + tree = ast.parse(src, filename, 'exec') + return None, None, tree except (SyntaxError, TypeError): exc_type, exc = sys.exc_info()[:2] if len(exc.args) > 1: @@ -304,7 +305,8 @@ "args": [exc_type.__name__, exc.args[0]], }, { "E901": 1, - }) + }, + None) def __checkCodeStyle(filename, source, args): @@ -367,13 +369,10 @@ else: ignore = [] - syntaxError, syntaxStats = __checkSyntax(filename, source) - if syntaxError: - errors = [syntaxError] - stats.update(syntaxStats) + syntaxError, syntaxStats, tree = __checkSyntax(filename, source) - # perform the checks only, if syntax is ok - else: + # perform the checks only, if syntax is ok and AST tree was generated + if tree: # check coding style pycodestyle.BLANK_LINES_CONFIG = { # Top level class and function. @@ -404,7 +403,7 @@ # miscellaneous additional checks miscellaneousChecker = MiscellaneousChecker( - source, filename, select, ignore, [], repeatMessages, + source, filename, tree, select, ignore, [], repeatMessages, miscellaneousArgs) miscellaneousChecker.run() stats.update(miscellaneousChecker.counters) @@ -412,7 +411,7 @@ # check code complexity complexityChecker = ComplexityChecker( - source, filename, select, ignore, codeComplexityArgs) + source, filename, tree, select, ignore, codeComplexityArgs) complexityChecker.run() stats.update(complexityChecker.counters) errors += complexityChecker.errors @@ -422,7 +421,7 @@ # annotations are supported from Python 3.5 on from Annotations.AnnotationsChecker import AnnotationsChecker annotationsChecker = AnnotationsChecker( - source, filename, select, ignore, [], repeatMessages, + source, filename, tree, select, ignore, [], repeatMessages, annotationArgs) annotationsChecker.run() stats.update(annotationsChecker.counters) @@ -430,7 +429,7 @@ # check for security issues securityChecker = SecurityChecker( - source, filename, select, ignore, [], repeatMessages, + source, filename, tree, select, ignore, [], repeatMessages, securityArgs) securityChecker.run() stats.update(securityChecker.counters) @@ -438,17 +437,21 @@ # check for pathlib usage pathlibChecker = PathlibChecker( - source, filename, select, ignore, [], repeatMessages) + source, filename, tree, select, ignore, [], repeatMessages) pathlibChecker.run() stats.update(pathlibChecker.counters) errors += pathlibChecker.errors # check for code simplifications simplifyChecker = SimplifyChecker( - source, filename, select, ignore, [], repeatMessages) + source, filename, tree, select, ignore, [], repeatMessages) simplifyChecker.run() stats.update(simplifyChecker.counters) errors += simplifyChecker.errors + + elif syntaxError: + errors = [syntaxError] + stats.update(syntaxStats) errorsDict = {} for error in errors: