Module rulebook-pylint.rulebook_pylint.duplicate_space
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(DuplicateSpaceChecker(linter))
Classes
class DuplicateSpaceChecker (linter: PyLinter)
-
Expand source code
class DuplicateSpaceChecker(RulebookTokenChecker): """See wiki: https://github.com/hanggrian/rulebook/wiki/Rules/#duplicate-space""" MSG: str = 'duplicate-space' name: str = 'duplicate-space' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG) def process_tokens(self, tokens: list[TokenInfo]) -> None: fstring_flag: bool = False for i, token in enumerate(tokens): # get last token to compare last_token: TokenInfo = tokens[i - 1] if last_token.type == FSTRING_END: fstring_flag = False # checks for violation if not fstring_flag and self._is_duplicate_space(token, last_token): self.add_message(self.MSG, line=last_token.start[0], col_offset=last_token.start[1]) if token.type == FSTRING_START: fstring_flag = True @staticmethod def _is_duplicate_space(token: TokenInfo, last_token: TokenInfo) -> bool: if any( (t in (NEWLINE, NL, INDENT, DEDENT, ENDMARKER) \ for t in (token.type, last_token.type)), ): return False return token.start[1] - last_token.end[1] > 2 \ if token.type == COMMENT \ else token.start[1] - last_token.end[1] > 1
See wiki: https://github.com/hanggrian/rulebook/wiki/Rules/#duplicate-space
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: fstring_flag: bool = False for i, token in enumerate(tokens): # get last token to compare last_token: TokenInfo = tokens[i - 1] if last_token.type == FSTRING_END: fstring_flag = False # checks for violation if not fstring_flag and self._is_duplicate_space(token, last_token): self.add_message(self.MSG, line=last_token.start[0], col_offset=last_token.start[1]) if token.type == FSTRING_START: fstring_flag = True
Should be overridden by subclasses.