[commit: ghc] master: lint: Add linter to catch uses of ASSERT macro that Clang dislikes (901cab1)

git at git.haskell.org git at git.haskell.org
Fri Dec 4 16:31:30 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/901cab10609dc9795e57163834512373530fc4a5/ghc

>---------------------------------------------------------------

commit 901cab10609dc9795e57163834512373530fc4a5
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Fri Dec 4 13:25:26 2015 +0100

    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.


>---------------------------------------------------------------

901cab10609dc9795e57163834512373530fc4a5
 .arc-linters/check-cpp.py | 37 +++++++++++++++++++++++++++++++++++++
 .arclint                  |  5 +++++
 2 files changed, 42 insertions(+)

diff --git a/.arc-linters/check-cpp.py b/.arc-linters/check-cpp.py
new file mode 100755
index 0000000..3794ca2
--- /dev/null
+++ b/.arc-linters/check-cpp.py
@@ -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)
diff --git a/.arclint b/.arclint
index 1b13507..ef43856 100644
--- a/.arclint
+++ b/.arclint
@@ -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"
     }
   },
 



More information about the ghc-commits mailing list