def check_line(line, i): if not line.endswith("\n"): self.add_message("missing-final-newline", line=i) else: # exclude \f (formfeed) from the rstrip stripped_line = line.rstrip("\t\n\r\v ") if not stripped_line and _EMPTY_LINE in self.config.no_space_check: # allow empty lines pass elif line[len(stripped_line) :] not in ("\n", "\r\n"): self.add_message( "trailing-whitespace", line=i, col_offset=len(stripped_line) ) # Don't count excess whitespace in the line length. line = stripped_line mobj = OPTION_RGX.search(line) if mobj and "=" in line: front_of_equal, _, back_of_equal = mobj.group(1).partition("=") if front_of_equal.strip() == "disable": if "line-too-long" in { _msg_id.strip() for _msg_id in back_of_equal.split(",") }: return None line = line.rsplit("#", 1)[0].rstrip() if len(line) > max_chars and not ignore_long_line.search(line): self.add_message("line-too-long", line=i, args=(len(line), max_chars)) return i + 1
def check_line(line, i, prev_line=None): if not line.endswith('\n'): self.add_message('missing-final-newline', line=i) else: # exclude \f (formfeed) from the rstrip stripped_line = line.rstrip('\t\n\r\v ') if not stripped_line and _EMPTY_LINE in self.config.no_space_check: # allow empty lines pass elif line[len(stripped_line):] not in ('\n', '\r\n'): self.add_message('trailing-whitespace', line=i) # Don't count excess whitespace in the line length. line = stripped_line mobj = OPTION_RGX.search(line) if mobj and mobj.group(1).split('=', 1)[0].strip() == 'disable': line = line.split('#')[0].rstrip() if len(line) > max_chars and not ignore_long_line.search(line): self.add_message('line-too-long', line=i, args=(len(line), max_chars)) return i + 1
def process_tokens(self, tokens): """inspect the source to find fixme problems""" if not self.config.notes: return comments = (token_info for token_info in tokens if token_info.type == tokenize.COMMENT) for comment in comments: comment_text = comment.string[1:].lstrip( ) # trim '#' and whitespaces # handle pylint disable clauses disable_option_match = OPTION_RGX.search(comment_text) if disable_option_match: try: _, value = disable_option_match.group(1).split("=", 1) values = [ _val.strip().upper() for _val in value.split(",") ] if set(values) & set(self.config.notes): continue except ValueError: self.add_message( "bad-inline-option", args=disable_option_match.group(1).strip(), line=comment.start[0], ) continue # emit warnings if necessary match = self._fixme_pattern.search("#" + comment_text.lower()) if match: note = match.group(1) self.add_message( "fixme", col_offset=comment.string.lower().index(note.lower()), args=comment_text, line=comment.start[0], )