rustqual 1.2.3

Comprehensive Rust code quality analyzer — seven dimensions: IOSP, Complexity, DRY, SRP, Coupling, Test Quality, Architecture
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# rustqual.toml — Configuration for the rustqual code quality analyzer
#
# Place this file in your project root.


# Function names (or patterns with trailing *) to exclude from analysis.
#   - `main` / `run` — Composition-Root-Dispatcher, IOSP-Ignore
#     (Top-Level-Entrypoints mischen zwangsläufig Branching + Delegation).
#   - `visit_*` — syn-Visitor-Methoden mit fester extern-Signatur. Sie
#     werden von `syn::visit::visit_file` via Trait-Dispatch aufgerufen,
#     nicht direkt von Rustcode — daher sieht TQ-003 keinen Call-Pfad
#     und `DimensionAnalyzer` keine eigenen Calls.
# `test_*` entfernt: Test-Aware-Analyse (is_test) erledigt die Filterung
# jetzt strukturell; ein Namens-Präfix ist nicht mehr nötig.
ignore_functions = [
    "main",
    "run",
    "visit_*",
]

# Glob patterns for files to exclude.
# `examples/**` hält per-rule Fixture-Crates, die NICHT Teil rustquals sind —
# sie werden von den Analyzer-Tests geladen, aber nicht mit-analysiert.
exclude_files = ["examples/**"]

# If true, closures count as "logic" even when passed to iterator adaptors.
# Default: false (lenient — closures inside .map()/.filter() are ignored).
strict_closures = false

# If true, iterator chains (.map, .filter, .fold, ...) count as logic.
# Default: false.
strict_iterator_chains = false

# If true, recursive calls (function calling itself) are allowed and don't
# count as IOSP violations. Default: false.
allow_recursion = false

# If true, the ? operator counts as logic (implicit control flow).
# Default: false.
strict_error_propagation = false

# Maximum ratio of all allow suppressions (qual:allow + #[allow]) before a warning is emitted.
max_suppression_ratio = 0.10

# ── Complexity Analysis ──────────────────────────────────────────────────

[complexity]
enabled = true
# max_cognitive = 15
# max_cyclomatic = 10
# max_nesting_depth = 4
# max_function_lines = 60
# detect_unsafe = true
# detect_error_handling = true
allow_expect = false

# ── DRY / Duplicate Detection ───────────────────────────────────────────

[duplicates]
enabled = true

# ── Boilerplate Detection ───────────────────────────────────────────────

[boilerplate]
enabled = true

# ── SRP (Single Responsibility) ─────────────────────────────────────────

[srp]
enabled = true

# ── Coupling Analysis ───────────────────────────────────────────────────

[coupling]
enabled = true

# ── Structural Binary Checks ───────────────────────────────────────────

[structural]
enabled = true

# ── Test Quality Analysis ──────────────────────────────────────────────

[test_quality]
enabled = true
# Extra macro names (beyond assert*/debug_assert*) to recognize as assertions in TQ-001.
# Example: extra_assertion_macros = ["verify", "check", "expect_that"]
# extra_assertion_macros = []

# ── Quality Score Weights ──────────────────────────────────────────────

[weights]
iosp         = 0.22
complexity   = 0.18
dry          = 0.13
srp          = 0.18
coupling     = 0.09
test_quality = 0.10
architecture = 0.10


# ── Architecture Dimension ─────────────────────────────────────────────
#
# Rules are grouped thematically (see section headers below). Every rule
# is live and enforced.

[architecture]
enabled = true


# ── Layer definitions ──────────────────────────────────────────────────
#
# Reihenfolge von innen (Rang 0) nach außen. Ungewöhnlich gegenüber
# klassisch-hexagonal: rustquals Analyse-Logik lebt in `adapters/`, ist
# aber konzeptuell näher an der Domain als an klassischer Infrastruktur.
# Deshalb teilen wir den Adapter-Ring:
#   - infrastructure  — I/O-Adapter (Config, Source, Suppression)
#   - analysis        — die eigentliche Analyse + ihre Präsentation
#                       (adapters/analyzers, adapters/shared, adapters/report)
#
# Reports sitzen bewusst auf `analysis`-Rang: sie rendern Analyse-Output
# und dürfen die zugehörigen Datentypen kennen. Das vermeidet den
# kosmetischen Zwang, jede Detail-Struktur in Finding hineinzuquetschen.
#
# Application orchestriert — kennt deshalb legitim alle darunter liegenden
# Ringe. Composition Root ist reexport point.

