src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Naming/NamingStyleChecker.py

branch
eric7
changeset 10683
779cda568acb
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
equal deleted inserted replaced
10682:47be220abdaf 10683:779cda568acb
267 @return flag indicating to avoid it 267 @return flag indicating to avoid it
268 @rtype bool 268 @rtype bool
269 """ 269 """
270 return name in ("l", "O", "I") 270 return name in ("l", "O", "I")
271 271
272 def __checkNameToBeAvoided(self, node, parents): # noqa: U100 272 def __checkNameToBeAvoided(self, node, _parents):
273 """ 273 """
274 Private class to check the given node for a name to be avoided (N831). 274 Private class to check the given node for a name to be avoided (N831).
275 275
276 @param node AST note to check 276 @param node AST note to check
277 @type ast.Ast 277 @type ast.Ast
278 @param parents list of parent nodes 278 @param _parents list of parent nodes (unused)
279 @type list of ast.AST 279 @type list of ast.AST
280 @yield tuple giving line number, offset within line and error code 280 @yield tuple giving line number, offset within line and error code
281 @ytype tuple of (int, int, str) 281 @ytype tuple of (int, int, str)
282 """ 282 """
283 if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): 283 if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
376 376
377 superClasses = self.__superClassNames(name, parents) 377 superClasses = self.__superClassNames(name, parents)
378 if "Exception" in superClasses and not name.endswith("Error"): 378 if "Exception" in superClasses and not name.endswith("Error"):
379 yield self.__error(node, "N818") 379 yield self.__error(node, "N818")
380 380
381 def __checkFunctionName(self, node, parents): # noqa: U100 381 def __checkFunctionName(self, node, _parents):
382 """ 382 """
383 Private class to check the given node for function name 383 Private class to check the given node for function name
384 conventions (N802, N809). 384 conventions (N802, N809).
385 385
386 Function names should be lowercase, with words separated by underscores 386 Function names should be lowercase, with words separated by underscores
389 only in contexts where that's already the prevailing style 389 only in contexts where that's already the prevailing style
390 (e.g. threading.py), to retain backwards compatibility. 390 (e.g. threading.py), to retain backwards compatibility.
391 391
392 @param node AST note to check 392 @param node AST note to check
393 @type ast.FunctionDef or ast.AsynFunctionDef 393 @type ast.FunctionDef or ast.AsynFunctionDef
394 @param parents list of parent nodes 394 @param _parents list of parent nodes (unused)
395 @type list of ast.AST 395 @type list of ast.AST
396 @yield tuple giving line number, offset within line and error code 396 @yield tuple giving line number, offset within line and error code
397 @ytype tuple of (int, int, str) 397 @ytype tuple of (int, int, str)
398 """ 398 """
399 functionType = getattr(node, "function_type", "function") 399 functionType = getattr(node, "function_type", "function")
405 if name.lower() != name: 405 if name.lower() != name:
406 yield self.__error(node, "N802") 406 yield self.__error(node, "N802")
407 if functionType == "function" and name[:2] == "__" and name[-2:] == "__": 407 if functionType == "function" and name[:2] == "__" and name[-2:] == "__":
408 yield self.__error(node, "N809") 408 yield self.__error(node, "N809")
409 409
410 def __checkFunctionArgumentNames(self, node, parents): # noqa: U100 410 def __checkFunctionArgumentNames(self, node, _parents):
411 """ 411 """
412 Private class to check the argument names of functions 412 Private class to check the argument names of functions
413 (N803, N804, N805, N806). 413 (N803, N804, N805, N806).
414 414
415 The argument names of a function should be lowercase, with words 415 The argument names of a function should be lowercase, with words
416 separated by underscores. A class method should have 'cls' as the 416 separated by underscores. A class method should have 'cls' as the
417 first argument. A method should have 'self' as the first argument. 417 first argument. A method should have 'self' as the first argument.
418 418
419 @param node AST note to check 419 @param node AST note to check
420 @type ast.FunctionDef or ast.AsynFunctionDef 420 @type ast.FunctionDef or ast.AsynFunctionDef
421 @param parents list of parent nodes 421 @param _parents list of parent nodes (unused)
422 @type list of ast.AST 422 @type list of ast.AST
423 @yield tuple giving line number, offset within line and error code 423 @yield tuple giving line number, offset within line and error code
424 @ytype tuple of (int, int, str) 424 @ytype tuple of (int, int, str)
425 """ 425 """
426 if node.args.kwarg is not None: 426 if node.args.kwarg is not None:
617 isinstance(nodeValue.func, ast.Name) 617 isinstance(nodeValue.func, ast.Name)
618 and nodeValue.func.id == "namedtuple" 618 and nodeValue.func.id == "namedtuple"
619 ) 619 )
620 ) 620 )
621 621
622 def __checkModule(self, node, parents): # noqa: U100 622 def __checkModule(self, node, _parents):
623 """ 623 """
624 Private method to check module naming conventions (N807, N808). 624 Private method to check module naming conventions (N807, N808).
625 625
626 Module and package names should be lowercase. 626 Module and package names should be lowercase.
627 627
628 @param node AST node to check 628 @param node AST node to check
629 @type ast.AST 629 @type ast.AST
630 @param parents list of parent nodes 630 @param _parents list of parent nodes (unused)
631 @type list of ast.AST 631 @type list of ast.AST
632 @yield tuple giving line number, offset within line and error code 632 @yield tuple giving line number, offset within line and error code
633 @ytype tuple of (int, int, str) 633 @ytype tuple of (int, int, str)
634 """ 634 """
635 if self.__filename: 635 if self.__filename:
641 # we got a package 641 # we got a package
642 packageName = os.path.split(os.path.dirname(self.__filename))[1] 642 packageName = os.path.split(os.path.dirname(self.__filename))[1]
643 if packageName.lower() != packageName: 643 if packageName.lower() != packageName:
644 yield self.__error(node, "N808") 644 yield self.__error(node, "N808")
645 645
646 def __checkImportAs(self, node, parents): # noqa: U100 646 def __checkImportAs(self, node, _parents):
647 """ 647 """
648 Private method to check that imports don't change the 648 Private method to check that imports don't change the
649 naming convention (N811, N812, N813, N814, N815). 649 naming convention (N811, N812, N813, N814, N815).
650 650
651 @param node AST node to check 651 @param node AST node to check
652 @type ast.Import 652 @type ast.Import
653 @param parents list of parent nodes 653 @param _parents list of parent nodes (unused)
654 @type list of ast.AST 654 @type list of ast.AST
655 @yield tuple giving line number, offset within line and error code 655 @yield tuple giving line number, offset within line and error code
656 @ytype tuple of (int, int, str) 656 @ytype tuple of (int, int, str)
657 """ 657 """
658 for name in node.names: 658 for name in node.names:

eric ide

mercurial