mirror of
https://fuchsia.googlesource.com/third_party/github.com/pylint-dev/pylint
synced 2024-09-21 07:58:04 +00:00
Fixing Issue #149 (W0511 false positive)
This commit is contained in:
parent
ae998e73b4
commit
1ab3a5b65b
|
@ -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"""
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"""docstring"""
|
||||
|
||||
# pylint: disable=W0612
|
||||
__revision__ = ''
|
||||
|
||||
# FIXME: beep
|
||||
|
||||
|
||||
def function():
|
||||
'''XXX:bop'''
|
||||
|
||||
variable = "FIXME: Ignore me!"
|
||||
test = "text" # FIXME: Valid test
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
W: 5: FIXME: beep
|
||||
W: 8: XXX:bop'''
|
||||
W: 11: FIXME: Valid test
|
Loading…
Reference in New Issue
Block a user