Module rulebook-pylint.rulebook_pylint.inner_class_position

Functions

def register(linter: PyLinter)
Expand source code
def register(linter: 'PyLinter') -> None:
    linter.register_checker(InnerClassPositionChecker(linter))

Classes

class InnerClassPositionChecker (linter: PyLinter)
Expand source code
class InnerClassPositionChecker(RulebookChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#inner-class-position"""
    MSG: str = 'inner-class-position'

    name: str = 'inner-class-position'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def visit_classdef(self, node: ClassDef) -> None:
        # consider only inner class
        if node.parent and not isinstance(node.parent, ClassDef):
            return

        current: NodeNG = node
        while current:
            # checks for violation
            if isinstance(current, FunctionDef):
                self.add_message(self.MSG, node=node)
                return

            current = current.next_sibling()

See detail: https://hanggrian.github.io/rulebook/rules/#inner-class-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 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_classdef(self, node: astroid.nodes.scoped_nodes.scoped_nodes.ClassDef) ‑> None
Expand source code
def visit_classdef(self, node: ClassDef) -> None:
    # consider only inner class
    if node.parent and not isinstance(node.parent, ClassDef):
        return

    current: NodeNG = node
    while current:
        # checks for violation
        if isinstance(current, FunctionDef):
            self.add_message(self.MSG, node=node)
            return

        current = current.next_sibling()