auditmysite 0.26.0

Resource-efficient WCAG 2.1 Accessibility Checker in Rust
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
//! Single-report page-section renderers for `generate_pdf`.
//!
//! Each function takes ownership of the builder, appends its section's
//! components, and returns the builder for further chaining.

use renderreport::components::advanced::{
    ChecklistPanel, ChecklistRow, DiagnosisPanel, DiagnosisRow, List, PageBreak, PhaseBlock,
    SectionHeaderSplit,
};
use renderreport::prelude::*;

use super::appendix::build_cli_snapshot_table;
use super::detail_modules::{
    render_ai_visibility, render_best_practices, render_budget_violations,
    render_content_visibility, render_dark_mode, render_journey, render_mobile, render_performance,
    render_security, render_seo, render_source_quality, render_tech_stack, render_ux,
};
use super::diagnosis::render_diagnosis_section;
use super::findings::render_finding_technical;
use super::helpers::map_severity;
use super::modules::{build_was_jetzt_tun_table, WasJetztTunContent};
use super::wcag_coverage::render_wcag_coverage_section;
use crate::audit::AuditReport;
use crate::cli::ReportLevel;
use crate::i18n::I18n;
use crate::output::report_model::*;

/// Render a part divider — visually separates the three report parts (#246).
///
/// Each divider produces a page break, a strong level=1 section header tagged
/// with "TEIL N / 3" (or "PART N OF 3"), an audience callout, and a contents list.
#[allow(clippy::too_many_arguments)]
pub(super) fn render_part_divider(
    mut builder: renderreport::engine::ReportBuilder,
    part_num: u8,
    title: &str,
    intro: &str,
    audience_title: &str,
    audience_body: &str,
    contents_title: &str,
    contents: &[&str],
    i18n: &I18n,
) -> renderreport::engine::ReportBuilder {
    let en = i18n.locale() == "en";
    let eyebrow = if en {
        format!("PART {} OF 3", part_num)
    } else {
        format!("TEIL {} VON 3", part_num)
    };
    builder = builder
        .add_component(PageBreak::new())
        .add_component(
            SectionHeaderSplit::new(title, intro)
                .with_eyebrow(eyebrow)
                .with_level(1),
        )
        .add_component(Callout::info(audience_body).with_title(audience_title));
    if !contents.is_empty() {
        let mut list = List::new().with_title(contents_title);
        for item in contents {
            list = list.add_item(*item);
        }
        builder = builder.add_component(list);
    }
    builder
}

/// Section 4 — Action Plan: quick wins, prioritized actions, execution note.
pub(super) fn render_action_plan(
    mut builder: renderreport::engine::ReportBuilder,
    vm: &ReportViewModel,
    i18n: &I18n,
) -> renderreport::engine::ReportBuilder {
    builder = builder.add_component(PageBreak::new()).add_component(
        SectionHeaderSplit::new(
            &vm.executive.action_plan_title,
            &vm.executive.action_plan_intro,
        )
        .with_eyebrow(if i18n.locale() == "en" {
            "IMPLEMENTATION PLAN"
        } else {
            "UMSETZUNGSPLAN"
        })
        .with_level(2),
    );

    // Empfohlene Vorgehensweise
    builder = builder.add_component(
        Callout::info(&vm.executive.action_plan_callout_body)
            .with_title(&vm.executive.action_plan_callout_title),
    );

    if !vm.actions.phase_preview.is_empty() {
        for (idx, phase) in vm.actions.phase_preview.iter().enumerate() {
            builder = builder.add_component(
                PhaseBlock::new((idx + 1) as u8, &phase.phase_label, &phase.description)
                    .with_items(phase.top_items.clone())
                    .with_total(phase.item_count)
                    .with_color(&phase.accent_color),
            );
        }
    }

    // QuickWins — immediate actions
    let quick_items: Vec<&RoadmapItemData> = vm
        .actions
        .roadmap_columns
        .iter()
        .flat_map(|col| col.items.iter())
        .filter(|i| {
            i.execution_priority.contains("Direkt") || i.execution_priority.contains("Sofort")
        })
        .take(5)
        .collect();

    if !quick_items.is_empty() {
        let rows: Vec<ChecklistRow> = quick_items
            .iter()
            .map(|item| ChecklistRow::new(&item.action, &item.user_effect).with_status("warn"))
            .collect();
        builder = builder
            .add_component(ChecklistPanel::new(rows).with_title(i18n.t("panel-quick-actions")));
    }

    // ActionTable — full prioritized table
    let wjt_table = build_was_jetzt_tun_table(vm);
    match wjt_table {
        WasJetztTunContent::Table(t) => builder = builder.add_component(t),
        WasJetztTunContent::Empty(c) => builder = builder.add_component(c),
    }

    builder
}

