lint: Add linter to catch uses of ASSERT macro that Clang dislikes
authorBen Gamari <ben@smart-cactus.org>
Fri, 4 Dec 2015 12:25:26 +0000 (13:25 +0100)
committerBen Gamari <ben@smart-cactus.org>
Fri, 4 Dec 2015 16:31:55 +0000 (17:31 +0100)
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.

.arc-linters/check-cpp.py [new file with mode: 0755]
.arclint

diff --git a/.arc-linters/check-cpp.py b/.arc-linters/check-cpp.py
new file mode 100755 (executable)
index 0000000..3794ca2
--- /dev/null
@@ -0,0 +1,37 @@
+#!/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)
index 1b13507..ef43856 100644 (file)
--- a/.arclint
+++ b/.arclint
     "check-binaries": {
       "type": "external-json",
       "external-json.script": "python .arc-linters/check-binaries.py"
     "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"
     }
   },
 
     }
   },