[architecture.layers]
order = ["domain", "port", "infrastructure", "analysis", "application"]
unmatched_behavior = "strict_error"

[architecture.layers.domain]
paths = ["src/domain/**"]

[architecture.layers.port]
paths = ["src/ports/**"]

[architecture.layers.infrastructure]
paths = [
    "src/adapters/config/**",
    "src/adapters/source/**",
    "src/adapters/suppression/**",
]

[architecture.layers.analysis]
paths = [
    "src/adapters/analyzers/**",
    "src/adapters/shared/**",
    "src/adapters/report/**",
]

[architecture.layers.application]
paths = ["src/app/**"]


# ── Re-export points ───────────────────────────────────────────────────

[architecture.reexport_points]
paths = [
    "src/lib.rs",
    "src/main.rs",
    "src/adapters/mod.rs",
    "src/bin/**",
    "src/cli/**",
    "tests/**",
]


# ── External-crate mapping (leer für Single-Crate) ─────────────────────
#
# Rustqual ist Single-Crate; Workspace-Nutzer mappen hier ihre Crates
# auf Layer (z.B. "pv_port_*" = "port").

[architecture.external_crates]


# ── Forbidden edges ────────────────────────────────────────────────────

# Dimension-Analyzer sind isoliert: neue Dimension lässt sich hinzufügen,
# ohne existierende zu ändern. Ausnahmen:
#   - IOSP liefert die Basis-Datentypen (FunctionAnalysis, ProjectScope).
#     Jeder Analyzer darf daraus lesen.
#   - DRY liefert die Dead-Code-/Declared-Function-Infrastruktur, auf der
#     TQ-003/004/005 aufbauen. Strukturell abgeleitet, nicht peer.
# Jede andere Analyzer↔Analyzer-Referenz ist unerwünscht.
[[architecture.forbidden]]
from = "src/adapters/analyzers/iosp/**"
to = "src/adapters/analyzers/**"
except = ["src/adapters/analyzers/iosp/**"]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

[[architecture.forbidden]]
from = "src/adapters/analyzers/complexity/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/complexity/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

[[architecture.forbidden]]
from = "src/adapters/analyzers/dry/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/dry/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

[[architecture.forbidden]]
from = "src/adapters/analyzers/srp/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/srp/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

[[architecture.forbidden]]
from = "src/adapters/analyzers/coupling/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/coupling/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

# TQ ist explizit abgeleitete Dimension: baut auf DRY-Dead-Code-
# Infrastruktur (DeclaredFunction, DeadCodeWarning) und IOSP-Scope auf.
[[architecture.forbidden]]
from = "src/adapters/analyzers/tq/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/tq/**",
    "src/adapters/analyzers/dry/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig (TQ ist derivativ)"

[[architecture.forbidden]]
from = "src/adapters/analyzers/structural/**"
to = "src/adapters/analyzers/**"
except = [
    "src/adapters/analyzers/structural/**",
    "src/adapters/analyzers/iosp/**",
]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

[[architecture.forbidden]]
from = "src/adapters/analyzers/architecture/**"
to = "src/adapters/analyzers/**"
except = ["src/adapters/analyzers/architecture/**"]
reason = "Dimension-Analyzer kennen sich nicht gegenseitig"

# Analyzer produzieren Findings, keine Reports
[[architecture.forbidden]]
from = "src/adapters/analyzers/**"
to = "src/adapters/report/**"
reason = "Analyzer erzeugen Findings; Reporter konsumieren sie separat"

# Reporter lesen Analyzer-Datentypen (FunctionAnalysis, Classification,
# DeadCodeWarning etc.) zum Rendern — das ist legitime DTO-Kopplung auf
# gleichem Layer-Rang (beide in `analysis`). Was Reporter NICHT dürfen:
# Analyzer-Funktionen aufrufen (d.h. Analyse auslösen). Das verhindert
# bereits die Layer-Struktur: report ist gleichrangig mit analyzer, hat
# aber keinen Anlass, orchestration zu bauen. Die Gegenrichtung
# (Analyzer → Report) oben bleibt strikt verboten.

