Module rulebook_pylint.checkers.comment_space

Functions

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

Classes

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

    name: str = 'comment-space'
    msgs: dict[str, MessageDefinitionTuple] = _Messages.of(MSG)

    def process_tokens(self, tokens: list[TokenInfo]) -> None:
        # checks for violation
        for token in [t for t in tokens if t.type == COMMENT]:
            if token.string.startswith('# ') or all(c == '#' for c in token.string):
                continue
            self.add_message(self.MSG, line=token.start[0], col_offset=token.start[1])

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

Checker instances should have the linter as argument.

Ancestors

  • 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:
    # checks for violation
    for token in [t for t in tokens if t.type == COMMENT]:
        if token.string.startswith('# ') or all(c == '#' for c in token.string):
            continue
        self.add_message(self.MSG, line=token.start[0], col_offset=token.start[1])

Should be overridden by subclasses.