eric6/Plugins/CheckerPlugins/CodeStyleChecker/Naming/NamingStyleChecker.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8222
5994b80b8760
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
16 ast.AsyncFunctionDef # __IGNORE_EXCEPTION__ 16 ast.AsyncFunctionDef # __IGNORE_EXCEPTION__
17 except AttributeError: 17 except AttributeError:
18 ast.AsyncFunctionDef = ast.FunctionDef 18 ast.AsyncFunctionDef = ast.FunctionDef
19 19
20 20
21 class NamingStyleChecker(object): 21 class NamingStyleChecker:
22 """ 22 """
23 Class implementing a checker for naming conventions. 23 Class implementing a checker for naming conventions.
24 """ 24 """
25 LowercaseRegex = re.compile(r"[_a-z][_a-z0-9]*$") 25 LowercaseRegex = re.compile(r"[_a-z][_a-z0-9]*$")
26 UppercaseRegexp = re.compile(r"[_A-Z][_A-Z0-9]*$") 26 UppercaseRegexp = re.compile(r"[_A-Z][_A-Z0-9]*$")
94 94
95 @param node AST tree node to scan 95 @param node AST tree node to scan
96 @yield tuple giving line number, offset within line and error code 96 @yield tuple giving line number, offset within line and error code
97 @ytype tuple of (int, int, str) 97 @ytype tuple of (int, int, str)
98 """ 98 """
99 for error in self.__visitNode(node): 99 yield from self.__visitNode(node)
100 yield error
101 self.__parents.append(node) 100 self.__parents.append(node)
102 for child in ast.iter_child_nodes(node): 101 for child in ast.iter_child_nodes(node):
103 for error in self.__visitTree(child): 102 yield from self.__visitTree(child)
104 yield error
105 self.__parents.pop() 103 self.__parents.pop()
106 104
107 def __visitNode(self, node): 105 def __visitNode(self, node):
108 """ 106 """
109 Private method to inspect the given AST node. 107 Private method to inspect the given AST node.
342 yield self.__error(node, "N805") 340 yield self.__error(node, "N805")
343 elif functionType == "classmethod": 341 elif functionType == "classmethod":
344 yield self.__error(node, "N804") 342 yield self.__error(node, "N804")
345 return 343 return
346 344
347 if functionType == "method": 345 if (
348 if argNames[0] != "self": 346 functionType == "method" and
349 yield self.__error(node, "N805") 347 argNames[0] != "self"
350 elif functionType == "classmethod": 348 ):
351 if argNames[0] != "cls": 349 yield self.__error(node, "N805")
352 yield self.__error(node, "N804") 350 elif (
353 elif functionType == "staticmethod": 351 functionType == "classmethod" and
354 if argNames[0] in ("cls", "self"): 352 argNames[0] != "cls"
355 yield self.__error(node, "N806") 353 ):
354 yield self.__error(node, "N804")
355 elif (
356 functionType == "staticmethod" and
357 argNames[0] in ("cls", "self")
358 ):
359 yield self.__error(node, "N806")
356 for arg in argNames: 360 for arg in argNames:
357 if not self.LowercaseRegex.match(arg): 361 if not self.LowercaseRegex.match(arg):
358 yield self.__error(node, "N803") 362 yield self.__error(node, "N803")
359 return 363 return
360 364

eric ide

mercurial