Module rulebook_pylint.checkers.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

        next2: NodeNG = node
        while next2:
            next2 = next2.next_sibling()

            # checks for violation
            if isinstance(next2, (FunctionDef, Assign, AssignName)):
                self.add_message(self.MSG, node=node)
                return

See detail: https://hanggrian.github.io/rulebook/rules/#inner-class-position

Checker instances should have the linter as argument.

Ancestors

  • 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

    next2: NodeNG = node
    while next2:
        next2 = next2.next_sibling()

        # checks for violation
        if isinstance(next2, (FunctionDef, Assign, AssignName)):
            self.add_message(self.MSG, node=node)
            return