22# Clang-tidy configuration for sqlite-diskann
33# Focus on C best practices, memory safety, and SQLite extension patterns
44
5+ # ============================================================================
6+ # CHECKS: What to enable and suppress
7+ # ============================================================================
8+ # - Start with nothing: -*
9+ # - Enable category: bugprone-*
10+ # - Suppress specific: -bugprone-easily-swappable-parameters
11+ # - NO inline comments in the Checks string (they break clang-tidy parsing!)
12+ #
513Checks : '
614 -*,
715 bugprone-*,
816 -bugprone-easily-swappable-parameters,
917 -bugprone-misplaced-widening-cast,
1018 -bugprone-multi-level-implicit-pointer-conversion,
1119 cert-*,
20+ -cert-err33-c,
1221 -cert-err58-cpp,
1322 -cert-msc30-c,
1423 -cert-msc32-c,
1524 -cert-msc50-cpp,
1625 -cert-msc51-cpp,
1726 clang-analyzer-*,
1827 -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
28+ -clang-analyzer-deadcode.DeadStores,
1929 cppcoreguidelines-*,
2030 -cppcoreguidelines-avoid-magic-numbers,
31+ -cppcoreguidelines-avoid-non-const-global-variables,
2132 -cppcoreguidelines-init-variables,
2233 -cppcoreguidelines-macro-to-enum,
2334 -cppcoreguidelines-pro-bounds-pointer-arithmetic,
@@ -26,6 +37,7 @@ Checks: '
2637 misc-*,
2738 -misc-include-cleaner,
2839 performance-*,
40+ -performance-no-int-to-ptr,
2941 readability-*,
3042 -readability-braces-around-statements,
3143 -readability-else-after-return,
@@ -34,10 +46,52 @@ Checks: '
3446 -readability-isolate-declaration,
3547 -readability-magic-numbers,
3648 -readability-uppercase-literal-suffix,
37- -performance-no-int-to-ptr,
38- -clang-analyzer-deadcode.DeadStores
3949'
4050
51+ # ============================================================================
52+ # SUPPRESSION RATIONALE
53+ # ============================================================================
54+ #
55+ # Bug Detection:
56+ # -bugprone-easily-swappable-parameters → SQLite APIs have many similar params
57+ # -bugprone-misplaced-widening-cast → False positives in distance calcs
58+ # -bugprone-multi-level-implicit-pointer-conversion → SQLite void* patterns
59+ #
60+ # CERT Security:
61+ # -cert-err33-c → SQLite APIs intentionally ignore returns (sqlite3_finalize)
62+ # -cert-msc30-c/32-c → rand() in tests is acceptable
63+ # -cert-*-cpp → C++ only checks
64+ #
65+ # Static Analysis:
66+ # -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling → We validate manually
67+ # -clang-analyzer-deadcode.DeadStores → False positives with cleanup patterns
68+ #
69+ # C++ Core Guidelines (adapted for C):
70+ # -cppcoreguidelines-avoid-magic-numbers → Test constants are fine
71+ # -cppcoreguidelines-avoid-non-const-global-variables → SQLite extensions need module state
72+ # -cppcoreguidelines-init-variables → Defensive init is selective
73+ # -cppcoreguidelines-macro-to-enum → SQLite macros intentional
74+ # -cppcoreguidelines-pro-bounds-pointer-arithmetic → Required for vector math/traversal
75+ # -cppcoreguidelines-pro-type-reinterpret-cast → BLOB serialization needs it
76+ # -cppcoreguidelines-pro-type-union-access → SQLite sqlite3_value union
77+ #
78+ # Misc:
79+ # -misc-include-cleaner → Too aggressive with vendored SQLite
80+ #
81+ # Performance:
82+ # -performance-no-int-to-ptr → SQLite ROWID casting patterns
83+ #
84+ # Readability:
85+ # -readability-braces-around-statements → Single-line if/for allowed
86+ # -readability-else-after-return → Explicit control flow preferred
87+ # -readability-function-cognitive-complexity → Some algorithms inherently complex
88+ # -readability-identifier-length → Short names (i, j, k, rc, db) are idiomatic
89+ # -readability-isolate-declaration → Multiple declarations allowed
90+ # -readability-magic-numbers → Duplicates avoid-magic-numbers
91+ # -readability-uppercase-literal-suffix → 1.0f clearer than 1.0F
92+ #
93+ # ============================================================================
94+
4195# Treat warnings as errors
4296WarningsAsErrors : ' '
4397
@@ -47,23 +101,77 @@ HeaderFilterRegex: '^src/.*\.h$'
47101# Format style
48102FormatStyle : file
49103
50- # Check options — naming conventions match SQLite's CamelCase for types
104+ # ============================================================================
105+ # Naming Conventions
106+ # ============================================================================
107+ # Base rule: snake_case for code we write
108+ # Exceptions: SQLite's Hungarian notation and vtab callback patterns
109+ #
110+ # SQLite Hungarian Notation Guide:
111+ # p* = pointer (pVtab, ppCursor, pzErr)
112+ # z* = zero-terminated string (zName, zSql)
113+ # i* = integer (iCol, idxNum, idxStr)
114+ # n* = count/size (nConstraint, nOrderBy, nArg)
115+ # a* = array (aConstraint, aOrderBy, argv)
116+ # x* = method/callback (xCreate, xFilter, xBestIndex)
117+ #
51118CheckOptions :
119+ # --------------------------------------------------------------------------
120+ # Functions: snake_case for our code, camelCase for SQLite callbacks
121+ # --------------------------------------------------------------------------
52122 - key : readability-identifier-naming.FunctionCase
53123 value : lower_case
124+ - key : readability-identifier-naming.FunctionIgnoredRegexp
125+ value : ' ^(diskann[A-Z][a-zA-Z0-9]*|sqlite3_[a-z0-9_]+|x[A-Z][a-zA-Z]*)$'
126+ # Matches: diskannCreate, diskannBestIndex, sqlite3_malloc, xCreate, xFilter
127+
128+ # --------------------------------------------------------------------------
129+ # Variables: snake_case for our code, Hungarian for SQLite interop
130+ # --------------------------------------------------------------------------
54131 - key : readability-identifier-naming.VariableCase
55132 value : lower_case
133+ - key : readability-identifier-naming.VariableIgnoredRegexp
134+ value : ' ^([pzian][A-Z][a-zA-Z0-9]*|idx[A-Z][a-zA-Z0-9]*|x[A-Z][a-zA-Z]*|diskannModule)$'
135+ # Matches: pVtab, zName, iCol, nConstraint, aConstraint, idxNum, xFilter, diskannModule
136+ # Hungarian notation + SQLite module name
137+
138+ # --------------------------------------------------------------------------
139+ # Parameters: snake_case for our code, Hungarian for SQLite API params
140+ # --------------------------------------------------------------------------
56141 - key : readability-identifier-naming.ParameterCase
57142 value : lower_case
143+ - key : readability-identifier-naming.ParameterIgnoredRegexp
144+ value : ' ^([pzian]{1,2}[A-Z][a-zA-Z0-9]*|idx[A-Z][a-zA-Z0-9]*|pApi|argc|argv)$'
145+ # Matches: pVtab, ppCursor, pzErr, zName, iCol, nConstraint, aOrderBy, idxNum, pApi
146+ # Note: {1,2} allows both pVar and ppVar (pointer to pointer)
147+
148+ # --------------------------------------------------------------------------
149+ # Constants and Macros: SCREAMING_SNAKE_CASE
150+ # --------------------------------------------------------------------------
58151 - key : readability-identifier-naming.ConstantCase
59152 value : UPPER_CASE
60153 - key : readability-identifier-naming.MacroDefinitionCase
61154 value : UPPER_CASE
155+ - key : readability-identifier-naming.GlobalConstantCase
156+ value : UPPER_CASE
157+
158+ # --------------------------------------------------------------------------
159+ # Types: CamelCase (our convention), snake_case for SQLite interop
160+ # --------------------------------------------------------------------------
62161 - key : readability-identifier-naming.StructCase
63162 value : CamelCase
163+ - key : readability-identifier-naming.StructIgnoredRegexp
164+ value : ' ^(diskann_[a-z_]+|sqlite3_[a-z_]+)$'
165+ # Matches: diskann_vtab, diskann_cursor, sqlite3_vtab, sqlite3_index_info
166+
64167 - key : readability-identifier-naming.TypedefCase
65168 value : CamelCase
66- - key : readability-identifier-naming.GlobalConstantCase
67- value : UPPER_CASE
169+ - key : readability-identifier-naming.TypedefIgnoredRegexp
170+ value : ' ^(diskann_[a-z_]+|sqlite3_[a-z_]+)$'
171+ # Matches: diskann_vtab, sqlite3_module, etc.
172+
173+ # --------------------------------------------------------------------------
174+ # Performance tweaks
175+ # --------------------------------------------------------------------------
68176 - key : performance-move-const-arg.CheckTriviallyCopyableMove
69177 value : false
0 commit comments