Add linter to check for binaries accidentally added to repository
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 4 Dec 2015 12:14:27 +0000 (13:14 +0100)
committerBen Gamari <ben@smart-cactus.org>
Fri, 4 Dec 2015 16:31:14 +0000 (17:31 +0100)
This should catch mistakes like
a703fbce20969e6f02e74fee76c0a9e22b513426.

Adds an arcanist-external-json-linter submodule, which should eventually
be mirrored on haskell.org resources.

Test Plan: Validate

Reviewers: thomie, hvr, austin

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D1515

.arc-linters/arcanist-external-json-linter [new submodule]
.arc-linters/check-binaries.py [new file with mode: 0755]
.arcconfig
.arclint
.gitmodules

diff --git a/.arc-linters/arcanist-external-json-linter b/.arc-linters/arcanist-external-json-linter
new file mode 160000 (submodule)
index 0000000..85ece0f
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 85ece0f8653e7b1e7de6024d372cfeaf36ab5fa9
diff --git a/.arc-linters/check-binaries.py b/.arc-linters/check-binaries.py
new file mode 100755 (executable)
index 0000000..ae00756
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+# A linter to warn when binary files are added to the repository
+
+import sys
+import os
+import json
+
+path = sys.argv[1]
+warnings = []
+if os.path.isfile(path):
+    with open(path) as f:
+        if '\0' in f.read(8000):
+            warning = {
+                'severity': 'warning',
+                'message': 'This file appears to be a binary file; does it really belong in the repository?'
+            }
+            warnings.append(warning)
+
+print json.dumps(warnings)
index b9c3932..c886789 100644 (file)
@@ -1,5 +1,9 @@
 {
   "project.name"        : "ghc",
   "repository.callsign" : "GHC",
-  "phabricator.uri"     : "https://phabricator.haskell.org"
+  "phabricator.uri"     : "https://phabricator.haskell.org",
+
+  "load": [
+    ".arc-linters/arcanist-external-json-linter"
+  ]
 }
index 8f83776..1b13507 100644 (file)
--- a/.arclint
+++ b/.arclint
       "severity": {
         "2": "disabled"
       }
+    },
+    "check-binaries": {
+      "type": "external-json",
+      "external-json.script": "python .arc-linters/check-binaries.py"
     }
   },
 
index 662f6d6..0d88e01 100644 (file)
        path = libffi-tarballs
        url = ../libffi-tarballs.git
        ignore = none
+[submodule ".arc-linters/arcanist-external-json-linter"]
+       path = .arc-linters/arcanist-external-json-linter
+       url = https://github.com/bgamari/arcanist-external-json-linter.git