55PAT_TAB = re .compile ("#?\t *[^\t ]*$" )
66
77def checkascii (l ):
8- return any ((ord (c ) < 32 or ord (c ) > 127 ) and c != '\t ' for c in l )
8+ return any ((ord (c ) < 32 or ord (c ) > 127 ) and c != '\t ' for c in l )
99
1010status = 0
1111filename = None
@@ -14,47 +14,47 @@ def checkascii(l):
1414lastline = None
1515
1616for l in open (sys .argv [1 ], encoding = "utf-8" ):
17- l = l .rstrip ("\n " )
17+ l = l .rstrip ("\n " )
1818
19- if l .startswith ("+++" ):
20- line = 1
21- lastline = None
22- filename = l [4 :].strip ()
23- if checkascii (filename ):
24- sys .stderr .write ("*** Filename is non-ASCII: '{}'\n " .format (filename ))
25- status = 1
26- is_source = (filename .find ("3rdparty" ) < 0 ) and filename .endswith ((".cpp" , ".c" , ".hpp" , ".h" , ".mm" ))
27- elif l .startswith ("@@" ):
28- line = int (l .split ()[2 ].split ("," )[0 ])
29- lastline = None
30- elif l .startswith ("+" ):
31- l = l [1 :]
32- lastline = "+"
33- if is_source and checkascii (l ):
34- sys .stderr .write ("*** {}:{}: Non-ASCII found: '{}'\n " .format (filename , line , l ))
35- status = 1
36- if l != l .rstrip ():
37- sys .stderr .write ("*** {}:{}: Trailing whitespace: '{}'\n " .format (filename , line , l ))
38- status = 1
39- if is_source and not PAT_TAB .match (l ):
40- sys .stderr .write ("*** {}:{}: Invalid tab usage: '{}'\n " .format (filename , line , l ))
41- status = 1
42- if is_source and (l .find ("\t #" ) >= 0 ):
43- sys .stderr .write ("*** {}:{}: Preprocessor hash is put into the first column, before the tab indentation: '{}'\n " .format (filename , line , l ))
44- status = 1
45- if is_source and l .startswith (" " ):
46- sys .stderr .write ("*** {}:{}: Use tabs for indentation: '{}'\n " .format (filename , line , l ))
47- status = 1
48- line += 1
49- elif l .startswith (" " ):
50- line += 1
51- lastline = " "
52- elif l .startswith ("-" ):
53- # do not increment line
54- lastline = "-"
55- elif l == "\\ No newline at end of file" and lastline != "-" :
56- sys .stderr .write ("*** {}: No newline at end of file\n " .format (filename ))
57- if lastline == " " : sys .stderr .write ("Please fix the existing newline problem in the file.\n " )
58- status = 1
19+ if l .startswith ("+++" ):
20+ line = 1
21+ lastline = None
22+ filename = l [4 :].strip ()
23+ if checkascii (filename ):
24+ sys .stderr .write ("*** Filename is non-ASCII: '{}'\n " .format (filename ))
25+ status = 1
26+ is_source = (filename .find ("3rdparty" ) < 0 ) and filename .endswith ((".cpp" , ".c" , ".hpp" , ".h" , ".mm" ))
27+ elif l .startswith ("@@" ):
28+ line = int (l .split ()[2 ].split ("," )[0 ])
29+ lastline = None
30+ elif l .startswith ("+" ):
31+ l = l [1 :]
32+ lastline = "+"
33+ if is_source and checkascii (l ):
34+ sys .stderr .write ("*** {}:{}: Non-ASCII found: '{}'\n " .format (filename , line , l ))
35+ status = 1
36+ if l != l .rstrip ():
37+ sys .stderr .write ("*** {}:{}: Trailing whitespace: '{}'\n " .format (filename , line , l ))
38+ status = 1
39+ if is_source and not PAT_TAB .match (l ):
40+ sys .stderr .write ("*** {}:{}: Invalid tab usage: '{}'\n " .format (filename , line , l ))
41+ status = 1
42+ if is_source and (l .find ("\t #" ) >= 0 ):
43+ sys .stderr .write ("*** {}:{}: Preprocessor hash is put into the first column, before the tab indentation: '{}'\n " .format (filename , line , l ))
44+ status = 1
45+ if is_source and l .startswith (" " ):
46+ sys .stderr .write ("*** {}:{}: Use tabs for indentation: '{}'\n " .format (filename , line , l ))
47+ status = 1
48+ line += 1
49+ elif l .startswith (" " ):
50+ line += 1
51+ lastline = " "
52+ elif l .startswith ("-" ):
53+ # do not increment line
54+ lastline = "-"
55+ elif l == "\\ No newline at end of file" and lastline != "-" :
56+ sys .stderr .write ("*** {}: No newline at end of file\n " .format (filename ))
57+ if lastline == " " : sys .stderr .write ("Please fix the existing newline problem in the file.\n " )
58+ status = 1
5959
6060sys .exit (status )
0 commit comments