Commit 901cab10 authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

lint: Add linter to catch uses of ASSERT macro that Clang dislikes

In particular Clang rejects uses of CPP macros where the argument list
is separated by a space from the macro name. Warn when we see ASSERT
used in this way.
parent 020375d1
#!/usr/bin/env python
# A linter to warn for ASSERT macros which are separated from their argument
# list by a space, which Clang's CPP barfs on
import sys
import logging
import os
import json
import re
def setup_logging():
logger = logging.getLogger()
hdlr = logging.FileHandler('linter.log', 'w')
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
return logger
logger = setup_logging()
#logger.debug(sys.argv)
path = sys.argv[1]
warnings = []
if os.path.isfile(path):
with open(path) as f:
for lineno, line in enumerate(f):
if re.search('ASSERT \(', line) is not None:
warning = {
'severity': 'warning',
'message': 'CPP macros should not have a space between the macro name and their argument list',
'line': lineno+1,
}
warnings.append(warning)
logger.debug(warnings)
print json.dumps(warnings)
......@@ -56,6 +56,11 @@
"check-binaries": {
"type": "external-json",
"external-json.script": "python .arc-linters/check-binaries.py"
},
"bad-assert-clang-cpp": {
"type": "external-json",
"include": ["(\\.(l?hs|x|y\\.pp)(\\.in)?$)"],
"external-json.script": "python .arc-linters/check-cpp.py"
}
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment