9473 Want git nits to check for white space nits
[unleashed.git] / usr / src / tools / onbld / Checks / WsCheck.py
blobb05402e68caaa0579127dbbae3cb89495fa0bcb7
1 #! /usr/bin/python
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright 2018 Gordon Ross <gordon.w.ross@gmail.com>
18 # Check file for whitespace issues
19 # (space tab, trailing space)
23 import time, re, sys
25 stMsg = 'space tab sequences'
26 twsMsg = 'has trailing spaces'
28 def err(stream, fname, lineno, msg):
29 stream.write("%s:%d: %s\n" % (fname, lineno, msg))
31 def wscheck(fh, output=sys.stderr):
32 lineno = 1
33 ret = 0
35 fname = fh.name
37 for line in fh:
38 if re.search(r' \t', line):
39 err(output, fname, lineno, stMsg);
40 ret = 1
41 if re.search(r'[ \t]$', line):
42 err(output, fname, lineno, twsMsg);
43 ret = 1
44 lineno += 1
46 return ret