Module rulebook-pylint.rulebook_pylint.built_in_function_position
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(BuiltInFunctionPositionChecker(linter))
Classes
class BuiltInFunctionPositionChecker (linter: PyLinter)
-
Expand source code
class BuiltInFunctionPositionChecker(RulebookChecker): """See detail: https://hanggrian.github.io/rulebook/rules/#built-in-function-position""" MSG: str = 'built-in-function-position' SPECIAL_FUNCTIONS = ( '__str__', '__hash__', '__eq__', '__new__', '__del__', '__repr__', '__bytes__', '__format__', '__lt__', '__le__', '__ne__', '__gt__', '__ge__', '__bool__', ) name: str = 'built-in-function-position' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG) def visit_functiondef(self, node: FunctionDef) -> None: # target special function if node.name not in self.SPECIAL_FUNCTIONS: return current: NodeNG = node while current: # checks for violation if isinstance(current, FunctionDef) and \ not has_decorator(current, 'staticmethod') and \ current.name not in self.SPECIAL_FUNCTIONS: self.add_message(self.MSG, node=node, args=node.name) return current = current.next_sibling()
See detail: https://hanggrian.github.io/rulebook/rules/#built-in-function-position
Checker instances should have the linter as argument.
Ancestors
- rulebook_pylint.checkers.RulebookChecker
- pylint.checkers.base_checker.BaseChecker
- pylint.config.arguments_provider._ArgumentsProvider
Class variables
var MSG : str
-
The type of the None singleton.
var SPECIAL_FUNCTIONS
-
The type of the None singleton.
var msgs : dict[str, tuple[str, str, str] | tuple[str, str, str, pylint.typing.ExtraMessageOptions]]
-
The type of the None singleton.
var name : str
-
The type of the None singleton.
Methods
def visit_functiondef(self, node: astroid.nodes.scoped_nodes.scoped_nodes.FunctionDef) ‑> None
-
Expand source code
def visit_functiondef(self, node: FunctionDef) -> None: # target special function if node.name not in self.SPECIAL_FUNCTIONS: return current: NodeNG = node while current: # checks for violation if isinstance(current, FunctionDef) and \ not has_decorator(current, 'staticmethod') and \ current.name not in self.SPECIAL_FUNCTIONS: self.add_message(self.MSG, node=node, args=node.name) return current = current.next_sibling()