summaryrefslogtreecommitdiff
path: root/checkers/misc.py
diff options
context:
space:
mode:
authorAlexandru Coman <fcoman@bitdefender.com>2014-07-09 01:44:35 +0300
committerAlexandru Coman <fcoman@bitdefender.com>2014-07-09 01:44:35 +0300
commit1ab3a5b65b0b61f63ea153e6f9a0ed0b555e155b (patch)
tree70e162f223aa6da2df8b1b2e77c4a98272e7c98b /checkers/misc.py
parentae998e73b43075dac6e27fffbde78d1460bfd206 (diff)
downloadpylint-git-1ab3a5b65b0b61f63ea153e6f9a0ed0b555e155b.tar.gz
Fixing Issue #149 (W0511 false positive)
Diffstat (limited to 'checkers/misc.py')
-rw-r--r--checkers/misc.py32
1 files changed, 18 insertions, 14 deletions
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' : '<comma separated values>',
- 'default' : ('FIXME', 'XXX', 'TODO'),
- 'help' : 'List of note tags to take in consideration, \
-separated by a comma.'
- }),
- )
+ {'type': 'csv', 'metavar': '<comma separated values>',
+ '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"""