Module rulebook-pylint.rulebook_pylint.block_comment_trim

Functions

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

Classes

class BlockCommentTrimChecker (linter: PyLinter)
Expand source code
class BlockCommentTrimChecker(RulebookChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#block-comment-trim"""
    MSG_FIRST: str = 'block-comment-trim-first'
    MSG_LAST: str = 'block-comment-trim-last'

    name: str = 'block-comment-trim'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG_FIRST, MSG_LAST)

    def visit_module(self, node: Module) -> None:
        self._process(node.doc_node)

    def visit_classdef(self, node: ClassDef) -> None:
        self._process(node.doc_node)

    def visit_functiondef(self, node: FunctionDef) -> None:
        self._process(node.doc_node)

    def _process(self, docstring: Const | None) -> None:
        # checks for violation
        if not docstring:
            return
        if docstring.value.startswith('\n\n'):
            self.add_message(self.MSG_FIRST, node=docstring, line=docstring.lineno)
        if regex.search(r'\n\n\s*$', docstring.value):
            self.add_message(self.MSG_LAST, node=docstring, line=docstring.end_lineno)

See detail: https://hanggrian.github.io/rulebook/rules/#block-comment-trim

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_FIRST : str

The type of the None singleton.

var MSG_LAST : 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:
    self._process(node.doc_node)
def visit_functiondef(self, node: astroid.nodes.scoped_nodes.scoped_nodes.FunctionDef) ‑> None
Expand source code
def visit_functiondef(self, node: FunctionDef) -> None:
    self._process(node.doc_node)
def visit_module(self, node: astroid.nodes.scoped_nodes.scoped_nodes.Module) ‑> None
Expand source code
def visit_module(self, node: Module) -> None:
    self._process(node.doc_node)