From 3af8f7147256f8bfe1b3bffa7828e5b9ce52ce58 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 24 Jun 2016 13:23:10 +0200 Subject: [PATCH] linter: run clang-format and fail on diffs --- Tools/lint.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Tools/lint.sh b/Tools/lint.sh index 70cb812877..4e502bdd4b 100755 --- a/Tools/lint.sh +++ b/Tools/lint.sh @@ -1,22 +1,23 @@ -#! /bin/sh +#! /bin/bash # # Linter script that checks for common style issues in Dolphin's codebase. -REPO_BASE=$(realpath $(dirname $0)/..) - fail=0 -# Step 1: check for trailing whitespaces. -echo "[.] Checking for trailing whitespaces." -res=$( - find ${REPO_BASE}/Source/Core -name "*.cpp" -o -name "*.h" \ - | xargs egrep -n "\s+$" -) -if [ -n "$res" ]; then - echo "FAIL: ${res}" - fail=1 -else - echo "OK" -fi +# Check for clang-format issues. +git status --porcelain | awk '{print $2}' | while read f; do + if ! echo "${f}" | egrep -q "[.](cpp|h|mm)$"; then + continue + fi + if ! echo "${f}" | egrep -q "^Source/Core"; then + continue + fi + d=$(diff -u "${f}" <(clang-format ${f})) + if ! [ -z "${d}" ]; then + echo "!!! ${f} not compliant to coding style, here is the fix:" + echo "${d}" + fail=1 + fi +done exit ${fail}