#!/bin/bash

if [ -z "${MESON_SOURCE_ROOT}" ]; then
    echo "[ERROR] This script can only be ran with meson!"
    exit 1
fi

cd "${MESON_SOURCE_ROOT}"

tidy_checks="*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,\
-fuchsia-default-arguments,-fuchsia-overloaded-operator,-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-hicpp-avoid-c-arrays,-google-readability-casting,-cppcoreguidelines-pro-bounds-constant-array-index,\
-modernize-avoid-c-arrays,-cppcoreguidelines-avoid-c-arrays,-modernize-use-equals-default,-hicpp-use-equals-default,\
-google-runtime-references,-google-explicit-constructor,-hicpp-explicit-conversions,\
-misc-non-private-member-variables-in-classes,-cppcoreguidelines-special-member-functions,-modernize-use-nodiscard,\
-hicpp-special-member-functions,-llvm-header-guard,-google-runtime-int,-readability-isolate-declaration,\
-fuchsia-default-arguments-calls,-modernize-use-trailing-return-type,-bugprone-branch-clone,\
-fuchsia-default-arguments-declarations,-cppcoreguidelines-pro-type-union-access,\
-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-vararg,-android-cloexec-pipe,\
-hicpp-signed-bitwise,-cert-err58-cpp,-hicpp-vararg,-abseil-string-find-startswith,-misc-definitions-in-headers,\
-clang-analyzer-valist.Uninitialized,-android-cloexec-open,-cppcoreguidelines-owning-memory,\
-cppcoreguidelines-non-private-member-variables-in-classes,-fuchsia-statically-constructed-objects,\
-modernize-return-braced-init-list,-clang-analyzer-unix.Vfork,-clang-analyzer-security.insecureAPI.vfork,\
-cppcoreguidelines-init-variables,readability-identifier-naming,-google-readability-todo,\
-cppcoreguidelines-macro-usage,-cppcoreguidelines-pro-type-reinterpret-cast,-llvmlibc-*"

tidy_options="[
  { key: readability-identifier-naming.ClassCase,                 value: CamelCase },
  { key: readability-identifier-naming.VariableCase,              value: lower_case },
  { key: readability-identifier-naming.FunctionCase,              value: lower_case },
  { key: readability-identifier-naming.ParameterCase,             value: lower_case },
  { key: readability-identifier-naming.GlobalConstantCase,        value: UPPER_CASE },
  { key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE },
  { key: readability-identifier-naming.StaticConstantCase,        value: UPPER_CASE },
  { key: readability-identifier-naming.ConstexprVariableCase,     value: UPPER_CASE },
]"

files=$(scripts/get_include_files)
clang-tidy -warnings-as-errors='*' -config="{Checks: '$tidy_checks', CheckOptions: $tidy_options}" $files -- \
-std=c++11 -Iinclude $@