tools/indentlevel.py

Sun, 09 Apr 2023 16:23:05 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 09 Apr 2023 16:23:05 +0300
changeset 365
9d5cb5635c18
parent 317
852021f38b66
permissions
-rw-r--r--

Add undo, redo, cut, copy and paste actions to MainWindow which pass onto the editor widget

317
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python3
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
2 import sys
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
3 too_many = 6
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
4 for filename in sys.argv[1:]:
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
5 with open(filename) as file:
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
6 at_start_of_new_block = False
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
7 old_n = 0
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
8 for linenumber, line in enumerate(file, 1):
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
9 import re
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
10 n = len(re.match('^(\t*).*$', line).group(1))
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
11 if at_start_of_new_block and n >= too_many and old_n < too_many:
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
12 print(f'{filename}:{linenumber}: warning: block with {n} indent levels', file = sys.stderr)
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
13 at_start_of_new_block = line.strip().endswith('{')
852021f38b66 Let's try to keep the amount of indents in check...
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff changeset
14 old_n = n

mercurial