Module rulebook-pylint.rulebook_pylint.short_block_comment_clip

Functions

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

Classes

class ShortBlockCommentClipChecker (linter: PyLinter)
Expand source code
class ShortBlockCommentClipChecker(RulebookChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#short-block-comment-clip"""
    MSG: str = 'short-block-comment-clip'

    SINGLELINE_TEMPLATE = 6  # """"""

    name: str = 'short-block-comment-clip'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)
    options: Options = (
        (
            'rulebook-max-line-length',
            {
                'default': 100,
                'type': 'int',
                'metavar': '<int>',
                'help': 'Max length of a line.',
            },
        ),
    )

    _max_line_length: int = 100

    def open(self) -> None:
        self._max_line_length = self.linter.config.rulebook_max_line_length

    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 '\n' not in docstring.value:
            return
        line: str = docstring.value.strip()
        if '\n' in line:
            return
        text_length: int = docstring.col_offset + len(line)
        if text_length + self.SINGLELINE_TEMPLATE <= self._max_line_length:
            self.add_message(self.MSG, node=docstring)

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

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 SINGLELINE_TEMPLATE

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.

var options : tuple[tuple[str, dict[str, str | bool | int | re.Pattern[str] | Iterable[str | int | re.Pattern[str]] | type['_CallbackAction'] | Callable[[Any], Any] | Callable[[Any, Any, Any, Any], Any] | None]], ...]

The type of the None singleton.

Methods

def open(self) ‑> None
Expand source code
def open(self) -> None:
    self._max_line_length = self.linter.config.rulebook_max_line_length

Called before visiting project (i.e. set of modules).

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)