Module rulebook-pylint.rulebook_pylint.member_order

Functions

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

Classes

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

    name: str = 'member-order'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def visit_classdef(self, node: ClassDef) -> None:
        # in Python, static members have are annotated
        last_method: FunctionDef | None = None
        for method in [m for m in node.mymethods() if not has_decorator(m, 'staticmethod')]:
            # checks for violation
            if last_method and \
                last_method.name != '__init__' and \
                method.name == '__init__':
                self.add_message(self.MSG, node=method, args=('constructor', 'function'))

            last_method = method

See detail: https://hanggrian.github.io/rulebook/rules/#member-order

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:
    # in Python, static members have are annotated
    last_method: FunctionDef | None = None
    for method in [m for m in node.mymethods() if not has_decorator(m, 'staticmethod')]:
        # checks for violation
        if last_method and \
            last_method.name != '__init__' and \
            method.name == '__init__':
            self.add_message(self.MSG, node=method, args=('constructor', 'function'))

        last_method = method