def _check_cover_comments(self, token: tokenize.TokenInfo) -> None: comment_text = get_comment_text(token) match = self._no_cover.match(comment_text) if not match: return self._no_cover_count += 1
def _check_empty_comment(self, token: tokenize.TokenInfo) -> None: self._line_num = token.start[0] self._check_same_block(token) # Triggering reserved token to be added if not self._in_same_block and self._has_reserved_token(): self.add_violation(EmptyCommentViolation(self._reserved_token)) self._block_alerted = True self._reserved_token = SENTINEL_TOKEN if get_comment_text(token) == EMPTY_STRING: if not self._in_same_block: # Stand alone empty comment or first empty comment in a block self.add_violation(EmptyCommentViolation(token)) self._block_alerted = True self._in_same_block = True to_reserve = ( # Empty comment right after non-empty, block not yet alerted self._is_consecutive(self._prev_non_empty) and self._in_same_block and not self._block_alerted) if to_reserve: self._reserved_token = token else: self._prev_non_empty = self._line_num if self._in_same_block: self._reserved_token = SENTINEL_TOKEN self._prev_comment_line_num = token.start[0]
def _check_typed_ast(self, token: tokenize.TokenInfo) -> None: comment_text = get_comment_text(token) match = self._type_check.match(comment_text) if not match: return declared_type = match.groups()[0].strip() if not declared_type.startswith('ignore'): self.add_violation( WrongMagicCommentViolation(token, text=comment_text), )
def _check_noqa(self, token: tokenize.TokenInfo) -> None: comment_text = get_comment_text(token) match = self._noqa_check.match(comment_text) if not match: return self._noqa_count += 1 excludes = match.groups()[0].strip() if not excludes: # We can not pass the actual line here, # since it will be ignored due to `# noqa` comment: self.add_violation(WrongMagicCommentViolation(text=comment_text))
def _check_empty_doc_comment(self, token: tokenize.TokenInfo) -> None: if get_comment_text(token) == ':': self.add_violation(WrongDocCommentViolation(token))