lint: Add linter to catch uses of ASSERT macro that Clang dislikes
[ghc.git] / .arc-linters / check-cpp.py
1 #!/usr/bin/env python
2
3 # A linter to warn for ASSERT macros which are separated from their argument
4 # list by a space, which Clang's CPP barfs on
5
6 import sys
7 import logging
8 import os
9 import json
10 import re
11
12
13 def setup_logging():
14 logger = logging.getLogger()
15 hdlr = logging.FileHandler('linter.log', 'w')
16 logger.addHandler(hdlr)
17 logger.setLevel(logging.DEBUG)
18 return logger
19
20 logger = setup_logging()
21 #logger.debug(sys.argv)
22
23 path = sys.argv[1]
24 warnings = []
25 if os.path.isfile(path):
26 with open(path) as f:
27 for lineno, line in enumerate(f):
28 if re.search('ASSERT \(', line) is not None:
29 warning = {
30 'severity': 'warning',
31 'message': 'CPP macros should not have a space between the macro name and their argument list',
32 'line': lineno+1,
33 }
34 warnings.append(warning)
35
36 logger.debug(warnings)
37 print json.dumps(warnings)