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,13 +66,19 @@ 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()]
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')
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')
for cur, dirnames, filenames in os.walk(root_path):
for cur, dirnames, filenames in os.walk(root_path):
for filename in filenames:
full_path = os.path.join(cur, filename)
rel_path = full_path.replace(root_path, '.')
@ -82,8 +92,11 @@ for cur, dirnames, filenames in os.walk(root_path):
except LinterError as e:
error('%s: %s' % (rel_path, e))
if success:
if success:
print('All linters completed successfully')
sys.exit(0)
else:
else:
sys.exit(1)
if __name__ == '__main__':
main()