tools/linelength.py

changeset 114
4e03b0e2a29f
equal deleted inserted replaced
113:c0d064521ee0 114:4e03b0e2a29f
1 #!/usr/bin/env python3
2 import sys
3 def check(filename):
4 with open(filename) as file:
5 for linenumber, line in enumerate(file, 1):
6 if line[-1] == '\n':
7 line = line[:-1]
8 line = str.replace(line, '\t', ' ' * 4)
9 if len(line) > 120:
10 print(str.format(
11 '{filename}:{linenumber}: warning: line length exceeds 120 characters',
12 filename = filename,
13 linenumber = linenumber
14 ), file = sys.stderr)
15 def main():
16 for filename in sys.argv[1:]:
17 check(filename)
18 return 0
19 if __name__ == '__main__':
20 sys.exit(main())

mercurial