/// Section 5 — Tech Entry: intro + module health diagnosis panel.
pub(super) fn render_tech_entry(
    mut builder: renderreport::engine::ReportBuilder,
    vm: &ReportViewModel,
    i18n: &I18n,
) -> renderreport::engine::ReportBuilder {
    // Part 2 — Technical Accessibility Report (#246).
    let en = i18n.locale() == "en";
    let (p2_title, p2_intro, p2_audience_title, p2_audience_body, p2_contents_title) = if en {
        (
            "Technical Accessibility Report",
            "WCAG compliance, diagnosed findings with code snippets, and the complete list of detected issues.",
            "Audience",
            "Developers and engineering teams. Read this part to understand each finding with its WCAG criterion, HTML evidence, fix guidance, and component attribution.",
            "What's in this part",
        )
    } else {
        (
            "Technischer Accessibility-Report",
            "WCAG-Konformität, diagnostizierte Befunde mit Code-Snippets und die vollständige Liste erkannter Probleme.",
            "Zielgruppe",
            "Entwickler und Engineering-Teams. Dieser Teil zeigt jeden Befund mit WCAG-Kriterium, HTML-Evidenz, Fix-Hinweis und Komponentenzuordnung.",
            "Inhalt dieses Teils",
        )
    };
    let p2_contents: Vec<&str> = if en {
        vec![
            "Module health overview",
            "System diagnosis",
            "Findings by criticality (mandatory vs. optimization)",
            "HTML snippets and fix guidance per finding",
            "WCAG coverage matrix",
            "Complete list of detected violations",
        ]
    } else {
        vec![
            "Modul-Übersicht",
            "Systemdiagnose",
            "Befunde nach Kritikalität (Pflicht vs. Optimierung)",
            "HTML-Snippets und Fix-Hinweise pro Befund",
            "WCAG-Coverage-Matrix",
            "Vollständige Liste aller erkannten Verstöße",
        ]
    };
    builder = render_part_divider(
        builder,
        2,
        p2_title,
        p2_intro,
        p2_audience_title,
        p2_audience_body,
        p2_contents_title,
        &p2_contents,
        i18n,
    );
    builder = builder.add_component(
        SectionHeaderSplit::new(&vm.executive.technical_title, &vm.executive.technical_intro)
            .with_eyebrow(if i18n.locale() == "en" {
                "DEVELOPER"
            } else {
                "ENTWICKLER"
            })
            .with_level(2),
    );

    if !vm.modules.dashboard.is_empty() {
        let diag_rows: Vec<DiagnosisRow> = vm
            .modules
            .dashboard
            .iter()
            .map(|module| {
                let status = if module.score >= 80 {
                    "good"
                } else if module.score >= 50 {
                    "warn"
                } else {
                    "bad"
                };
                let display_name = if module.measurement_type == "heuristic" {
                    let suffix = if i18n.locale() == "en" {
                        "Indicator"
                    } else {
                        "Indikator"
                    };
                    format!("{} ({suffix})", module.name)
                } else {
                    module.name.clone()
                };
                DiagnosisRow::new(&display_name, format!("{}/100", module.score))
                    .with_status(status)
            })
            .collect();
        builder = builder.add_component(
            DiagnosisPanel::new(diag_rows).with_title(i18n.t("panel-modules-overview")),
        );
    }

    builder
}

