Plugins/CheckerPlugins/CodeStyleChecker/MiscellaneousChecker.py

changeset 6178
905ea208884a
parent 6177
af76e795c4ce
child 6180
8d72871c16ba
equal deleted inserted replaced
6177:af76e795c4ce 6178:905ea208884a
614 else: 614 else:
615 errorCode = "M821" 615 errorCode = "M821"
616 self.__error(default.lineno - 1, default.col_offset, 616 self.__error(default.lineno - 1, default.col_offset,
617 errorCode, typeName) 617 errorCode, typeName)
618 618
619 def __dictShouldBeChecked(self, node):
620 """
621 Private function to test, if the node should be checked.
622
623 @param node reference to the AST node
624 @return flag indicating to check the node
625 @rtype bool
626 """
627 if not all(isinstance(key, ast.Str) for key in node.keys):
628 return False
629
630 if "__IGNORE_WARNING__" in self.__source[node.lineno - 1] or \
631 "__IGNORE_WARNING_M201__" in self.__source[node.lineno - 1]:
632 return False
633
634 lineNumbers = [key.lineno for key in node.keys]
635 return len(lineNumbers) == len(set(lineNumbers))
636
619 def __checkDictWithSortedKeys(self): 637 def __checkDictWithSortedKeys(self):
620 """ 638 """
621 Private method to check, if dictionary keys appear in sorted order. 639 Private method to check, if dictionary keys appear in sorted order.
622 """ 640 """
623 for node in ast.walk(self.__tree): 641 for node in ast.walk(self.__tree):
624 if isinstance(node, ast.Dict) and \ 642 if isinstance(node, ast.Dict) and self.__dictShouldBeChecked(node):
625 all(isinstance(key, ast.Str) for key in node.keys):
626 for key1, key2 in zip(node.keys, node.keys[1:]): 643 for key1, key2 in zip(node.keys, node.keys[1:]):
627 if key2.s < key1.s: 644 if key2.s < key1.s:
628 self.__error(key2.lineno - 1, key2.col_offset, 645 self.__error(key2.lineno - 1, key2.col_offset,
629 "M201", key2.s, key1.s) 646 "M201", key2.s, key1.s)
630 647

eric ide

mercurial