diff --git a/checkers/misc.py b/checkers/misc.py index d1b7c2162..45ed348b4 100644 --- a/checkers/misc.py +++ b/checkers/misc.py @@ -32,10 +32,11 @@ MSGS = { 'Used when a source line cannot be decoded using the specified ' 'source file encoding.', {'maxversion': (3, 0)}), - } +} class EncodingChecker(BaseChecker): + """checks for: * warning notes in the code like FIXME, XXX * encoding issues. @@ -47,17 +48,17 @@ class EncodingChecker(BaseChecker): msgs = MSGS options = (('notes', - {'type' : 'csv', 'metavar' : '', - 'default' : ('FIXME', 'XXX', 'TODO'), - 'help' : 'List of note tags to take in consideration, \ -separated by a comma.' - }), - ) + {'type': 'csv', 'metavar': '', + 'default': ('FIXME', 'XXX', 'TODO'), + 'help': ('List of note tags to take in consideration, ' + 'separated by a comma.')}),) def _check_note(self, notes, lineno, line): - match = notes.search(line) - if match: - self.add_message('fixme', args=line[match.start():-1], line=lineno) + for note in notes: + match = note.search(line) + if not match: + continue + self.add_message('fixme', args=match.group(1).strip(), line=lineno) def _check_encoding(self, lineno, line, file_encoding): try: @@ -71,19 +72,22 @@ separated by a comma.' notes """ stream = module.file_stream - stream.seek(0) # XXX may be removed with astroid > 0.23 + stream.seek(0) # XXX may be removed with astroid > 0.23 if self.config.notes: - notes = re.compile('|'.join(self.config.notes)) + notes = [re.compile(r'.*?#\s+({}:*\s*.+)'.format(note)) + for note in self.config.notes] else: notes = None if module.file_encoding: encoding = module.file_encoding else: encoding = 'ascii' + for lineno, line in enumerate(stream): - line = self._check_encoding(lineno+1, line, encoding) + line = self._check_encoding(lineno + 1, line, encoding) if line is not None and notes: - self._check_note(notes, lineno+1, line) + self._check_note(notes, lineno + 1, line) + def register(linter): """required method to auto register this checker""" diff --git a/test/input/func_fixme.py b/test/input/func_fixme.py index b6371f1ea..7bd665312 100644 --- a/test/input/func_fixme.py +++ b/test/input/func_fixme.py @@ -1,9 +1,11 @@ """docstring""" - +# pylint: disable=W0612 __revision__ = '' # FIXME: beep + def function(): '''XXX:bop''' - + variable = "FIXME: Ignore me!" + test = "text" # FIXME: Valid test diff --git a/test/messages/func_fixme.txt b/test/messages/func_fixme.txt index 2544ce8f4..c114e7982 100644 --- a/test/messages/func_fixme.txt +++ b/test/messages/func_fixme.txt @@ -1,2 +1,2 @@ W: 5: FIXME: beep -W: 8: XXX:bop''' +W: 11: FIXME: Valid test \ No newline at end of file