# SPDX-License-Identifier: GPL-3.0-or-later
# clang-tidy configuration for olduvai.
#
# Deliberately CONSERVATIVE.  This is a trace-validated engine: behaviour is
# pinned by a zero-tolerance per-frame oracle diff, and docs/internal/
# OOP_SOLID_AUDIT.md Section B is an explicit DO-NOT-abstract list.  So the
# check set is chosen for SIGNAL (real defects + honest size metrics), not for
# style churn:
#
#   enabled   bugprone / performance / clang-analyzer  — real defects
#             misc-*                                   — dead code, header hygiene
#             readability-function-size                — the size KPIs
#             readability-function-cognitive-complexity
#             a few readability-* that catch genuine mistakes
#
#   NOT enabled, on purpose:
#     modernize-*            churn across a stable C++17 tree; would rewrite
#                            thousands of lines the oracle diff must re-prove
#     cppcoreguidelines-*    opinionated; fights the deliberately data-oriented
#                            core (free functions over plain structs is WHY the
#                            oracle diff works)
#     readability-identifier-naming  the naming is consistent already
#     google-/fuchsia-/llvm-*        foreign house styles
#     performance-enum-size  fires on ~12 enums; changing an enum's base type
#                            on a trace-validated engine risks struct layout and
#                            save/serialisation for no measurable gain
#     bugprone-incorrect-roundings   all 24 hits are ONE idiom,
#                            static_cast<int>(v * scale + 0.5) — the HD/widescreen
#                            coordinate round.  The suggested std::lround is NOT
#                            equivalent: it rounds half away from zero, while
#                            +0.5-then-truncate rounds toward zero for negative
#                            operands.  So "fixing" them is a BEHAVIOUR CHANGE on
#                            a trace-validated engine, applied to 24 sites in
#                            presentation code the oracle diff does not cover,
#                            to fix zero known defects.  Measured 2026-07-30.
#     bugprone-implicit-widening-of-multiplication-result
#                            32 hits, all buffer-index math of the shape
#                            static_cast<size_t>(y * k) * w + x * k.  Every
#                            dimension is bounded by the 320x200 surface times a
#                            small HD scale, so the widest index is ~9.2M — three
#                            orders of magnitude below INT_MAX, and no input can
#                            grow them (the surface size is the format's, not the
#                            user's).  The check is right in general and wrong
#                            here; moving the casts would be churn in exactly the
#                            trace-sensitive render code this file avoids
#                            churning.  Re-open if a scaler ever takes an
#                            unbounded dimension.
#
# Widened 2026-09-27 (BACKLOG §3.42), each finding fixed first: member
# initialisation, rule of five, override, member-const, static members,
# emplace, any_of/all_of, boolean simplification WITHOUT De Morgan (the EXE-
# shaped conditions in systems/ keep their cited shape), const locals (scope
# guards exempt), and the checks that already found nothing, so they stay at
# nothing.  Measured and NOT enabled:
#     cppcoreguidelines-prefer-member-initializer  its fix hoisted two
#                            margin computations above the SDL call that
#                            feeds them (WidescreenPresenter, BossWidescreen)
#
# readability-function-size is used as a MEASUREMENT, not a hard rule: the
# thresholds are set to flag genuine monsters (run_platform_level,
# run_boss_level) and not ordinary code.  NestingThreshold and VariableThreshold
# are the two that actually predict "hard to read" — the live-local count is
# what makes a function hard to extract from.
Checks: >
  -*,
  bugprone-*,
  -bugprone-easily-swappable-parameters,
  -bugprone-narrowing-conversions,
  -bugprone-incorrect-roundings,
  -bugprone-implicit-widening-of-multiplication-result,
  performance-*,
  -performance-enum-size,
  clang-analyzer-*,
  misc-definitions-in-headers,
  misc-redundant-expression,
  misc-unused-alias-decls,
  misc-unused-using-decls,
  readability-function-size,
  readability-function-cognitive-complexity,
  readability-misleading-indentation,
  readability-redundant-control-flow,
  readability-redundant-string-init,
  readability-inconsistent-declaration-parameter-name,
  cppcoreguidelines-pro-type-member-init,
  cppcoreguidelines-special-member-functions,
  cppcoreguidelines-virtual-class-destructor,
  cppcoreguidelines-slicing,
  modernize-use-override,
  modernize-use-nullptr,
  modernize-use-equals-default,
  modernize-use-equals-delete,
  modernize-use-using,
  modernize-redundant-void-arg,
  modernize-use-emplace,
  misc-unused-parameters,
  readability-else-after-return,
  readability-simplify-boolean-expr,
  readability-container-size-empty,
  readability-make-member-function-const,
  readability-convert-member-functions-to-static,
  readability-non-const-parameter,
  readability-redundant-member-init,
  readability-redundant-declaration,
  readability-qualified-auto,
  readability-static-accessed-through-instance,
  readability-duplicate-include,
  readability-avoid-const-params-in-decls,
  readability-const-return-type,
  readability-delete-null-pointer,
  readability-use-anyofallof,
  readability-string-compare,
  readability-redundant-smartptr-get,
  misc-const-correctness

CheckOptions:
  # Flag only genuine monsters — ordinary 100-line functions are fine here.
  readability-function-size.LineThreshold: 200
  readability-function-size.StatementThreshold: 200
  readability-function-size.BranchThreshold: 40
  readability-function-size.ParameterThreshold: 8
  # The two that actually track readability:
  readability-function-size.NestingThreshold: 6
  readability-function-size.VariableThreshold: 40
  readability-function-cognitive-complexity.Threshold: 50
  readability-function-cognitive-complexity.IgnoreMacros: true
  # Conditions mirroring the EXE's branches keep their shape.
  readability-simplify-boolean-expr.SimplifyDeMorgan: false
  # Deleting copy leaves the class non-movable, which is the intent; a
  # defaulted virtual destructor alone marks an interface.
  cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
  cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: true
  cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: true
  # Scope guards live for their destructor; const on them says nothing.
  misc-const-correctness.AllowedTypes: 'FrameStats::Timer;OvTimer;std::lock_guard;std::unique_lock;std::scoped_lock'

# Only our own sources; vendored third_party (Nuked-OPL3, doctest) is exempt.
HeaderFilterRegex: '^.*/src/(formats|prepare|core|systems|enhance|presentation|app|trace)/.*\.hpp$'
WarningsAsErrors: ''
