Module rulebook-pylint.rulebook_pylint.unnecessary_blank_line_after_colon

Functions

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

Classes

class UnnecessaryBlankLineAfterColonChecker (linter: PyLinter)
Expand source code
class UnnecessaryBlankLineAfterColonChecker(RulebookTokenChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#unnecessary-blank-line-after-colon"""
    MSG: str = 'unnecessary-blank-line-after-colon'

    name: str = 'unnecessary-blank-line-after-colon'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def process_tokens(self, tokens: list[TokenInfo]) -> None:
        for i, token in enumerate(tokens):
            # target colon operator
            if token.type != OP or token.string != ':':
                continue

            # checks for violation
            if i + 2 >= len(tokens):
                continue
            next_token: TokenInfo = tokens[i + 1]
            next_token2: TokenInfo = tokens[i + 2]
            if next_token.type != NEWLINE or next_token2.type != NL:
                continue
            self.add_message(self.MSG, line=next_token2.start[0], col_offset=next_token2.start[1])

See detail: https://hanggrian.github.io/rulebook/rules/#unnecessary-blank-line-after-colon

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:
    for i, token in enumerate(tokens):
        # target colon operator
        if token.type != OP or token.string != ':':
            continue

        # checks for violation
        if i + 2 >= len(tokens):
            continue
        next_token: TokenInfo = tokens[i + 1]
        next_token2: TokenInfo = tokens[i + 2]
        if next_token.type != NEWLINE or next_token2.type != NL:
            continue
        self.add_message(self.MSG, line=next_token2.start[0], col_offset=next_token2.start[1])

Should be overridden by subclasses.