diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-09-18 11:34:43 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-25 21:18:17 +0200 |
commit | df4c9b729dace8141ab9e1732b4890446144e993 (patch) | |
tree | 023b11f93c8cb349e51767de4251b29e425b978a /Meta/lint-clang-format.sh | |
parent | a2feef17bf44271f8587ff8c682e1491fe6deed6 (diff) | |
download | serenity-df4c9b729dace8141ab9e1732b4890446144e993.zip |
Meta: Provide script to automatically flag bad formatting
Diffstat (limited to 'Meta/lint-clang-format.sh')
-rwxr-xr-x | Meta/lint-clang-format.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Meta/lint-clang-format.sh b/Meta/lint-clang-format.sh new file mode 100755 index 0000000000..02fcdb7eb7 --- /dev/null +++ b/Meta/lint-clang-format.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e + +script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +cd "${script_path}/.." || exit 1 + +CLANG_FORMAT=false +if command -v clang-format-10 >/dev/null 2>&1 ; then + CLANG_FORMAT=clang-format-10 +elif command -v clang-format >/dev/null 2>&1 ; then + CLANG_FORMAT=clang-format + if ! "${CLANG_FORMAT}" --version | grep -qF ' 10.' ; then + echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 10." + echo "It is very likely that the resulting changes are not what you wanted." + fi +else + echo "clang-format-10 is not available. Either skip this script, or install clang-format-10." + echo "(If you install a package 'clang-format', please make sure it's version 10.)" + exit 1 +fi + +if [ "$#" -eq "1" ] && [ "x--overwrite-inplace" = "x$1" ] ; then + true # The only way to run this script. +else + # Note that this branch also covers --help, -h, -help, -?, etc. + echo "USAGE: $0 --overwrite-inplace" + echo "The argument is necessary to make you aware that this *will* overwrite your local files." + exit 1 +fi + +echo "Running ${CLANG_FORMAT} ..." + +{ + git ls-files -- \ + '*.cpp' \ + '*.h' \ + ':!:Base' \ + ':!:Kernel/Arch/i386/CPU.cpp' \ + ':!:Kernel/FileSystem/ext2_fs.h' \ + ':!:Libraries/LibC/getopt.cpp' \ + ':!:Libraries/LibC/syslog.h' \ + ':!:Libraries/LibCore/puff.h' \ + ':!:Libraries/LibCore/puff.cpp' \ + ':!:Libraries/LibELF/exec_elf.h' \ + || echo "'git ls-files failed!'" +} | xargs -d'\n' clang-format-10 -style=file -i + +echo "Maybe some files have changed. Sorry, but clang-format doesn't indicate what happened." |