From 8f6639470664f1fa1e4bf05b1b26b43aae4a3136 Mon Sep 17 00:00:00 2001
From: Luca Erbetta <luca.erbetta@skywarder.eu>
Date: Tue, 5 Mar 2019 22:15:30 +0100
Subject: [PATCH] [SCRIPTS] Added linter

---
 scripts/cppcheck_suppressions_list.txt |  2 ++
 scripts/linter.sh                      | 38 ++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 scripts/cppcheck_suppressions_list.txt
 create mode 100644 scripts/linter.sh

diff --git a/scripts/cppcheck_suppressions_list.txt b/scripts/cppcheck_suppressions_list.txt
new file mode 100644
index 000000000..84fbc0df2
--- /dev/null
+++ b/scripts/cppcheck_suppressions_list.txt
@@ -0,0 +1,2 @@
+*:src/tests/*
+
diff --git a/scripts/linter.sh b/scripts/linter.sh
new file mode 100644
index 000000000..79792ccfa
--- /dev/null
+++ b/scripts/linter.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+declare -i RESULT=0
+
+function check {
+    B=$(eval "$3")
+    A=$?
+    echo -n "[LINTER] $2... "
+
+    if [ "$1" == "OUT" ]; then
+        if [ ${#B} -gt 0 ]; then
+            A=$1
+        fi;
+    fi;
+    if [ "$A" == "$1" ]; then
+        echo -e "FAIL\n------------ OUTPUT ------------"
+        echo "$B"
+        echo "--------------------------------"
+        return 1
+    else
+        echo "OK"
+        return 0
+    fi;
+}
+
+#check 0 "Checking for files with lines longer than 80 characters" 'egrep --include="*.cpp" --include="*.h" -nr ".{81}" src/' 
+check 0 "Checking for files with lines longer than 120 characters" 'egrep --include="*.cpp" --include="*.h" -nr ".{121}" src/' 
+RESULT+=$?
+check OUT "Checking for files having \n\n\n" "grep -HPcrz '(\\r?\\n){4,}' src | egrep -v ':0$' | cut -d ':' -f 1"
+check OUT "Checking for files not having the copyright" "grep -rL '* Permission is hereby granted, free of charge' src/"
+check OUT "Checking for tabulations instead of spaces" "grep -Pr '\t' src"
+check OUT "MMP wants his full name" "grep -rl 'Matteo Piazzolla' src/"
+check OUT "Launching cppcheck" "cppcheck  --suppressions-list=./scripts/cppcheck_suppressions_list.txt --template=gcc -q --suppress=unusedFunction --suppress=missingInclude --std=c++11 --enable=all src/ 2>&1"
+RESULT+=$?
+check OUT "Checking for using namespace in header files" "grep -rl 'using namespace' src | egrep '.h(pp)?$'"
+RESULT+=$?
+
+exit 0
-- 
GitLab