tools/indentlevel.py

changeset 317
852021f38b66
equal deleted inserted replaced
316:aab8e139a149 317:852021f38b66
1 #!/usr/bin/env python3
2 import sys
3 too_many = 6
4 for filename in sys.argv[1:]:
5 with open(filename) as file:
6 at_start_of_new_block = False
7 old_n = 0
8 for linenumber, line in enumerate(file, 1):
9 import re
10 n = len(re.match('^(\t*).*$', line).group(1))
11 if at_start_of_new_block and n >= too_many and old_n < too_many:
12 print(f'{filename}:{linenumber}: warning: block with {n} indent levels', file = sys.stderr)
13 at_start_of_new_block = line.strip().endswith('{')
14 old_n = n

mercurial