--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityChecker.py Sat Apr 03 15:09:56 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityChecker.py Sat Apr 03 16:02:33 2021 +0200 @@ -7,8 +7,7 @@ Module implementing the security checker. """ -import sys -import ast +import copy import collections from . import Checks @@ -94,13 +93,10 @@ # hardcoded AWS passwords "S801", "S802", - - # Syntax error - "S999", ] - def __init__(self, source, filename, select, ignore, expected, repeat, - args): + def __init__(self, source, filename, tree, select, ignore, expected, + repeat, args): """ Constructor @@ -108,6 +104,8 @@ @type list of str @param filename name of the source file @type str + @param tree AST tree of the source code + @type ast.Module @param select list of selected codes @type list of str @param ignore list of codes to be ignored @@ -125,6 +123,7 @@ self.__repeat = repeat self.__filename = filename self.__source = source[:] + self.__tree = copy.deepcopy(tree) self.__args = args # statistics counters @@ -198,33 +197,6 @@ "confidence": confidence, }) - def __reportInvalidSyntax(self): - """ - Private method to report a syntax error. - """ - exc_type, exc = sys.exc_info()[:2] - if len(exc.args) > 1: - offset = exc.args[1] - if len(offset) > 2: - offset = offset[1:3] - else: - offset = (1, 0) - self.reportError(offset[0] - 1, - offset[1] or 0, - 'S999', - "H", - "H", - exc_type.__name__, exc.args[0]) - - def __generateTree(self): - """ - Private method to generate an AST for our source. - - @return generated AST - @rtype ast.AST - """ - return ast.parse("".join(self.__source), self.__filename) - def getConfig(self): """ Public method to get the configuration dictionary. @@ -247,12 +219,6 @@ # don't do anything, if no codes were selected return - try: - self.__tree = self.__generateTree() - except (SyntaxError, TypeError): - self.__reportInvalidSyntax() - return - securityNodeVisitor = SecurityNodeVisitor( self, self.__checkers, self.__filename) securityNodeVisitor.generic_visit(self.__tree)