/// Sections 5b + 6+ — diagnosis, findings by severity tier, module metrics, appendix.
pub(super) fn render_tech_details(
    mut builder: renderreport::engine::ReportBuilder,
    vm: &ReportViewModel,
    report: &AuditReport,
    i18n: &I18n,
) -> renderreport::engine::ReportBuilder {
    let en = i18n.locale() == "en";

    // Section 5b — System Diagnosis
    if vm.severity.has_issues {
        builder = render_diagnosis_section(builder, &vm.diagnosis, i18n);
    }

    // Section 6+ — Findings grouped by criticality tier, then severity (#245).
    if vm.severity.has_issues {
        if !vm.findings.by_tier.is_empty() {
            let (findings_title, findings_intro) = if en {
                (
                    "Findings by Criticality",
                    "All technical findings, separated into mandatory (BFSG-relevant) and optimization.",
                )
            } else {
                (
                    "Befunde nach Kritikalität",
                    "Alle technischen Befunde, getrennt in Pflicht (BFSG-relevant) und Optimierung.",
                )
            };
            builder = builder.add_component(PageBreak::new()).add_component(
                SectionHeaderSplit::new(findings_title, findings_intro)
                    .with_eyebrow(if en { "FINDINGS" } else { "BEFUNDE" })
                    .with_level(2),
            );

            for criticality in &vm.findings.by_tier {
                let tier_summary = if en {
                    format!(
                        "{} finding(s) — {} occurrence(s) total. {}",
                        criticality.total_findings,
                        criticality.total_occurrences,
                        criticality.intro
                    )
                } else {
                    format!(
                        "{} Befund(e) — {} Vorkommen gesamt. {}",
                        criticality.total_findings,
                        criticality.total_occurrences,
                        criticality.intro
                    )
                };
                builder = builder.add_component(PageBreak::new()).add_component(
                    SectionHeaderSplit::new(&criticality.label, &tier_summary)
                        .with_eyebrow(&criticality.eyebrow)
                        .with_level(2),
                );
                let tier_callout = match criticality.tier {
                    crate::output::report_model::CriticalityTier::Mandatory => {
                        Callout::error(&criticality.intro).with_title(if en {
                            "Mandatory — legal risk"
                        } else {
                            "Pflicht — rechtliches Risiko"
                        })
                    }
                    crate::output::report_model::CriticalityTier::Optimization => {
                        Callout::info(&criticality.intro).with_title(if en {
                            "Optimization — no direct legal risk"
                        } else {
                            "Optimierung — kein unmittelbares rechtliches Risiko"
                        })
                    }
                };
                builder = builder.add_component(tier_callout);

                for tier in &criticality.by_severity {
                    let tier_intro = if en {
                        format!(
                            "{} finding(s) — {} occurrence(s) total",
                            tier.findings.len(),
                            tier.total_occurrences
                        )
                    } else {
                        format!(
                            "{} Befund(e) — {} Vorkommen gesamt",
                            tier.findings.len(),
                            tier.total_occurrences
                        )
                    };
                    builder = builder.add_component(
                        SectionHeaderSplit::new(&tier.label, &tier_intro)
                            .with_eyebrow(tier.label.to_uppercase())
                            .with_level(3),
                    );

                    if tier.severity == crate::wcag::Severity::Critical
                        && criticality.tier
                            == crate::output::report_model::CriticalityTier::Mandatory
                    {
                        let msg = if en {
                            format!(
                                "{} critical issue(s) blocking accessibility — must be resolved before deployment.",
                                tier.findings.len()
                            )
                        } else {
                            format!(
                                "{} kritische(r) Befund(e) blockiert/blockieren die Barrierefreiheit — vor dem Deployment zu beheben.",
                                tier.findings.len()
                            )
                        };
                        builder = builder.add_component(Callout::error(&msg));
                    }

                    for group in &tier.findings {
                        builder = render_finding_technical(builder, group, i18n);
                    }
                }
            }
        } else {
            // Fallback: tier classification unavailable for all findings
            for group in &vm.findings.all_findings {
                builder = render_finding_technical(builder, group, i18n);
            }
        }
    }

    // WCAG Coverage (issue #37)
    if vm.meta.report_level != ReportLevel::Executive {
        builder = render_wcag_coverage_section(builder, report, i18n);
    }

    // Appendix — full violations list, conclusion of Part 2 (#246).
    {
        let (appendix_title, appendix_intro) = if en {
            (
                "Complete Findings List",
                "Raw audit data and the full list of detected violations.",
            )
        } else {
            (
                "Vollständige Fundstellen",
                "Rohdaten des Audits und die vollständige Liste aller erkannten Verstöße.",
            )
        };
        builder = builder.add_component(PageBreak::new()).add_component(
            SectionHeaderSplit::new(appendix_title, appendix_intro)
                .with_eyebrow(if en { "APPENDIX" } else { "ANHANG" })
                .with_level(2),
        );
    }

    if vm.appendix.has_violations {
        builder = builder.add_component(build_cli_snapshot_table(vm, i18n));

        // JSON hint in appendix (#219)
        let json_note = if en {
            "The accompanying JSON report contains the complete machine-readable issue list with selectors, occurrences, and all detail data for automated processing."
        } else {
            "Der begleitende JSON-Report enthält die vollständige maschinenlesbare Fehlerliste mit Selektoren, Vorkommen und allen Detaildaten für automatisierte Weiterverarbeitung."
        };
        builder = builder.add_component(Callout::info(json_note).with_title(if en {
            "Raw data & processing"
        } else {
            "Rohdaten & Weiterverarbeitung"
        }));

        if vm.meta.report_level == ReportLevel::Technical {
            for v in &vm.appendix.violations {
                let mut desc = v.message.clone();
                if let Some(ref fix) = v.fix_suggestion {
                    desc.push_str(&format!("\n\nFix: {}", fix));
                }
                desc.push_str(&format!(
                    "\n\n{} Elemente betroffen",
                    v.affected_elements.len()
                ));
                let useful_selectors: Vec<&str> = v
                    .affected_elements
                    .iter()
                    .map(|e| e.selector.as_str())
                    .filter(|s| {
                        s.contains('.')
                            || s.contains('#')
                            || s.contains('[')
                            || s.contains('>')
                            || s.contains(' ')
                    })
                    .collect();
                if !useful_selectors.is_empty() {
                    desc.push_str(&format!("\nSelektoren: {}", useful_selectors.join(", ")));
                }
                builder = builder.add_component(Finding::new(
                    format!("{} — {}", v.rule, v.rule_name),
                    map_severity(&v.severity),
                    &desc,
                ));
            }
        } else {
            let rows: Vec<ChecklistRow> = vm
                .appendix
                .violations
                .iter()
                .map(|v| {
                    let status = match v.severity {
                        crate::wcag::Severity::Critical => "bad",
                        crate::wcag::Severity::High => "warn",
                        _ => "neutral",
                    };
                    ChecklistRow::new(format!("{} — {}", v.rule, v.rule_name), v.message.clone())
                        .with_status(status)
                })
                .collect();
            builder = builder.add_component(
                ChecklistPanel::new(rows).with_title(i18n.t("section-all-violations")),
            );
        }
    }

    // Part 3 — SEO, AI & Quality (optional). Only render if any module is present (#246).
    let has_part3 = vm.module_details.seo.is_some()
        || vm.module_details.ai_visibility.is_some()
        || vm.module_details.content_visibility.is_some()
        || vm.module_details.performance.is_some()
        || !report.budget_violations.is_empty()
        || vm.module_details.security.is_some()
        || vm.module_details.mobile.is_some()
        || vm.module_details.ux.is_some()
        || vm.module_details.journey.is_some()
        || vm.module_details.dark_mode.is_some()
        || vm.module_details.source_quality.is_some()
        || vm.module_details.tech_stack.is_some()
        || vm.module_details.best_practices.is_some();

    if has_part3 {
        let (p3_title, p3_intro, p3_audience_title, p3_audience_body, p3_contents_title) = if en {
            (
                "SEO, AI & Quality",
                "Search engine optimization, AI discoverability, and technical quality signals.",
                "Audience",
                "Marketing, SEO specialists, and engineering teams. This part is optional and complements the accessibility findings with discoverability and technical quality metrics.",
                "What's in this part",
            )
        } else {
            (
                "SEO, KI & Qualität",
                "Suchmaschinenoptimierung, KI-Auffindbarkeit und technische Qualitätssignale.",
                "Zielgruppe",
                "Marketing, SEO-Spezialisten und Engineering-Teams. Dieser Teil ist optional und ergänzt die Accessibility-Befunde um Auffindbarkeits- und Qualitätsmetriken.",
                "Inhalt dieses Teils",
            )
        };
        let mut p3_contents: Vec<&str> = Vec::new();
        if vm.module_details.seo.is_some()
            || vm.module_details.ai_visibility.is_some()
            || vm.module_details.content_visibility.is_some()
        {
            p3_contents.push(if en {
                "SEO, AI visibility, and content authority signals"
            } else {
                "SEO, KI-Sichtbarkeit und inhaltliche Autoritätssignale"
            });
        }
        if vm.module_details.performance.is_some() || !report.budget_violations.is_empty() {
            p3_contents.push(if en {
                "Performance details and budget violations"
            } else {
                "Performance-Details und Budget-Verstöße"
            });
        }
        if vm.module_details.security.is_some() {
            p3_contents.push(if en {
                "Security headers"
            } else {
                "Sicherheits-Header"
            });
        }
        if vm.module_details.mobile.is_some() {
            p3_contents.push(if en {
                "Mobile usability"
            } else {
                "Mobile Nutzbarkeit"
            });
        }
        if vm.module_details.ux.is_some() || vm.module_details.journey.is_some() {
            p3_contents.push(if en {
                "UX and user journey"
            } else {
                "UX und Nutzerführung"
            });
        }
        if vm.module_details.dark_mode.is_some() {
            p3_contents.push(if en {
                "Dark mode support"
            } else {
                "Dark-Mode-Unterstützung"
            });
        }
        if vm.module_details.source_quality.is_some()
            || vm.module_details.tech_stack.is_some()
            || vm.module_details.best_practices.is_some()
        {
            p3_contents.push(if en {
                "Source quality, tech stack, and best practices"
            } else {
                "Quellqualität, Tech-Stack und Best Practices"
            });
        }
        builder = render_part_divider(
            builder,
            3,
            p3_title,
            p3_intro,
            p3_audience_title,
            p3_audience_body,
            p3_contents_title,
            &p3_contents,
            i18n,
        );
    }

    // SEO & Visibility sub-section (level=2 inside Part 3).
    if vm.module_details.seo.is_some()
        || vm.module_details.ai_visibility.is_some()
        || vm.module_details.content_visibility.is_some()
    {
        builder = builder.add_component(PageBreak::new()).add_component(
            SectionHeaderSplit::new(
                if en {
                    "SEO & Visibility"
                } else {
                    "SEO & Sichtbarkeit"
                },
                if en {
                    "Search engine optimization, AI discoverability, and content authority signals."
                } else {
                    "Suchmaschinenoptimierung, KI-Auffindbarkeit und inhaltliche Autoritätssignale."
                },
            )
            .with_eyebrow(if en { "ANALYSIS" } else { "ANALYSE" })
            .with_level(2),
        );
    }
    if let Some(ref seo) = vm.module_details.seo {
        builder = render_seo(builder, seo, i18n);
    }
    if let Some(ref av) = vm.module_details.ai_visibility {
        builder = render_ai_visibility(builder, av, i18n);
    }
    if let Some(ref cv) = vm.module_details.content_visibility {
        builder = render_content_visibility(builder, cv, i18n);
    }

    // Technology & Quality sub-section (level=2 inside Part 3).
    if vm.module_details.performance.is_some()
        || !report.budget_violations.is_empty()
        || vm.module_details.security.is_some()
        || vm.module_details.mobile.is_some()
        || vm.module_details.ux.is_some()
        || vm.module_details.journey.is_some()
        || vm.module_details.dark_mode.is_some()
        || vm.module_details.source_quality.is_some()
        || vm.module_details.tech_stack.is_some()
        || vm.module_details.best_practices.is_some()
    {
        builder = builder.add_component(PageBreak::new()).add_component(
            SectionHeaderSplit::new(
                if en { "Technology & Quality" } else { "Technik & Qualität" },
                if en {
                    "Core technical quality: performance, security, mobile usability, UX, and engineering foundations."
                } else {
                    "Technische Kernqualität: Performance, Sicherheit, Mobile-Nutzbarkeit, UX und technische Grundlagen."
                },
            )
            .with_eyebrow(if en { "ANALYSIS" } else { "ANALYSE" })
            .with_level(2),
        );
    }
    if let Some(ref perf) = vm.module_details.performance {
        builder = render_performance(builder, perf, i18n);
    }
    if !report.budget_violations.is_empty() {
        builder = render_budget_violations(builder, &report.budget_violations, i18n);
    }
    if let Some(ref sec) = vm.module_details.security {
        builder = render_security(builder, sec, i18n);
    }
    if let Some(ref mobile) = vm.module_details.mobile {
        builder = render_mobile(builder, mobile, i18n);
    }
    if let Some(ref ux) = vm.module_details.ux {
        builder = render_ux(builder, ux, i18n);
    }
    if let Some(ref journey) = vm.module_details.journey {
        builder = render_journey(builder, journey, i18n);
    }
    if let Some(ref dm) = vm.module_details.dark_mode {
        builder = render_dark_mode(builder, dm, i18n);
    }
    if let Some(ref sq) = vm.module_details.source_quality {
        builder = render_source_quality(builder, sq, i18n);
    }
    if let Some(ref ts) = vm.module_details.tech_stack {
        builder = render_tech_stack(builder, ts, i18n);
    }
    if let Some(ref bp) = vm.module_details.best_practices {
        builder = render_best_practices(builder, bp, i18n);
    }

    builder
}