1d07b4ed377592c74b7dacb7bd25e193d48fe394
[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 def setup_logging(logger):
13 """
14 ``arc lint`` makes it quite tricky to catch debug output from linters.
15 Log to a file to work around this.
16 """
17 hdlr = logging.FileHandler('linter.log', 'w')
18 logger.addHandler(hdlr)
19 logger.setLevel(logging.DEBUG)
20 return logger
21
22 logger = logging.getLogger()
23 #setup_logging(logger)
24 logger.debug(sys.argv)
25
26 path = sys.argv[1]
27 warnings = []
28 if os.path.isfile(path):
29 with open(path) as f:
30 for lineno, line in enumerate(f):
31 if re.search('ASSERT \(', line) is not None:
32 warning = {
33 'severity': 'warning',
34 'message': 'CPP macros should not have a space between the macro name and their argument list',
35 'line': lineno+1,
36 }
37 warnings.append(warning)
38
39 logger.debug(warnings)
40 print(json.dumps(warnings))