# clang-tidy's checks for our C++. Run them with the build's `tidy` target:
#   uv run cmake --build --preset dev --target tidy
#
# A new clang-tidy's new checks are adopted: the code changes to pass them,
# and a check is switched off only with its reason written beside its name,
# as below. The net grows over time. 🚧 Families not yet on, the candidates
# for more: cert-*, cppcoreguidelines-*, misc-*, concurrency-*.
Checks:
  - bugprone-*
  - clang-analyzer-*
  - google-*
  - modernize-*
  - performance-*
  - portability-*
  - readability-*

  # Switched off, each for a reason:

  # Any two parameters of one type "could be swapped". True of most functions
  # that take an address and a value.
  - -bugprone-easily-swappable-parameters
  # `auto f() -> int` everywhere is not Google style.
  - -modernize-use-trailing-return-type
  # [[nodiscard]] on every getter is noise.
  - -modernize-use-nodiscard
  # Asks for a one-byte base type on every small enum.
  - -performance-enum-size
  # Google style allows `if (done) return;` on one line with no braces. The
  # google- version of this check allows it too, and stays on.
  - -readability-braces-around-statements
  # A method that does not touch `this` is often still part of an interface
  # that someone else calls on an object: a coroutine's promise, a TLM
  # target. Platform's methods act on the one SystemC kernel, not on members.
  - -readability-convert-member-functions-to-static
  # Short names such as `it` and `id` are fine.
  - -readability-identifier-length
  # Addresses, sizes and test data are numbers; naming each one would bury
  # the code.
  - -readability-magic-numbers
  # A virtual function called from a constructor or a destructor that is
  # not pure, and so merely does not reach an override. A pure one, which
  # is undefined behaviour, is clang-analyzer-cplusplus.PureVirtualCall's,
  # and stays on. The analyzer follows a path from the QBox CPU's adapter
  # into QBox's own destructor, which calls one of its own, and reports it
  # there, in a header nothing here can mark (docs/upstream.md).
  - -clang-analyzer-optin.cplusplus.VirtualCall
  # Leaving a parameter unnamed is how C++ says it is unused.
  - -readability-named-parameter

# Every finding fails the run. A check that is not worth failing for is not
# worth having on.
WarningsAsErrors: '*'

# The register maps' headers are left alone. They are generated
# (tools/regs.py), and they are C, because the Zephyr drivers include the
# same files: nothing but #define, which is what these checks would have
# us replace. So are the headers under src/vpvper/, which are written in
# MINRES's style for VPV-Peripherals, to be offered upstream; its one source
# file, rvi/iommu.cpp, is in the tidy target with ours.
ExcludeHeaderFilterRegex: '.*/zephyr_module/include/socpuppet/regs/.*|.*/src/vpvper/.*'

CheckOptions:
  # Count the complexity a person reads, not what gtest's EXPECT_ macros
  # expand to.
  readability-function-cognitive-complexity.IgnoreMacros: true

  # Google's names. Types and functions are CamelCase, variables are
  # lower_case, a private member ends in an underscore, and a constant is a
  # k followed by CamelCase.
  readability-identifier-naming.NamespaceCase: lower_case
  readability-identifier-naming.ClassCase: CamelCase
  readability-identifier-naming.StructCase: CamelCase
  readability-identifier-naming.EnumCase: CamelCase
  readability-identifier-naming.TypeAliasCase: CamelCase
  readability-identifier-naming.TypedefCase: CamelCase
  readability-identifier-naming.TemplateParameterCase: CamelCase
  readability-identifier-naming.ConceptCase: CamelCase
  readability-identifier-naming.FunctionCase: CamelCase
  # Names we do not get to choose:
  #   - TLM-2.0 calls a target's transport functions by these names, and
  #     anyone who has met TLM elsewhere knows them.
  #   - The compiler calls a coroutine's promise and awaiters by these names
  #     (see core/script.h).
  #   - SystemC's library calls sc_main (platform/sc_main_stub.cpp).
  readability-identifier-naming.FunctionIgnoredRegexp: '^(sc_main|b_transport|nb_transport_fw|nb_transport_bw|transport_dbg|get_direct_mem_ptr|invalidate_direct_mem_ptr|get_return_object|initial_suspend|final_suspend|return_void|return_value|unhandled_exception|await_transform|await_ready|await_suspend|await_resume|yield_value)$'
  readability-identifier-naming.StructIgnoredRegexp: '^promise_type$'
  readability-identifier-naming.VariableCase: lower_case
  readability-identifier-naming.ParameterCase: lower_case
  readability-identifier-naming.MemberCase: lower_case
  readability-identifier-naming.PrivateMemberSuffix: _
  readability-identifier-naming.ProtectedMemberSuffix: _
  readability-identifier-naming.EnumConstantCase: CamelCase
  readability-identifier-naming.EnumConstantPrefix: k
  readability-identifier-naming.ConstexprVariableCase: CamelCase
  readability-identifier-naming.ConstexprVariablePrefix: k
  readability-identifier-naming.GlobalConstantCase: CamelCase
  readability-identifier-naming.GlobalConstantPrefix: k
  readability-identifier-naming.ClassConstantCase: CamelCase
  readability-identifier-naming.ClassConstantPrefix: k
