File: github-indent-warnings.py

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (33 lines) | stat: -rwxr-xr-x 1,124 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3
import sys
import re

re_file = r'^diff --git a/(\S\S*)\s.*$'
re_line = r'^@@ -(\d\d*)\D.*@@.*$'

if __name__ == '__main__':
    if len(sys.argv) != 1 and len(sys.argv) != 2:
        print(f'usage: {sys.argv[0]} <path/to/file>')
        print(f'usage: <command> | {sys.argv[0]}')
        exit(1)

    input_file = sys.stdin.fileno()
    if len(sys.argv) == 2:
        input_file = sys.argv[1]

    with open(input_file, 'r') as fi:
        file_name = None
        line_number = None
        for line in fi:
            file_matches = re.findall(re_file, line)
            if len(file_matches) == 1:
                file_name = file_matches[0]
                continue

            if file_name is None:
                continue

            line_matches = re.findall(re_line, line)
            if len(line_matches) == 1:
                line_number = int(line_matches[0]) + 3
                print(f'::warning file={file_name},line={line_number}::clang-format: Possible coding style problem (https://github.com/checkpoint-restore/criu/blob/criu-dev/CONTRIBUTING.md#automatic-tools-to-fix-coding-style)')