# Adapter kennen Application nicht (folgt aus Layer-Reihenfolge,
# explizites Verbot verhindert Adapter → App Import)
[[architecture.forbidden]]
from = "src/adapters/**"
to = "src/app/**"
reason = "Adapter kennt Ports + Domain, aber keine Application-Use-Cases"


# ── Symbol rules: Language boundaries ──────────────────────────────────
# Where specific crates (syn, globset, rayon, serialization, filesystem)
# may appear. Keeps Domain and Ports free of implementation-detail types.

# AST-Parsing ist überall erlaubt ausser in Domain. Der syn-Typ ist
# rustquals primäre Datendarstellung nach dem Parsen — Adapter, Ports,
# App und CLI reichen ihn durch. Nur Domain muss rein bleiben: Findings,
# Severity, Score sind sprach-agnostische Werttypen.
[[architecture.pattern]]
name = "no_syn_in_domain"
forbid_path_prefix = ["syn::", "proc_macro2::", "quote::"]
forbidden_in = ["src/domain/**"]
reason = "Domain-Typen kennen keine AST-Darstellung"

# Glob-Imports in Domain verboten — verstecken Layer-Tunneling
[[architecture.pattern]]
name = "no_glob_imports_in_domain"
forbid_glob_import = true
forbidden_in = ["src/domain/**"]
reason = "Glob-Imports (use foo::*) verstecken Layer-Tunneling durch Re-Exports"

# Filesystem-Zugriff ist Adapter-Concern
[[architecture.pattern]]
name = "filesystem_only_in_adapters"
forbid_path_prefix = ["walkdir::", "notify::"]
allowed_in = ["src/adapters/**"]
reason = "Filesystem-Zugriff läuft über Adapter-Ports"

# Serialisierungs-Libraries leben in Adaptern
[[architecture.pattern]]
name = "serialization_only_in_adapters"
forbid_path_prefix = ["toml::", "serde_json::", "toon_encode::"]
allowed_in = ["src/adapters/**", "**/tests/**"]
reason = "Serde-derives überall erlaubt, aber Serialisierungs-I/O nur in Adaptern"

# Parallelisierung ist Implementierungs-Detail
[[architecture.pattern]]
name = "rayon_only_in_adapters"
forbid_path_prefix = ["rayon::"]
allowed_in = ["src/adapters/**"]
reason = "Parallelisierung ist Adapter-Implementierung, nicht Domain-/App-Concern"

# Pattern-Matching-Libraries sind Adapter-Detail
[[architecture.pattern]]
name = "globset_only_in_adapters"
forbid_path_prefix = ["globset::", "regex::"]
allowed_in = ["src/adapters/**", "**/tests/**"]
reason = "Glob- und Regex-Matching leben in Adaptern"


# ── Symbol rules: Error-handling policy ────────────────────────────────
# Production propagates errors through Result. Panic helpers, panic
# macros, and stdout writes belong in narrowly-scoped locations only.

# Keine Panic-Helper (.unwrap/.expect) in Production
[[architecture.pattern]]
name = "no_panic_helpers_in_production"
forbid_method_call = ["unwrap", "expect"]
forbidden_in = ["src/**"]
except = ["**/tests/**"]
reason = "Production propagiert Fehler typisiert statt zu panicken"

# stdout ist das Report-Channel: nur Report-Adapter und CLI dürfen dorthin
# schreiben. Analyzer/App/Domain/Ports müssen Daten zurückgeben, nicht drucken.
[[architecture.pattern]]
name = "no_stdout_in_library_code"
forbid_macro_call = ["println", "print", "dbg"]
forbidden_in = ["src/**"]
except = [
    "src/main.rs",
    "src/lib.rs",
    "src/bin/**",
    "src/cli/**",
    "src/adapters/report/**",
    "**/tests/**",
]
reason = "Stdout-Dispatch nur in Report-Adaptern und Composition Root"

