Remove clang tidy from hooks (#94)

* Removed clang-tidy from hooks

* Improved clang-format output

* Remove lcp from types to format
This commit is contained in:
antonio2368 2021-02-16 11:22:59 +01:00 committed by GitHub
parent cc1c1513ef
commit 435af8b833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 24 deletions

View File

@ -15,7 +15,7 @@ exec 1>&2
tmpdir=$(mktemp -d repo-XXXXXXXX)
trap "rm -rf $tmpdir" EXIT INT
modified_files=$(git diff --cached --name-only --diff-filter=AM $against | sed -nE "/.*\.(cpp|cc|cxx|c|h|hpp|lcp)$/p")
modified_files=$(git diff --cached --name-only --diff-filter=AM $against | sed -nE "/.*\.(cpp|cc|cxx|c|h|hpp)$/p")
for file in $modified_files; do
echo "Checking $file..."
@ -30,14 +30,6 @@ for file in $modified_files; do
if [ $code -ne 0 ]; then
break
fi
echo "Running clang-tidy..."
$project_folder/tools/git-clang-tidy $tmpdir/$file
code=$?
if [ $code -ne 0 ]; then
break
fi
done;
return $code

View File

@ -2,22 +2,46 @@
import re
import sys
import subprocess
import difflib
# Run this script through arc lint
MESSAGE = "Wrong formatting!"
def colorize(diff_lines):
def bold(s):
return '\x1b[1m' + s + '\x1b[0m'
data = subprocess.run(
["clang-format", "--output-replacements-xml", sys.argv[1]],
stdout=subprocess.PIPE, check=True).stdout.decode(
"utf-8").strip().split("\n")
has_error = False
for row in data:
match = re.match(
r"^<replacement offset='([0-9]+)' length='([0-9]+)'>", row)
if match:
has_error = True
offset = int(match.group(1)) + int(match.group(2))
print("warning:{}:{}".format(offset, MESSAGE))
def cyan(s):
return '\x1b[36m' + s + '\x1b[0m'
sys.exit(1 if has_error else 0)
def green(s):
return '\x1b[32m' + s + '\x1b[0m'
def red(s):
return '\x1b[31m' + s + '\x1b[0m'
for line in diff_lines:
if line[:4] in ['--- ', '+++ ']:
yield bold(line)
elif line.startswith('@@ '):
yield cyan(line)
elif line.startswith('+'):
yield green(line)
elif line.startswith('-'):
yield red(line)
else:
yield line
proc = subprocess.Popen(
["clang-format", sys.argv[1]],
stdout=subprocess.PIPE, encoding='utf-8')
with open(sys.argv[1], 'r') as original:
diff_lines = list(
difflib.unified_diff(
original.readlines(),
proc.stdout.readlines(),
fromfile="unformatted",
tofile="formatted",
n=3))
sys.stdout.writelines(colorize(diff_lines))
sys.exit(1 if len(diff_lines) > 0 else 0)