--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Sun Feb 23 12:42:47 2025 +0100 +++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Miscellaneous/MiscellaneousChecker.py Mon Feb 24 15:11:18 2025 +0100 @@ -95,161 +95,161 @@ Codes = [ ## Coding line - "M101", - "M102", + "M-101", + "M-102", ## Copyright - "M111", - "M112", + "M-111", + "M-112", ## Shadowed Builtins - "M131", - "M132", + "M-131", + "M-132", ## Comprehensions - "M180", - "M181", - "M182", - "M183", - "M184", - "M185", - "M186", - "M188", - "M189", - "M189a", - "M189b", - "M190", - "M190a", - "M190b", - "M191", - "M193", - "M193a", - "M193b", - "M193c", - "M194", - "M195", - "M196", - "M197", - "M198", - "M199", - "M200", + "M-180", + "M-181", + "M-182", + "M-183", + "M-184", + "M-185", + "M-186", + "M-188", + "M-189", + "M-189a", + "M-189b", + "M-190", + "M-190a", + "M-190b", + "M-191", + "M-193", + "M-193a", + "M-193b", + "M-193c", + "M-194", + "M-195", + "M-196", + "M-197", + "M-198", + "M-199", + "M-200", ## Dictionaries with sorted keys - "M251", + "M-251", ## Property - "M260", - "M261", - "M262", - "M263", - "M264", - "M265", - "M266", - "M267", + "M-260", + "M-261", + "M-262", + "M-263", + "M-264", + "M-265", + "M-266", + "M-267", ## Naive datetime usage - "M301", - "M302", - "M303", - "M304", - "M305", - "M306", - "M307", - "M308", - "M311", - "M312", - "M313", - "M314", - "M315", - "M321", + "M-301", + "M-302", + "M-303", + "M-304", + "M-305", + "M-306", + "M-307", + "M-308", + "M-311", + "M-312", + "M-313", + "M-314", + "M-315", + "M-321", ## sys.version and sys.version_info usage - "M401", - "M402", - "M403", - "M411", - "M412", - "M413", - "M414", - "M421", - "M422", - "M423", + "M-401", + "M-402", + "M-403", + "M-411", + "M-412", + "M-413", + "M-414", + "M-421", + "M-422", + "M-423", ## Bugbear - "M501", - "M502", - "M503", - "M504", - "M505", - "M506", - "M507", - "M508", - "M509", - "M510", - "M511", - "M512", - "M513", - "M514", - "M515", - "M516", - "M517", - "M518", - "M519", - "M520", - "M521", - "M522", - "M523", - "M524", - "M525", - "M526", - "M527", - "M528", - "M529", - "M530", - "M531", - "M532", - "M533", - "M534", - "M535", - "M536", - "M537", - "M539", - "M540", - "M541", + "M-501", + "M-502", + "M-503", + "M-504", + "M-505", + "M-506", + "M-507", + "M-508", + "M-509", + "M-510", + "M-511", + "M-512", + "M-513", + "M-514", + "M-515", + "M-516", + "M-517", + "M-518", + "M-519", + "M-520", + "M-521", + "M-522", + "M-523", + "M-524", + "M-525", + "M-526", + "M-527", + "M-528", + "M-529", + "M-530", + "M-531", + "M-532", + "M-533", + "M-534", + "M-535", + "M-536", + "M-537", + "M-539", + "M-540", + "M-541", ## Bugbear, opininonated - "M569", + "M-569", ## Bugbear++ - "M581", - "M582", + "M-581", + "M-582", ## Format Strings - "M601", - "M611", - "M612", - "M613", - "M621", - "M622", - "M623", - "M624", - "M625", - "M631", - "M632", + "M-601", + "M-611", + "M-612", + "M-613", + "M-621", + "M-622", + "M-623", + "M-624", + "M-625", + "M-631", + "M-632", ## Future statements - "M701", - "M702", + "M-701", + "M-702", ## Gettext - "M711", + "M-711", ## print() statements - "M801", + "M-801", ## one element tuple - "M811", + "M-811", ## return statements - "M831", - "M832", - "M833", - "M834", + "M-831", + "M-832", + "M-833", + "M-834", ## line continuation - "M841", + "M-841", ## implicitly concatenated strings - "M851", - "M852", - "M853", + "M-851", + "M-852", + "M-853", ## commented code - "M891", + "M-891", ## structural pattern matching - "M901", - "M902", + "M-901", + "M-902", ] Formatter = Formatter() @@ -309,153 +309,153 @@ self.errors = [] checkersWithCodes = [ - (self.__checkCoding, ("M101", "M102")), - (self.__checkCopyright, ("M111", "M112")), - (self.__checkBuiltins, ("M131", "M132")), + (self.__checkCoding, ("M-101", "M-102")), + (self.__checkCopyright, ("M-111", "M-112")), + (self.__checkBuiltins, ("M-131", "M-132")), ( self.__checkComprehensions, ( - "M180", - "M181", - "M182", - "M183", - "M184", - "M185", - "M186", - "M188", - "M189", - "M189a", - "M189b", - "M190", - "M190a", - "M190b", - "M191", - "M193", - "M193a", - "M193b", - "M193c", - "M194", - "M195", - "M196", - "M197", - "M198", - "M199", - "M200", + "M-180", + "M-181", + "M-182", + "M-183", + "M-184", + "M-185", + "M-186", + "M-188", + "M-189", + "M-189a", + "M-189b", + "M-190", + "M-190a", + "M-190b", + "M-191", + "M-193", + "M-193a", + "M-193b", + "M-193c", + "M-194", + "M-195", + "M-196", + "M-197", + "M-198", + "M-199", + "M-200", ), ), - (self.__checkDictWithSortedKeys, ("M251",)), + (self.__checkDictWithSortedKeys, ("M-251",)), ( self.__checkProperties, - ("M260", "M261", "M262", "M263", "M264", "M265", "M266", "M267"), + ("M-260", "M-261", "M-262", "M-263", "M-264", "M-265", "M-266", "M-267"), ), ( self.__checkDateTime, ( - "M301", - "M302", - "M303", - "M304", - "M305", - "M306", - "M307", - "M308", - "M311", - "M312", - "M313", - "M314", - "M315", - "M321", + "M-301", + "M-302", + "M-303", + "M-304", + "M-305", + "M-306", + "M-307", + "M-308", + "M-311", + "M-312", + "M-313", + "M-314", + "M-315", + "M-321", ), ), ( self.__checkSysVersion, ( - "M401", - "M402", - "M403", - "M411", - "M412", - "M413", - "M414", - "M421", - "M422", - "M423", + "M-401", + "M-402", + "M-403", + "M-411", + "M-412", + "M-413", + "M-414", + "M-421", + "M-422", + "M-423", ), ), ( self.__checkBugBear, ( - "M501", - "M502", - "M503", - "M504", - "M505", - "M506", - "M507", - "M508", - "M509", - "M510", - "M511", - "M512", - "M513", - "M514", - "M515", - "M516", - "M517", - "M518", - "M519", - "M520", - "M521", - "M522", - "M523", - "M524", - "M525", - "M526", - "M527", - "M528", - "M529", - "M530", - "M531", - "M532", - "M533", - "M534", - "M535", - "M536", - "M537", - "M539", - "M540", - "M541", - "M569", - "M581", - "M582", + "M-501", + "M-502", + "M-503", + "M-504", + "M-505", + "M-506", + "M-507", + "M-508", + "M-509", + "M-510", + "M-511", + "M-512", + "M-513", + "M-514", + "M-515", + "M-516", + "M-517", + "M-518", + "M-519", + "M-520", + "M-521", + "M-522", + "M-523", + "M-524", + "M-525", + "M-526", + "M-527", + "M-528", + "M-529", + "M-530", + "M-531", + "M-532", + "M-533", + "M-534", + "M-535", + "M-536", + "M-537", + "M-539", + "M-540", + "M-541", + "M-569", + "M-581", + "M-582", ), ), - (self.__checkPep3101, ("M601",)), + (self.__checkPep3101, ("M-601",)), ( self.__checkFormatString, ( - "M611", - "M612", - "M613", - "M621", - "M622", - "M623", - "M624", - "M625", - "M631", - "M632", + "M-611", + "M-612", + "M-613", + "M-621", + "M-622", + "M-623", + "M-624", + "M-625", + "M-631", + "M-632", ), ), - (self.__checkFuture, ("M701", "M702")), - (self.__checkGettext, ("M711",)), - (self.__checkPrintStatements, ("M801",)), - (self.__checkTuple, ("M811",)), - (self.__checkReturn, ("M831", "M832", "M833", "M834")), - (self.__checkLineContinuation, ("M841",)), - (self.__checkImplicitStringConcat, ("M851", "M852")), - (self.__checkExplicitStringConcat, ("M853",)), - (self.__checkCommentedCode, ("M891",)), - (self.__checkDefaultMatchCase, ("M901", "M902")), + (self.__checkFuture, ("M-701", "M-702")), + (self.__checkGettext, ("M-711",)), + (self.__checkPrintStatements, ("M-801",)), + (self.__checkTuple, ("M-811",)), + (self.__checkReturn, ("M-831", "M-832", "M-833", "M-834")), + (self.__checkLineContinuation, ("M-841",)), + (self.__checkImplicitStringConcat, ("M-851", "M-852")), + (self.__checkExplicitStringConcat, ("M-853",)), + (self.__checkCommentedCode, ("M-891",)), + (self.__checkDefaultMatchCase, ("M-901", "M-902")), ] # the eradicate whitelist @@ -573,9 +573,9 @@ lineno, coding = self.__getCoding() if coding: if coding.lower() not in encodings: - self.__error(lineno, 0, "M102", coding) + self.__error(lineno, 0, "M-102", coding) else: - self.__error(0, 0, "M101") + self.__error(0, 0, "M-101") def __checkCopyright(self): """ @@ -603,7 +603,7 @@ copyrightRe = re.compile(copyrightRegexStr.format(author=r".*"), re.IGNORECASE) if not copyrightRe.search(topOfSource): - self.__error(0, 0, "M111") + self.__error(0, 0, "M-111") return if copyrightAuthor: @@ -611,7 +611,7 @@ copyrightRegexStr.format(author=copyrightAuthor), re.IGNORECASE ) if not copyrightAuthorRe.search(topOfSource): - self.__error(0, 0, "M112") + self.__error(0, 0, "M-112") def __checkCommentedCode(self): """ @@ -629,7 +629,7 @@ for markedLine in self.__eradicator.commented_out_code_line_numbers( source, aggressive=aggressive ): - self.__error(markedLine - 1, 0, "M891") + self.__error(markedLine - 1, 0, "M-891") def __checkLineContinuation(self): """ @@ -652,7 +652,7 @@ if strippedLine.endswith("\\") and not strippedLine.startswith( ("assert", "with") ): - self.__error(lineIndex, len(line), "M841") + self.__error(lineIndex, len(line), "M-841") def __checkPrintStatements(self): """ @@ -662,7 +662,7 @@ if ( isinstance(node, ast.Call) and getattr(node.func, "id", None) == "print" ) or (hasattr(ast, "Print") and isinstance(node, ast.Print)): - self.__error(node.lineno - 1, node.col_offset, "M801") + self.__error(node.lineno - 1, node.col_offset, "M-801") def __checkTuple(self): """ @@ -670,7 +670,7 @@ """ for node in ast.walk(self.__tree): if isinstance(node, ast.Tuple) and len(node.elts) == 1: - self.__error(node.lineno - 1, node.col_offset, "M811") + self.__error(node.lineno - 1, node.col_offset, "M-811") def __checkFuture(self): """ @@ -708,13 +708,13 @@ self.__error( node.lineno - 1, node.col_offset, - "M701", + "M-701", ", ".join(expectedImports), ", ".join(imports), ) else: self.__error( - node.lineno - 1, node.col_offset, "M702", ", ".join(expectedImports) + node.lineno - 1, node.col_offset, "M-702", ", ".join(expectedImports) ) def __checkPep3101(self): @@ -738,7 +738,7 @@ c = line[pos] if c in "diouxXeEfFgGcrs": formatter += c - self.__error(lineno, formatPos, "M601", formatter) + self.__error(lineno, formatPos, "M-601", formatter) def __checkFormatString(self): """ @@ -761,12 +761,12 @@ fields, implicit, explicit = self.__getFields(text) if implicit: if node in visitor.calls: - self.__error(node.lineno - 1, node.col_offset, "M611") + self.__error(node.lineno - 1, node.col_offset, "M-611") else: if node.is_docstring: - self.__error(node.lineno - 1, node.col_offset, "M612") + self.__error(node.lineno - 1, node.col_offset, "M-612") else: - self.__error(node.lineno - 1, node.col_offset, "M613") + self.__error(node.lineno - 1, node.col_offset, "M-613") if node in visitor.calls: call, strArgs = visitor.calls[node] @@ -804,33 +804,33 @@ # parameters but at least check if the args are used if hasKwArgs and not names: # No names but kwargs - self.__error(call.lineno - 1, call.col_offset, "M623") + self.__error(call.lineno - 1, call.col_offset, "M-623") if hasStarArgs and not numbers: # No numbers but args - self.__error(call.lineno - 1, call.col_offset, "M624") + self.__error(call.lineno - 1, call.col_offset, "M-624") if not hasKwArgs and not hasStarArgs: # can actually verify numbers and names for number in sorted(numbers): if number >= numArgs: self.__error( - call.lineno - 1, call.col_offset, "M621", number + call.lineno - 1, call.col_offset, "M-621", number ) for name in sorted(names): if name not in keywords: - self.__error(call.lineno - 1, call.col_offset, "M622", name) + self.__error(call.lineno - 1, call.col_offset, "M-622", name) for arg in range(numArgs): if arg not in numbers: - self.__error(call.lineno - 1, call.col_offset, "M631", arg) + self.__error(call.lineno - 1, call.col_offset, "M-631", arg) for keyword in keywords: if keyword not in names: - self.__error(call.lineno - 1, call.col_offset, "M632", keyword) + self.__error(call.lineno - 1, call.col_offset, "M-632", keyword) if implicit and explicit: - self.__error(call.lineno - 1, call.col_offset, "M625") + self.__error(call.lineno - 1, call.col_offset, "M-625") def __getFields(self, string): """ @@ -891,7 +891,7 @@ # ignore compatibility assignments continue self.__error( - element.lineno - 1, element.col_offset, "M131", element.id + element.lineno - 1, element.col_offset, "M-131", element.id ) elif isinstance(element, (ast.Tuple, ast.List)): for tupleElement in element.elts: @@ -902,7 +902,7 @@ self.__error( tupleElement.lineno - 1, tupleElement.col_offset, - "M131", + "M-131", tupleElement.id, ) elif isinstance(node, ast.For): @@ -910,7 +910,7 @@ target = node.target if isinstance(target, ast.Name) and target.id in self.__builtins: self.__error( - target.lineno - 1, target.col_offset, "M131", target.id + target.lineno - 1, target.col_offset, "M-131", target.id ) elif isinstance(target, (ast.Tuple, ast.List)): for element in target.elts: @@ -921,14 +921,14 @@ self.__error( element.lineno - 1, element.col_offset, - "M131", + "M-131", element.id, ) elif any(isinstance(node, functionDef) for functionDef in functionDefs): # (asynchronous) function definition for arg in node.args.args: if isinstance(arg, ast.arg) and arg.arg in self.__builtins: - self.__error(arg.lineno - 1, arg.col_offset, "M132", arg.arg) + self.__error(arg.lineno - 1, arg.col_offset, "M-132", arg.arg) def __checkComprehensions(self): """ @@ -956,8 +956,8 @@ and node.func.id in ("list", "set") ): errorCode = { - "list": "M180", - "set": "M181", + "list": "M-180", + "set": "M-181", }[node.func.id] self.__error(node.lineno - 1, node.col_offset, errorCode) @@ -970,9 +970,9 @@ and len(node.args[0].elt.elts) == 2 ): if isinstance(node.args[0], ast.GeneratorExp): - errorCode = "M182" + errorCode = "M-182" else: - errorCode = "M184" + errorCode = "M-184" self.__error(node.lineno - 1, node.col_offset, errorCode) elif ( @@ -981,10 +981,10 @@ and node.func.id in ("list", "set", "any", "all") ): errorCode = { - "list": "M191", - "set": "M183", - "any": "M199", - "all": "M199", + "list": "M-191", + "set": "M-183", + "any": "M-199", + "all": "M-199", }[node.func.id] self.__error( node.lineno - 1, node.col_offset, errorCode, node.func.id @@ -997,8 +997,8 @@ and node.func.id == "list" ): errorCode = { - "tuple": "M189a", - "list": "M190a", + "tuple": "M-189a", + "list": "M-190a", }[node.func.id] self.__error( node.lineno - 1, @@ -1021,7 +1021,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M198", + "M-198", type_, ) @@ -1040,10 +1040,10 @@ ) ): errorCode = { - "tuple": "M189b", - "list": "M190b", - "set": "M185", - "dict": "M186", + "tuple": "M-189b", + "list": "M-190b", + "set": "M-185", + "dict": "M-186", }[node.func.id] self.__error( node.lineno - 1, @@ -1063,7 +1063,7 @@ and numKeywordArgs == 0 and node.func.id in ("tuple", "list") ): - self.__error(node.lineno - 1, node.col_offset, "M188", node.func.id) + self.__error(node.lineno - 1, node.col_offset, "M-188", node.func.id) elif ( node.func.id in {"list", "reversed"} @@ -1087,7 +1087,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M193a", + "M-193a", node.func.id, node.args[0].func.id, ) @@ -1095,7 +1095,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M193b", + "M-193b", node.func.id, node.args[0].func.id, not reverseFlagValue, @@ -1105,7 +1105,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M193c", + "M-193c", node.func.id, node.args[0].func.id, ) @@ -1130,7 +1130,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M194", + "M-194", node.args[0].func.id, node.func.id, ) @@ -1147,7 +1147,7 @@ and isinstance(node.args[0].slice.step.operand, ast.Constant) and node.args[0].slice.step.operand.n == 1 ): - self.__error(node.lineno - 1, node.col_offset, "M195", node.func.id) + self.__error(node.lineno - 1, node.col_offset, "M-195", node.func.id) elif ( node.func.id == "map" @@ -1156,7 +1156,7 @@ and isinstance(node.args[0], ast.Lambda) ): self.__error( - node.lineno - 1, node.col_offset, "M197", "generator expression" + node.lineno - 1, node.col_offset, "M-197", "generator expression" ) elif ( @@ -1186,7 +1186,7 @@ if rewriteable: comprehensionType = f"{node.func.id} comprehension" self.__error( - node.lineno - 1, node.col_offset, "M197", comprehensionType + node.lineno - 1, node.col_offset, "M-197", comprehensionType ) elif isinstance(node, (ast.DictComp, ast.ListComp, ast.SetComp)) and ( @@ -1213,7 +1213,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M196", + "M-196", compType[node.__class__], ) @@ -1227,7 +1227,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M200", + "M-200", compType[node.__class__], ) @@ -1263,7 +1263,7 @@ self.__error( key2.lineno - 1, key2.col_offset, - "M251", + "M-251", key2.value, key1.value, ) @@ -1277,7 +1277,7 @@ name.asname == "_" for name in node.names ): self.__error( - node.lineno - 1, node.col_offset, "M711", node.names[0].name + node.lineno - 1, node.col_offset, "M-711", node.names[0].name ) def __checkBugBear(self): @@ -1353,7 +1353,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M260", + "M-260", len(node.args.args), ) @@ -1366,7 +1366,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M265", + "M-265", node.name, decorator.value.id, ) @@ -1374,7 +1374,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M263", + "M-263", decorator.value.id, node.name, ) @@ -1382,7 +1382,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M261", + "M-261", len(node.args.args), ) @@ -1394,7 +1394,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M266", + "M-266", node.name, decorator.value.id, ) @@ -1402,7 +1402,7 @@ self.__error( node.lineno - 1, node.col_offset, - "M264", + "M-264", decorator.value.id, node.name, ) @@ -1410,12 +1410,12 @@ self.__error( node.lineno - 1, node.col_offset, - "M262", + "M-262", len(node.args.args), ) if propertyCount > 1: - self.__error(node.lineno - 1, node.col_offset, "M267", node.name) + self.__error(node.lineno - 1, node.col_offset, "M-267", node.name) ####################################################################### ## The following methods check for implicitly concatenated strings. @@ -1489,7 +1489,7 @@ for a, b in pairwise(tokensWithoutWhitespace): if self.__isImplicitStringConcat(a, b): self.__error( - a.end[0] - 1, a.end[1], "M851" if a.end[0] == b.start[0] else "M852" + a.end[0] - 1, a.end[1], "M-851" if a.end[0] == b.start[0] else "M-852" ) def __checkExplicitStringConcat(self): @@ -1506,7 +1506,7 @@ for operand in (node.left, node.right) ) ): - self.__error(node.lineno - 1, node.col_offset, "M853") + self.__error(node.lineno - 1, node.col_offset, "M-853") ################################################################################# ## The following method checks default match cases. @@ -1946,7 +1946,7 @@ if good != names: desc = good[0] if len(good) == 1 else "({0})".format(", ".join(good)) as_ = " as " + node.name if node.name is not None else "" - return (node, "M514", ", ".join(names), as_, desc, inTryStar) + return (node, "M-514", ", ".join(names), as_, desc, inTryStar) return None @@ -2019,7 +2019,7 @@ @type ast.Return """ if self.__inClassInit() and node.value is not None: - self.violations.append((node, "M537")) + self.violations.append((node, "M-537")) self.generic_visit(node) @@ -2031,7 +2031,7 @@ @type ast.Yield """ if self.__inClassInit(): - self.violations.append((node, "M537")) + self.violations.append((node, "M-537")) self.generic_visit(node) @@ -2043,7 +2043,7 @@ @type ast.YieldFrom """ if self.__inClassInit(): - self.violations.append((node, "M537")) + self.violations.append((node, "M-537")) self.generic_visit(node) @@ -2094,7 +2094,7 @@ names = self.__checkForM513_M514_M529_M530(node) if "BaseException" in names and not ExceptBaseExceptionVisitor(node).reRaised(): - self.violations.append((node, "M536")) + self.violations.append((node, "M-536")) self.generic_visit(node) @@ -2102,7 +2102,7 @@ self.__M540CaughtException is not None and self.__M540CaughtException.hasNote ): - self.violations.append((node, "M540")) + self.violations.append((node, "M-540")) self.__M540CaughtException = oldM540CaughtException def visit_UAdd(self, node): @@ -2115,7 +2115,7 @@ trailingNodes = list(map(type, self.nodeWindow[-4:])) if trailingNodes == [ast.UnaryOp, ast.UAdd, ast.UnaryOp, ast.UAdd]: originator = self.nodeWindow[-4] - self.violations.append((originator, "M502")) + self.violations.append((originator, "M-502")) self.generic_visit(node) @@ -2143,28 +2143,28 @@ and args[0].value.id == "self" and args[0].attr == "__class__" ): - self.violations.append((node, "M582")) + self.violations.append((node, "M-582")) # bad getattr and setattr if ( node.func.id in ("getattr", "hasattr") and node.args[1].value == "__call__" ): - self.violations.append((node, "M504")) + self.violations.append((node, "M-504")) if ( node.func.id == "getattr" and len(node.args) == 2 and self.__isIdentifier(node.args[1]) and iskeyword(AstUtilities.getValue(node.args[1])) ): - self.violations.append((node, "M509")) + self.violations.append((node, "M-509")) elif ( node.func.id == "setattr" and len(node.args) == 3 and self.__isIdentifier(node.args[1]) and iskeyword(AstUtilities.getValue(node.args[1])) ): - self.violations.append((node, "M510")) + self.violations.append((node, "M-510")) self.__checkForM526(node) @@ -2209,7 +2209,7 @@ and isinstance(target.value, ast.Name) and (target.value.id, target.attr) == ("os", "environ") ): - self.violations.append((node, "M503")) + self.violations.append((node, "M-503")) self.generic_visit(node) @@ -2309,7 +2309,7 @@ AstUtilities.isNameConstant(node.test) and AstUtilities.getValue(node.test) is False ): - self.violations.append((node, "M511")) + self.violations.append((node, "M-511")) self.generic_visit(node) @@ -2423,7 +2423,7 @@ if isinstance(value, ast.FormattedValue): return - self.violations.append((node, "M581")) + self.violations.append((node, "M-581")) def visit_AnnAssign(self, node): """ @@ -2512,7 +2512,7 @@ if len(value) == len(set(value)): return # no characters appear more than once - self.violations.append((node, "M505")) + self.violations.append((node, "M-505")) def __checkForM506_M508(self, node): """ @@ -2521,7 +2521,7 @@ @param node reference to the node to be processed @type ast.AsyncFunctionDef or ast.FunctionDef """ - visitor = FunctionDefDefaultsVisitor("M506", "M508") + visitor = FunctionDefDefaultsVisitor("M-506", "M-508") visitor.visit(node.args.defaults + node.args.kw_defaults) self.violations.extend(visitor.errors) @@ -2541,7 +2541,7 @@ usedNames = set(body.getNames()) for name in sorted(ctrlNames - usedNames): n = targets.getNames()[name][0] - self.violations.append((n, "M507", name)) + self.violations.append((n, "M-507", name)) def __checkForM512(self, node): """ @@ -2559,7 +2559,7 @@ badNodeTypes = (ast.Return,) elif isinstance(node, badNodeTypes): - self.violations.append((node, "M512", self.__inTryStar)) + self.violations.append((node, "M-512", self.__inTryStar)) for child in ast.iter_child_nodes(node): _loop(child, badNodeTypes) @@ -2593,16 +2593,16 @@ else: badHandlers.append(handler) if badHandlers: - self.violations.append((node, "M530")) + self.violations.append((node, "M-530")) if len(names) == 0 and not badHandlers and not ignoredHandlers: - self.violations.append((node, "M529", self.__inTryStar)) + self.violations.append((node, "M-529", self.__inTryStar)) elif ( len(names) == 1 and not badHandlers and not ignoredHandlers and isinstance(node.type, ast.Tuple) ): - self.violations.append((node, "M513", *names, self.__inTryStar)) + self.violations.append((node, "M-513", *names, self.__inTryStar)) else: maybeError = self.__checkRedundantExcepthandlers( names, node, self.__inTryStar @@ -2619,7 +2619,7 @@ @type ast.Compare """ if isinstance(self.nodeStack[-2], ast.Expr): - self.violations.append((node, "M515")) + self.violations.append((node, "M-515")) def __checkForM516(self, node): """ @@ -2633,7 +2633,7 @@ or AstUtilities.isNumber(node.exc) or AstUtilities.isString(node.exc) ): - self.violations.append((node, "M516")) + self.violations.append((node, "M-516")) def __checkForM517(self, node): """ @@ -2673,7 +2673,7 @@ and itemContext.args[0].id in ("Exception", "BaseException") and not item.optional_vars ): - self.violations.append((node, "M517")) + self.violations.append((node, "M-517")) def __checkForM518(self, node): """ @@ -2698,7 +2698,7 @@ or node.value.value is None ) ): - self.violations.append((node, "M518", node.value.__class__.__name__)) + self.violations.append((node, "M-518", node.value.__class__.__name__)) def __checkForM519(self, node): """ @@ -2731,7 +2731,7 @@ return if decorator in caches: - self.violations.append((node.decorator_list[idx], "M519")) + self.violations.append((node.decorator_list[idx], "M-519")) return def __checkForM520(self, node): @@ -2752,7 +2752,7 @@ for name in sorted(ctrlNames): if name in itersetNames: n = targets.getNames()[name][0] - self.violations.append((n, "M520")) + self.violations.append((n, "M-520")) def __checkForM521(self, node): """ @@ -2766,7 +2766,7 @@ and isinstance(node.body[0], ast.Expr) and isinstance(node.body[0].value, ast.JoinedStr) ): - self.violations.append((node.body[0].value, "M521")) + self.violations.append((node.body[0].value, "M-521")) def __checkForM522(self, node): """ @@ -2786,7 +2786,7 @@ and itemContext.func.attr == "suppress" and len(itemContext.args) == 0 ): - self.violations.append((node, "M522")) + self.violations.append((node, "M-522")) def __checkForM523(self, loopNode): """ @@ -2860,7 +2860,7 @@ for err in sorted(suspiciousVariables): if reassignedInLoop.issuperset(err[2]): - self.violations.append((err[3], "M523", err[2])) + self.violations.append((err[3], "M-523", err[2])) def __checkForM524_M527(self, node): """ @@ -2941,10 +2941,10 @@ and emptyBody(stmt.body) and not any(map(isOverload, stmt.decorator_list)) ): - self.violations.append((stmt, "M527", stmt.name)) + self.violations.append((stmt, "M-527", stmt.name)) if hasMethod and not hasAbstractMethod: - self.violations.append((node, "M524", node.name)) + self.violations.append((node, "M-524", node.name)) def __checkForM525(self, node): """ @@ -2970,7 +2970,7 @@ # sort to have a deterministic output duplicates = sorted({x for x in seen if seen.count(x) > 1}) for duplicate in duplicates: - self.violations.append((node, "M525", duplicate, self.__inTryStar)) + self.violations.append((node, "M-525", duplicate, self.__inTryStar)) def __checkForM526(self, node): """ @@ -2992,7 +2992,7 @@ firstKeyword.lineno, firstKeyword.col_offset, ): - self.violations.append((node, "M526")) + self.violations.append((node, "M-526")) def __checkForM528(self, node): """ @@ -3011,7 +3011,7 @@ and not any(isinstance(a, ast.Starred) for a in node.args) and not any(kw.arg is None for kw in node.keywords) ): - self.violations.append((node, "M528")) + self.violations.append((node, "M-528")) def __checkForM531(self, loopNode): """ @@ -3051,13 +3051,13 @@ isinstance(nestedNode, ast.Name) and nestedNode.id == groupName ): - self.violations.append((nestedNode, "M531")) + self.violations.append((nestedNode, "M-531")) # Handle multiple uses if isinstance(node, ast.Name) and node.id == groupName: numUsages += 1 if numUsages > 1: - self.violations.append((nestedNode, "M531")) + self.violations.append((nestedNode, "M-531")) def __checkForM532(self, node): """ @@ -3078,7 +3078,7 @@ ) ) ): - self.violations.append((node, "M532")) + self.violations.append((node, "M-532")) def __checkForM533(self, node): """ @@ -3092,7 +3092,7 @@ if not isinstance(elt, ast.Constant): continue if elt.value in seen: - self.violations.append((node, "M533", repr(elt.value))) + self.violations.append((node, "M-533", repr(elt.value))) else: seen.add(elt.value) @@ -3113,7 +3113,7 @@ def check(numArgs, paramName): if len(node.args) > numArgs: arg = node.args[numArgs] - self.violations.append((arg, "M534", func.attr, paramName)) + self.violations.append((arg, "M-534", func.attr, paramName)) if func.attr in ("sub", "subn"): check(3, "count") @@ -3131,11 +3131,11 @@ @type ast.DictComp """ if isinstance(node.key, ast.Constant): - self.violations.append((node, "M535", node.key.value)) + self.violations.append((node, "M-535", node.key.value)) elif isinstance( node.key, ast.Name ) and node.key.id not in self.__getDictCompLoopAndNamedExprVarNames(node): - self.violations.append((node, "M535", node.key.id)) + self.violations.append((node, "M-535", node.key.id)) def __checkForM539(self, node): """ @@ -3162,7 +3162,7 @@ else: return - visitor = FunctionDefDefaultsVisitor("M539", "M539") + visitor = FunctionDefDefaultsVisitor("M-539", "M-539") visitor.visit(kw.value) self.violations.extend(visitor.errors) @@ -3253,7 +3253,7 @@ value = convertToValue(node.values[index]) if value in seen: keyNode = node.keys[index] - self.violations.append((keyNode, "M541")) + self.violations.append((keyNode, "M-541")) seen.add(value) def __checkForM569(self, node): @@ -3272,7 +3272,7 @@ checker = M569Checker(name, self) checker.visit(node.body) for mutation in checker.mutations: - self.violations.append((mutation, "M569")) + self.violations.append((mutation, "M-569")) class M569Checker(ast.NodeVisitor): @@ -3945,7 +3945,7 @@ """ for node in self.returns: if not node.value: - self.violations.append((node, "M832")) + self.violations.append((node, "M-832")) def __checkUnnecessaryReturnNone(self): """ @@ -3953,7 +3953,7 @@ """ for node in self.returns: if self.__isNone(node.value): - self.violations.append((node, "M831")) + self.violations.append((node, "M-831")) def __checkImplicitReturn(self, node): """ @@ -3964,7 +3964,7 @@ """ if isinstance(node, ast.If): if not node.body or not node.orelse: - self.violations.append((node, "M833")) + self.violations.append((node, "M-833")) return self.__checkImplicitReturn(node.body[-1]) @@ -3987,7 +3987,7 @@ except AttributeError: okNodes = (ast.Return, ast.Raise, ast.While) if not isinstance(node, okNodes): - self.violations.append((node, "M833")) + self.violations.append((node, "M-833")) def __checkUnnecessaryAssign(self, node): """ @@ -4006,13 +4006,13 @@ return if varname not in self.refs: - self.violations.append((node, "M834")) + self.violations.append((node, "M-834")) return if self.__hasRefsBeforeNextAssign(varname, returnLineno): return - self.violations.append((node, "M834")) + self.violations.append((node, "M-834")) def __hasRefsBeforeNextAssign(self, varname, returnLineno): """ @@ -4126,7 +4126,7 @@ ) if not (isCase1 or isCase2): - self.violations.append((node, "M301")) + self.violations.append((node, "M-301")) elif node.func.attr == "time": # time(12, 10, 45, 0, datetime.timezone.utc) @@ -4143,20 +4143,20 @@ ) if not (isCase1 or isCase2): - self.violations.append((node, "M321")) + self.violations.append((node, "M-321")) elif node.func.attr == "date": - self.violations.append((node, "M311")) + self.violations.append((node, "M-311")) if isDateTimeClass or isDateTimeModuleAndClass: if node.func.attr == "today": - self.violations.append((node, "M302")) + self.violations.append((node, "M-302")) elif node.func.attr == "utcnow": - self.violations.append((node, "M303")) + self.violations.append((node, "M-303")) elif node.func.attr == "utcfromtimestamp": - self.violations.append((node, "M304")) + self.violations.append((node, "M-304")) elif node.func.attr in "now": # datetime.now(UTC) @@ -4177,7 +4177,7 @@ ) if not (isCase1 or isCase2): - self.violations.append((node, "M305")) + self.violations.append((node, "M-305")) elif node.func.attr == "fromtimestamp": # datetime.fromtimestamp(1234, UTC) @@ -4198,7 +4198,7 @@ ) if not (isCase1 or isCase2): - self.violations.append((node, "M306")) + self.violations.append((node, "M-306")) elif node.func.attr == "strptime": # datetime.strptime(...).replace(tzinfo=UTC) @@ -4216,10 +4216,10 @@ ) if not isCase1: - self.violations.append((node, "M307")) + self.violations.append((node, "M-307")) elif node.func.attr == "fromordinal": - self.violations.append((node, "M308")) + self.violations.append((node, "M-308")) # date.something() isDateClass = ( @@ -4239,16 +4239,16 @@ if isDateClass or isDateModuleAndClass: if node.func.attr == "today": - self.violations.append((node, "M312")) + self.violations.append((node, "M-312")) elif node.func.attr == "fromtimestamp": - self.violations.append((node, "M313")) + self.violations.append((node, "M-313")) elif node.func.attr == "fromordinal": - self.violations.append((node, "M314")) + self.violations.append((node, "M-314")) elif node.func.attr == "fromisoformat": - self.violations.append((node, "M315")) + self.violations.append((node, "M-315")) self.generic_visit(node) @@ -4337,23 +4337,23 @@ @type ast.Subscript """ if self.__isSysVersionUpperSlice(node, 1): - self.violations.append((node.value, "M423")) + self.violations.append((node.value, "M-423")) elif self.__isSysVersionUpperSlice(node, 3): - self.violations.append((node.value, "M401")) + self.violations.append((node.value, "M-401")) elif ( self.__isSys("version", node.value) and isinstance(node.slice, ast.Index) and AstUtilities.isNumber(node.slice.value) and AstUtilities.getValue(node.slice.value) == 2 ): - self.violations.append((node.value, "M402")) + self.violations.append((node.value, "M-402")) elif ( self.__isSys("version", node.value) and isinstance(node.slice, ast.Index) and AstUtilities.isNumber(node.slice.value) and AstUtilities.getValue(node.slice.value) == 0 ): - self.violations.append((node.value, "M421")) + self.violations.append((node.value, "M-421")) self.generic_visit(node) @@ -4375,7 +4375,7 @@ and AstUtilities.isNumber(node.comparators[0]) and AstUtilities.getValue(node.comparators[0]) == 3 ): - self.violations.append((node.left, "M411")) + self.violations.append((node.left, "M-411")) elif ( self.__isSys("version", node.left) and len(node.ops) == 1 @@ -4383,9 +4383,9 @@ and AstUtilities.isString(node.comparators[0]) ): if len(AstUtilities.getValue(node.comparators[0])) == 1: - errorCode = "M422" + errorCode = "M-422" else: - errorCode = "M403" + errorCode = "M-403" self.violations.append((node.left, errorCode)) elif ( isinstance(node.left, ast.Subscript) @@ -4397,7 +4397,7 @@ and isinstance(node.ops[0], (ast.Lt, ast.LtE, ast.Gt, ast.GtE)) and AstUtilities.isNumber(node.comparators[0]) ): - self.violations.append((node, "M413")) + self.violations.append((node, "M-413")) elif ( isinstance(node.left, ast.Attribute) and self.__isSys("version_info", node.left.value) @@ -4406,7 +4406,7 @@ and isinstance(node.ops[0], (ast.Lt, ast.LtE, ast.Gt, ast.GtE)) and AstUtilities.isNumber(node.comparators[0]) ): - self.violations.append((node, "M414")) + self.violations.append((node, "M-414")) self.generic_visit(node) @@ -4422,7 +4422,7 @@ and node.value.id == "six" and node.attr == "PY3" ): - self.violations.append((node, "M412")) + self.violations.append((node, "M-412")) self.generic_visit(node) @@ -4434,7 +4434,7 @@ @type ast.Name """ if node.id == "PY3" and self.__fromImports.get(node.id) == "six": - self.violations.append((node, "M412")) + self.violations.append((node, "M-412")) self.generic_visit(node) @@ -4479,9 +4479,9 @@ for case in node.cases: if self.__emptyMatchDefault(case): if self.__lastStatementDoesNotRaise(case): - yield self.__findBadNode(case), "M901" + yield self.__findBadNode(case), "M-901" elif self.__returnPrecedesExceptionRaising(case): - yield self.__findBadNode(case), "M902" + yield self.__findBadNode(case), "M-902" def __emptyMatchDefault(self, case): """