Module rulebook-pylint.rulebook_pylint.parentheses_trim
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(ParenthesesTrimChecker(linter))
Classes
class ParenthesesTrimChecker (linter: PyLinter)
-
Expand source code
class ParenthesesTrimChecker(RulebookTokenChecker): """See detail: https://hanggrian.github.io/rulebook/rules/#parentheses-trim""" MSG_FIRST: str = 'parentheses-trim-first' MSG_LAST: str = 'parentheses-trim-last' name: str = 'parentheses-trim' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG_FIRST, MSG_LAST) def process_tokens(self, tokens: list[TokenInfo]) -> None: for i, token in enumerate(tokens): # find opening and closing parentheses if token.type != OP: continue if token.string in {'(', '[', '{'}: # 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 != NL or next_token2.type != NL: continue self.add_message( self.MSG_FIRST, line=next_token2.start[0], col_offset=next_token2.start[1], args=token.string, ) # checks for violation if token.string not in {')', ']', '}'}: continue if i - 2 < 0: continue prev_token: TokenInfo = tokens[i - 1] prev_token2: TokenInfo = tokens[i - 2] if prev_token.type != NL or prev_token2.type != NL: continue self.add_message( self.MSG_LAST, line=prev_token.start[0], col_offset=prev_token.start[1], args=token.string, )
See detail: https://hanggrian.github.io/rulebook/rules/#parentheses-trim
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_FIRST : str
-
The type of the None singleton.
var MSG_LAST : 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): # find opening and closing parentheses if token.type != OP: continue if token.string in {'(', '[', '{'}: # 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 != NL or next_token2.type != NL: continue self.add_message( self.MSG_FIRST, line=next_token2.start[0], col_offset=next_token2.start[1], args=token.string, ) # checks for violation if token.string not in {')', ']', '}'}: continue if i - 2 < 0: continue prev_token: TokenInfo = tokens[i - 1] prev_token2: TokenInfo = tokens[i - 2] if prev_token.type != NL or prev_token2.type != NL: continue self.add_message( self.MSG_LAST, line=prev_token.start[0], col_offset=prev_token.start[1], args=token.string, )
Should be overridden by subclasses.