tools: add check-imports.sh script
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 5 Jul 2013 20:42:06 +0000 (22:42 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 6 Jul 2013 15:44:45 +0000 (17:44 +0200)
Checks that `using` statements in src/*.cc are properly sorted and
actually used.

tools/check-imports.sh [new file with mode: 0755]

diff --git a/tools/check-imports.sh b/tools/check-imports.sh
new file mode 100755 (executable)
index 0000000..54cba93
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+cd `dirname "$0"`/../
+
+for FILE in src/*.cc; do
+  sed -rne 's/^using (\w+::\w+);$/\1/p' $FILE | sort -c || echo "in $FILE"
+done
+
+for FILE in src/*.cc; do
+  for IMPORT in `sed -rne 's/^using (\w+)::(\w+);$/\2/p' $FILE`; do
+    if ! sed -re '/^using (\w+)::(\w+);$/d' $FILE | grep -q "$IMPORT"; then
+      echo "$IMPORT unused in $FILE"
+    fi
+  done
+done