Check for tabs and fix more line number issues

develop
lethosor 2015-02-14 22:07:57 -05:00
parent f91a5767cd
commit 7b29538485
1 changed files with 39 additions and 26 deletions

@ -36,19 +36,23 @@ class Linter(object):
if not len(lines):
# should never happen
return 'nowhere'
s = 'lines ' if len(lines) != 1 else 'line '
if len(lines) == 1:
return 'line %i' % lines[0]
s = 'lines '
range_start = range_end = lines[0]
for i, line in enumerate(lines):
if line > range_start + 1 or i == len(lines) - 1:
if i == len(lines) - 1:
range_end = line
if line > range_end + 1:
if range_start == range_end:
s += ('%i, ' % range_end)
else:
s += ('%i-%i, ' % (range_start, range_end))
range_start = range_end = line
if i == len(lines) - 1:
s += ('%i' % line)
else:
range_end = line
if i == len(lines) - 1:
s += ('%i-%i, ' % (range_start, range_end))
return s.rstrip(' ').rstrip(',')
class NewlineLinter(Linter):
@ -62,8 +66,14 @@ class TrailingWhitespaceLinter(Linter):
line = line.replace('\r', '')
return not line.endswith(' ') and not line.endswith('\t')
linters = [NewlineLinter(), TrailingWhitespaceLinter()]
class TabLinter(Linter):
msg = 'Contains tabs'
def check_line(self, line):
return '\t' not in line
linters = [NewlineLinter(), TrailingWhitespaceLinter(), TabLinter()]
def main():
root_path = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else '.')
path_blacklist.append(root_path + '/.git')
path_blacklist.append(root_path + '/build')
@ -87,3 +97,6 @@ if success:
sys.exit(0)
else:
sys.exit(1)
if __name__ == '__main__':
main()