Module rulebook-pylint.rulebook_pylint.duplicate_blank_line_in_comment

Functions

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

Classes

class DuplicateBlankLineInCommentChecker (linter: PyLinter)
Expand source code
class DuplicateBlankLineInCommentChecker(RulebookTokenChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#duplicate-blank-line-in-comment"""
    MSG: str = 'duplicate-blank-line-in-comment'

    name: str = 'duplicate-blank-line-in-comment'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def process_tokens(self, tokens: list[TokenInfo]) -> None:
        last_empty_token: TokenInfo | None = None
        # checks for violation
        for token in [t for t in tokens if t.type == COMMENT and is_comment_empty(t)]:
            if not last_empty_token:
                last_empty_token = token
                continue
            if last_empty_token.start[0] + 1 == token.start[0]:
                self.add_message(self.MSG, line=token.start[0], col_offset=token.start[1])

            # keep previous token for comparison
            last_empty_token = token

See detail: https://hanggrian.github.io/rulebook/rules/#duplicate-blank-line-in-comment

Checker instances should have the linter as argument.

Ancestors

  • rulebook_pylint.checkers.RulebookTokenChecker
  • pylint.checkers.base_checker.BaseTokenChecker
  • pylint.checkers.base_checker.BaseChecker
  • pylint.config.arguments_provider._ArgumentsProvider
  • abc.ABC

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 process_tokens(self, tokens: list[tokenize.TokenInfo]) ‑> None
Expand source code
def process_tokens(self, tokens: list[TokenInfo]) -> None:
    last_empty_token: TokenInfo | None = None
    # checks for violation
    for token in [t for t in tokens if t.type == COMMENT and is_comment_empty(t)]:
        if not last_empty_token:
            last_empty_token = token
            continue
        if last_empty_token.start[0] + 1 == token.start[0]:
            self.add_message(self.MSG, line=token.start[0], col_offset=token.start[1])

        # keep previous token for comparison
        last_empty_token = token

Should be overridden by subclasses.