# clang-tidy for the HID-BPF program in src/ (one C file, built for the eBPF
# target with clang, not for the host; see meson.build for the flags).
#
# Run it with the program's own compile flags after "--":
#   --target=bpf -g -O2 -Wall -I include -fms-extensions
#   -Wno-microsoft-anon-tag -D__TARGET_ARCH_x86
#
# The program lives under the rules of the BPF loader: the objects it places in
# SEC(...) sections (maps, the struct_ops, the "probe" syscall program, the
# license string) and the programs it looks up by name must be global, and the
# maps, the struct_ops and the license string must be writable. Those few
# declarations carry a NOLINT with the reason, as do the identifiers that the
# HID_BPF_ASYNC_* macros of include/hid_bpf_async.h generate.
#
# Starting point: Google's published profile,
#   https://github.com/googleapis/google-cloud-cpp/blob/main/.clang-tidy
#   (commit c9bdeeb9e797, 2026-02-18; Apache License 2.0).
# Its check groups and its naming options (CheckOptions below, unchanged) are
# used as they are. Its list of switched-off checks is NOT taken over: the aim
# here is to have as few checks off as possible, and nearly all of that list
# concerns C++ or that project's own code. The groups cert, clang-analyzer,
# concurrency, android, cppcoreguidelines, hicpp and linuxkernel are on in
# addition. Groups that are another project's house rules or another field
# (llvm, llvmlibc, altera, fuchsia, zircon, boost, darwin, mpi, objc, openmp)
# are not part of this.
#
# Switched off, each because it cannot be satisfied here:
#
#  -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling:
#      asks for the C11 Annex K functions (memcpy_s, snprintf_s, fprintf_s),
#      which glibc does not provide.
#
# Everything else that does not apply to a single line of code is marked on
# that line with NOLINT and a reason.
Checks: >
  -*,
  abseil-*,
  android-*,
  bugprone-*,
  cert-*,
  clang-analyzer-*,
  concurrency-*,
  cppcoreguidelines-*,
  google-*,
  hicpp-*,
  linuxkernel-*,
  misc-*,
  modernize-*,
  performance-*,
  portability-*,
  readability-*,
  -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling

# Turn all the warnings from the checks above into errors.
WarningsAsErrors: "*"

# Report only our own file: the headers in include/ are copied unchanged from
# the Linux kernel and udev-hid-bpf, are not ours to edit, and are checked
# there. The regex matches nothing, so no header is reported at all.
HeaderFilterRegex: "^$"

CheckOptions:
  - { key: readability-identifier-naming.NamespaceCase,          value: lower_case }
  - { key: readability-identifier-naming.ClassCase,              value: CamelCase  }
  - { key: readability-identifier-naming.StructCase,             value: CamelCase  }
  - { key: readability-identifier-naming.TemplateParameterCase,  value: CamelCase  }
  - { key: readability-identifier-naming.FunctionCase,           value: aNy_CasE  }
  - { key: readability-identifier-naming.VariableCase,           value: lower_case }
  - { key: readability-identifier-naming.ClassMemberCase,        value: lower_case }
  - { key: readability-identifier-naming.ClassMemberSuffix,      value: _          }
  - { key: readability-identifier-naming.PrivateMemberSuffix,    value: _          }
  - { key: readability-identifier-naming.ProtectedMemberSuffix,  value: _          }
  - { key: readability-identifier-naming.EnumConstantCase,         value: CamelCase }
  - { key: readability-identifier-naming.EnumConstantPrefix,       value: k         }
  - { key: readability-identifier-naming.ConstexprVariableCase,    value: CamelCase }
  - { key: readability-identifier-naming.ConstexprVariablePrefix,  value: k         }
  - { key: readability-identifier-naming.GlobalConstantCase,       value: CamelCase }
  - { key: readability-identifier-naming.GlobalConstantPrefix,     value: k         }
  - { key: readability-identifier-naming.MemberConstantCase,       value: CamelCase }
  - { key: readability-identifier-naming.MemberConstantPrefix,     value: k         }
  - { key: readability-identifier-naming.StaticConstantCase,       value: CamelCase }
  - { key: readability-identifier-naming.StaticConstantPrefix,     value: k         }
  - { key: readability-implicit-bool-conversion.AllowIntegerConditions,  value: 1   }
  - { key: readability-implicit-bool-conversion.AllowPointerConditions,  value: 1   }
  - { key: readability-function-cognitive-complexity.IgnoreMacros,  value: 1   }
  # Added for this program: the kernel's exported headers define __u8, __u32
  # and the errno values in asm-generic/ (reached through <linux/types.h> and
  # <linux/errno.h>), which must not be included directly; the include check
  # is told not to ask for those.
  - { key: misc-include-cleaner.IgnoreHeaders,  value: 'asm-generic/.*' }
  # Added for this program: functions of at most 40 lines.
  - { key: readability-function-size.LineThreshold,  value: 40   }