# stderr ist das Error/Warning-Channel. Nur Domain und Ports sind rein —
# dort muss jeder Fehler über Result propagieren. Alles andere darf am
# Rand stderr nutzen (App entscheidet exit codes, Adapter degradieren
# graceful mit Warnings).
[[architecture.pattern]]
name = "no_stderr_in_pure_layers"
forbid_macro_call = ["eprintln", "eprint"]
forbidden_in = ["src/domain/**", "src/ports/**"]
reason = "Domain und Ports propagieren Fehler über Result, nicht über stderr"

# Keine Panic-Makros in Production
[[architecture.pattern]]
name = "no_panic_macros_in_production"
forbid_macro_call = ["panic", "todo", "unimplemented", "unreachable"]
forbidden_in = ["src/**"]
except = ["**/tests/**"]
reason = "Production-Code hat typisierte Errors, keine Panics"


# ── Symbol rules: Composition-root boundary ────────────────────────────
# CLI parsing, anyhow, and Box<dyn Error> are only allowed where the
# process meets the outside world — not in Domain/App/Ports/Adapter.

# CLI-Parsing nur im Composition Root
[[architecture.pattern]]
name = "clap_only_in_composition_root"
forbid_path_prefix = ["clap::", "clap_complete::"]
allowed_in = ["src/main.rs", "src/lib.rs", "src/bin/**", "src/cli/**", "**/tests/**"]
reason = "CLI-Parsing ist Verdrahtungs-Concern im Composition Root"

# anyhow nur an der Boundary
[[architecture.pattern]]
name = "anyhow_only_at_boundary"
forbid_path_prefix = ["anyhow::"]
allowed_in = ["src/main.rs", "src/lib.rs", "src/bin/**", "**/tests/**"]
reason = "Typisierte Errors in Domain/App/Ports/Adapter; anyhow nur am Rand"

# Kein Box<dyn Error> im Code
[[architecture.pattern]]
name = "no_boxed_error"
forbid_path_prefix = ["Box<dyn std::error::Error", "Box<dyn Error"]
forbidden_in = ["src/**"]
except = ["**/tests/**"]
reason = "Typisierte Errors; kein Zerfall zu dyn Error"


# ── Symbol rules: Runtime guarantees ───────────────────────────────────
# Rustqual is a pure analyzer — no unsafe, no FFI.

# Kein unsafe in rustqual
[[architecture.pattern]]
name = "no_unsafe"
forbid_item_kind = ["unsafe_fn", "unsafe_impl", "extern_c_block"]
forbidden_in = ["src/**"]
reason = "Rustqual ist reiner Analyser, kein FFI, kein unsafe"


# ── Symbol rules: Test placement ───────────────────────────────────────
# Tests live in companion `tests/` subtrees (or workspace-root `tests/`)
# — never inline inside production files.

# Keine inline #[cfg(test)] mod tests { … }-Blöcke
# Erlaubt: #[cfg(test)] mod tests; (Deklaration ohne Body)
[[architecture.pattern]]
name = "no_inline_cfg_test_module"
forbid_item_kind = ["inline_cfg_test_module"]
forbidden_in = ["src/**"]
reason = "Tests in tests/-Schwester-Bäumen, nicht inline — ehrliche Modul-Längen-Metrik"

# Keine losen Top-Level-#[cfg(test)] fn/impl/const
[[architecture.pattern]]
name = "no_top_level_cfg_test_item"
forbid_item_kind = ["top_level_cfg_test_item"]
forbidden_in = ["src/**"]
reason = "Test-Helpers in Companion-Files oder mod tests, nicht lose zwischen Production-Code"


# ── Trait-signature rules: Port contract ───────────────────────────────
# Every Port trait must be object-safe, Send + Sync, and must never leak
# adapter-specific error types through its Result.

[[architecture.trait_contract]]
name = "port_traits"
scope = "src/ports/**"

receiver_may_be = ["shared_ref"]

forbidden_return_type_contains = [
    "anyhow::",
    "Box<dyn",
]

forbidden_error_variant_contains = [
    "syn::",
    "toml::",
    "serde_json::",
    "walkdir::",
    "notify::",
    "rayon::",
    "globset::",
    "regex::",
]

must_be_object_safe = true

required_supertraits_contain = ["Send", "Sync"]


# ══════════════════════════════════════════════════════════════════════
# Report aggregation (rustqual-wide, workspace mode)
# ══════════════════════════════════════════════════════════════════════

[report]
aggregation = "loc_weighted"