# Static analysis for the C++ in cpp/: the C++ Core Guidelines checks plus the
# bug, security (CERT), analyzer, modernisation, performance and readability
# families. Every warning is an error; tests/lint.test.mjs runs it.
Checks: >
  bugprone-*,
  cert-*,
  clang-analyzer-*,
  concurrency-*,
  cppcoreguidelines-*,
  misc-*,
  modernize-*,
  performance-*,
  portability-*,
  readability-*,
  -modernize-use-trailing-return-type,
  -bugprone-easily-swappable-parameters,
  -portability-avoid-pragma-once,
  -cppcoreguidelines-use-enum-class
# Off on purpose:
# - use-trailing-return-type: `auto f() -> int` is a style choice the
#   guidelines do not make; their examples use `int f()`.
# - avoid-pragma-once: every compiler dmakit builds with supports it, and 69 headers would each
#   need a guard name kept unique by hand.
# - use-enum-class: dma_data_direction keeps the kernel's unscoped names (DMA_TO_DEVICE) so the
#   code reads side by side with Linux.
# - easily-swappable-parameters: the DMA functions keep the Linux kernel's
#   signatures (dma_map_single(dev, phys, size, dir)) so they read side by side
#   with the kernel and the JavaScript twin. Fixing it means distinct address
#   types across the whole API, a redesign of its own.
WarningsAsErrors: '*'
# compile_flags.txt holds the warnings both compilers share (the tests and CMake read it too); clang
# alone adds everything else it has. Off: weak-vtables and exit-time-destructors are what a header-only
# library with polymorphic bases and namespace-scope tables costs; global-constructors is the same
# tables; the rest is C++98 and padding noise. -Weverything grows with each clang release, so a
# toolchain bump may need new -Wno- entries here.
ExtraArgs: ['-Weverything', '-Wno-c++98-compat', '-Wno-c++98-compat-pedantic', '-Wno-padded', '-Wno-weak-vtables', '-Wno-exit-time-destructors', '-Wno-global-constructors']
HeaderFilterRegex: '.*/dmakit/.*\.hpp$'
FormatStyle: file
CheckOptions:
  # C.2/C.8: a type whose members are all public is a plain struct and fine.
  misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
  cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
  # NL.10 underscore_style, with types in CamelCase (the guidelines' own
  # "Stroustrup" variant).
  readability-identifier-naming.NamespaceCase: lower_case
  readability-identifier-naming.ClassCase: CamelCase
  readability-identifier-naming.StructCase: CamelCase
  readability-identifier-naming.FunctionCase: lower_case
  readability-identifier-naming.MethodCase: lower_case
  readability-identifier-naming.VariableCase: lower_case
  readability-identifier-naming.ParameterCase: lower_case
  readability-identifier-naming.MemberCase: lower_case
  # Names copied from the Linux kernel and the AMD IOMMU specification
  # (PAGE_SIZE, DMA_TO_DEVICE, IO_PAGE_FAULT) keep their spelling, so a reader
  # can search for them in those sources.
  readability-identifier-naming.GlobalConstantIgnoredRegexp: '^[A-Z][A-Z0-9_]*$'
  readability-identifier-naming.EnumConstantIgnoredRegexp: '^[A-Z][A-Z0-9_]*$'
  # readability-function-size: no function body over this many lines. A ceiling just above the
  # longest library function, so no new giant lands; the target is far lower (see the README's
  # "Code style"). Library, examples and tests share this one ceiling.
  readability-function-size.LineThreshold: 125
