proa_source_tools 0.1.1

Source formatting, linting, and inspection engines for Proa
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
// Copyright Proa Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Managed-head lifecycle mistakes that dispatch always rejects at runtime:
//! checked head setters in a body, and metadata roles rendered inside
//! `Suspense` or inside the selected Page.
//!
//! Precision comes before recall. A rendered component is matched to a role
//! only when its path resolves, in the module that writes it, to the module
//! that defines the package's only type with that name, and every render impl
//! of that type declares the same literal `PAGE` or `LAYOUT` role. A name
//! bound by a function body, a glob import, the prelude, an external crate,
//! or a re-export is never resolved.

use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
use std::rc::Rc;

use proc_macro2::Span;

use super::*;
use crate::diagnostic::{SourceLabel, SourceRange};

/// The render traits with a head hook: `(trait, hook, body)`.
const RENDER_TRAITS: [(&str, &str, &str); 4] = [
    ("WebRender", "render_head", "render"),
    ("WebRenderSync", "render_head", "render"),
    ("WebRenderSend", "render_head_send", "render_send"),
    (
        "WebRenderSendSync",
        "render_head_send_sync",
        "render_send_sync",
    ),
];

/// Checked `HeadWriter` setters. They require an open head hook in a managed
/// document, so they fail in every body. The legacy setters (`set_title`,
/// `push_meta`, `push_link`, `push_raw_html`) still serve manual documents
/// and are deliberately absent.
const CHECKED_HEAD_SETTERS: &[&str] = &[
    "absolute_title",
    "alternates",
    "application_name",
    "authors",
    "canonical",
    "clear_alternates",
    "clear_authors",
    "clear_canonical",
    "clear_description",
    "clear_googlebot",
    "clear_icons",
    "clear_manifest",
    "clear_referrer",
    "clear_robots",
    "clear_title",
    "clear_title_template",
    "clear_twitter",
    "clear_verification",
    "creator",
    "description",
    "googlebot",
    "icon",
    "icons",
    "keywords",
    "manifest",
    "meta",
    "metadata",
    "module",
    "og_image",
    "open_graph",
    "publisher",
    "referrer",
    "remove_meta",
    "remove_module",
    "remove_stylesheet",
    "robots",
    "stylesheet",
    "title",
    "title_template",
    "twitter",
    "verification",
];

fn render_trait(item_impl: &ItemImpl) -> Option<(&'static str, &'static str)> {
    let (trait_path, _) = item_impl.trait_.as_ref()?;
    let name = trait_path.segments.last()?.ident.to_string();
    RENDER_TRAITS
        .iter()
        .find(|(trait_name, _, _)| *trait_name == name)
        .map(|(_, hook, body)| (*hook, *body))
}

/// `render/head-mutation-in-body`: a checked setter reached through
/// `head_mut()` inside a render body.
pub(super) fn lint_head_mutation_in_body(
    path: &Path,
    item_impl: &ItemImpl,
    ignored_ranges: &[RangeInclusive<usize>],
    diagnostics: &mut Vec<Diagnostic>,
) {
    let Some((hook, body)) = render_trait(item_impl) else {
        return;
    };
    for item in &item_impl.items {
        let ImplItem::Fn(method) = item else { continue };
        if method.sig.ident != body {
            continue;
        }
        let mut visitor = HeadMutationVisitor {
            scopes: vec![HashMap::new()],
            found: Vec::new(),
        };
        visitor.visit_block(&method.block);
        for (span, setter) in visitor.found {
            let start = span.start();
            if line_in_ranges(start.line, ignored_ranges) {
                continue;
            }
            diagnostics.push(
                Diagnostic::new(
                    path,
                    start.line,
                    start.column + 1,
                    Severity::Error,
                    "render/head-mutation-in-body",
                    format!("`head_mut().{setter}(..)` in `{body}` always fails: head metadata is written only in `{hook}`"),
                )
                .with_note(format!("`{body}` runs after the head hook has closed, so checked setters return `HeadError::OutsideHook`, or `HeadError::Closed` once the Page has sealed the head"))
                .with_help(format!("move this call into `{hook}` on the layout or Page that owns the metadata, and declare `const ROLE: proa::ComponentRole = proa::ComponentRole::PAGE;` (or `LAYOUT` for an ancestor layout)")),
            );
        }
    }
}

/// Tracks which locals hold a `HeadWriter`, following Rust's lexical scopes.
/// Every binding form shadows outer names: `let` (bound after its
/// initializer), `if let` / `while let`, match arms, `for` patterns, and
/// closure parameters. Only `let name = <cx>.head_mut()` binds a writer.
/// Blocks, closures, arms, and template slots each close their own scope.
struct HeadMutationVisitor {
    /// Innermost scope last; each maps a bound name to whether it is a writer.
    scopes: Vec<HashMap<String, bool>>,
    found: Vec<(Span, String)>,
}

impl HeadMutationVisitor {
    fn scoped(&mut self, visit: impl FnOnce(&mut Self)) {
        self.scopes.push(HashMap::new());
        visit(self);
        self.scopes.pop();
    }

    fn bind(&mut self, name: String, writer: bool) {
        if let Some(scope) = self.scopes.last_mut() {
            scope.insert(name, writer);
        }
    }

    /// Bind every name a pattern introduces as a non-writer.
    fn bind_pattern(&mut self, pat: &Pat) {
        for name in pattern_bindings(pat) {
            self.bind(name, false);
        }
    }

    fn is_writer_name(&self, name: &str) -> bool {
        self.scopes
            .iter()
            .rev()
            .find_map(|scope| scope.get(name))
            .copied()
            .unwrap_or(false)
    }

    fn is_head_writer(&self, expr: &Expr) -> bool {
        match expr {
            Expr::MethodCall(_) => is_head_mut_call(expr),
            Expr::Path(path) => path
                .path
                .get_ident()
                .is_some_and(|ident| self.is_writer_name(&ident.to_string())),
            Expr::Paren(inner) => self.is_head_writer(&inner.expr),
            _ => false,
        }
    }

    /// Each slot is evaluated in its own closure, so its bindings end with it.
    fn visit_template(&mut self, mac: &syn::Macro) {
        visit_template_exprs(mac, |expr| self.scoped(|visitor| visitor.visit_expr(expr)));
    }
}

fn is_head_mut_call(expr: &Expr) -> bool {
    matches!(expr, Expr::MethodCall(call) if call.method == "head_mut" && call.args.is_empty())
}

/// Whether a `let` initializer evaluates to `<cx>.head_mut()`, directly or
/// as the tail of a block.
fn yields_head_writer(expr: &Expr) -> bool {
    match expr {
        Expr::Paren(inner) => yields_head_writer(&inner.expr),
        Expr::Block(block) if block.label.is_none() => match block.block.stmts.last() {
            Some(syn::Stmt::Expr(tail, None)) => yields_head_writer(tail),
            _ => false,
        },
        _ => is_head_mut_call(expr),
    }
}

/// The name of a plain `name` / `mut name` / `name: T` binding.
fn simple_binding(pat: &Pat) -> Option<String> {
    match pat {
        Pat::Ident(pat) if pat.by_ref.is_none() && pat.subpat.is_none() => {
            Some(pat.ident.to_string())
        }
        Pat::Type(pat) => simple_binding(&pat.pat),
        _ => None,
    }
}

/// Every name a pattern may bind. Identifiers inside pattern macros count as
/// bindings, so an opaque pattern can only hide a writer.
fn pattern_bindings(pat: &Pat) -> Vec<String> {
    struct Bindings(Vec<String>);
    impl<'ast> Visit<'ast> for Bindings {
        fn visit_pat_ident(&mut self, node: &'ast syn::PatIdent) {
            self.0.push(node.ident.to_string());
            visit::visit_pat_ident(self, node);
        }
        fn visit_macro(&mut self, node: &'ast syn::Macro) {
            self.0.extend(token_idents(node.tokens.clone()));
        }
        // Names inside an arm guard or a const pattern (closure parameters,
        // block locals) are scoped to that expression and never bind in the
        // arm.
        fn visit_expr(&mut self, _: &'ast Expr) {}
    }
    let mut bindings = Bindings(Vec::new());
    bindings.visit_pat(pat);
    bindings.0
}

fn token_idents(tokens: proc_macro2::TokenStream) -> Vec<String> {
    let mut idents = Vec::new();
    for token in tokens {
        match token {
            proc_macro2::TokenTree::Ident(ident) => idents.push(ident.to_string()),
            proc_macro2::TokenTree::Group(group) => idents.extend(token_idents(group.stream())),
            _ => {}
        }
    }
    idents
}

impl<'ast> Visit<'ast> for HeadMutationVisitor {
    fn visit_block(&mut self, node: &'ast Block) {
        self.scoped(|visitor| visit::visit_block(visitor, node));
    }

    fn visit_local(&mut self, local: &'ast Local) {
        // The initializer and `else` block run before the new name exists.
        if let Some(init) = &local.init {
            self.visit_expr(&init.expr);
            if let Some((_, diverge)) = &init.diverge {
                self.visit_expr(diverge);
            }
        }
        let writer = local
            .init
            .as_ref()
            .is_some_and(|init| init.diverge.is_none() && yields_head_writer(&init.expr));
        match simple_binding(&local.pat) {
            Some(name) if writer => self.bind(name, true),
            _ => self.bind_pattern(&local.pat),
        }
    }

    fn visit_expr_closure(&mut self, node: &'ast syn::ExprClosure) {
        self.scoped(|visitor| {
            for input in &node.inputs {
                visitor.bind_pattern(input);
            }
            visitor.visit_expr(&node.body);
        });
    }

    fn visit_expr_match(&mut self, node: &'ast syn::ExprMatch) {
        self.visit_expr(&node.expr);
        for arm in &node.arms {
            self.scoped(|visitor| {
                visitor.bind_pattern(&arm.pat);
                // syn keeps an arm's guard inside its pattern.
                if let Pat::Guard(guarded) = &arm.pat {
                    visitor.visit_expr(&guarded.guard);
                }
                visitor.visit_expr(&arm.body);
            });
        }
    }

    fn visit_expr_for_loop(&mut self, node: &'ast syn::ExprForLoop) {
        self.visit_expr(&node.expr);
        self.scoped(|visitor| {
            visitor.bind_pattern(&node.pat);
            visitor.visit_block(&node.body);
        });
    }

    // `if let` / `while let` bindings reach the condition's remainder and the
    // body, not an `else` branch.
    fn visit_expr_if(&mut self, node: &'ast syn::ExprIf) {
        self.scoped(|visitor| {
            visitor.visit_expr(&node.cond);
            visitor.visit_block(&node.then_branch);
        });
        if let Some((_, otherwise)) = &node.else_branch {
            self.visit_expr(otherwise);
        }
    }

    fn visit_expr_while(&mut self, node: &'ast syn::ExprWhile) {
        self.scoped(|visitor| {
            visitor.visit_expr(&node.cond);
            visitor.visit_block(&node.body);
        });
    }

    fn visit_expr_let(&mut self, node: &'ast syn::ExprLet) {
        self.visit_expr(&node.expr);
        self.bind_pattern(&node.pat);
    }

    fn visit_expr_method_call(&mut self, node: &'ast ExprMethodCall) {
        let setter = node.method.to_string();
        if CHECKED_HEAD_SETTERS.contains(&setter.as_str()) && self.is_head_writer(&node.receiver) {
            self.found.push((node.span(), setter));
        }
        visit::visit_expr_method_call(self, node);
    }

    fn visit_expr_macro(&mut self, node: &'ast ExprMacro) {
        self.visit_template(&node.mac);
    }

    fn visit_stmt_macro(&mut self, node: &'ast syn::StmtMacro) {
        if is_html_macro(&node.mac) {
            self.visit_template(&node.mac);
            return;
        }
        // A statement macro can expand to `let $name = ..` for a name passed
        // to it, so any writer it mentions may be shadowed from here on.
        for name in token_idents(node.mac.tokens.clone()) {
            if self.is_writer_name(&name) {
                self.bind(name, false);
            }
        }
    }

    // Nested items have their own bodies and roles.
    fn visit_item(&mut self, _: &'ast Item) {}
}

/// Visit every Rust expression in an `html!`/`html_sync!` template: slots and
/// dynamic attribute values, including nested elements.
fn visit_template_exprs(mac: &syn::Macro, mut visit: impl FnMut(&Expr)) {
    if !is_html_macro(mac) {
        return;
    }
    let Ok(root) = syn::parse2::<HtmlRoot>(mac.tokens.clone()) else {
        return;
    };
    fn walk(nodes: &[Node], visit: &mut impl FnMut(&Expr)) {
        for node in nodes {
            match node {
                Node::Element(el) => {
                    for attr in &el.attrs {
                        if let Attribute::Dynamic { value, .. } = attr {
                            visit(value);
                        }
                    }
                    walk(&el.children, visit);
                }
                Node::Fragment(children) => walk(children, visit),
                Node::Block(expr) => visit(expr),
                Node::Text(_) | Node::Doctype(_) | Node::XmlDeclaration(_) => {}
            }
        }
    }
    walk(&root.nodes, &mut visit);
}

// ---------------------------------------------------------------------------
// Cross-file: metadata roles rendered where dispatch rejects them
// ---------------------------------------------------------------------------

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Role {
    Component,
    Layout,
    Page,
    /// Forwarded (`T::ROLE`) or application constant; not evaluated.
    Unknown,
}

impl Role {
    fn of_impl(item_impl: &ItemImpl) -> Self {
        let expr = item_impl.items.iter().find_map(|item| match item {
            ImplItem::Const(item) if item.ident == "ROLE" => Some(&item.expr),
            _ => None,
        });
        expr.map_or(Self::Component, Self::of_expr)
    }

    fn of_expr(expr: &Expr) -> Self {
        match expr {
            Expr::Path(path) => match path.path.segments.last() {
                Some(seg) if seg.ident == "PAGE" => Self::Page,
                Some(seg) if seg.ident == "LAYOUT" => Self::Layout,
                Some(seg) if seg.ident == "COMPONENT" => Self::Component,
                _ => Self::Unknown,
            },
            Expr::Paren(expr) => Self::of_expr(&expr.expr),
            Expr::Group(expr) => Self::of_expr(&expr.expr),
            Expr::Block(expr) => match expr.block.stmts.as_slice() {
                [syn::Stmt::Expr(expr, None)] => Self::of_expr(expr),
                _ => Self::Unknown,
            },
            _ => Self::Unknown,
        }
    }

    fn constant(self) -> &'static str {
        match self {
            Self::Page => "PAGE",
            Self::Layout => "LAYOUT",
            Self::Component | Self::Unknown => "COMPONENT",
        }
    }
}

/// Where a metadata role was declared, for the secondary label.
#[derive(Clone)]
struct Declaration {
    role: Role,
    file: usize,
    span: Span,
}

/// A module: the file holding its items, plus the inline `mod` path inside it.
type Location = (usize, Vec<String>);

#[derive(Default)]
struct PackageIndex {
    /// Every type definition by name; `None` locates a block-local item.
    definitions: BTreeMap<String, Vec<Option<Location>>>,
    roles: BTreeMap<String, Vec<Declaration>>,
}

impl PackageIndex {
    /// The metadata role of the package's only type named `name`, and where
    /// that type is defined.
    fn metadata_role(&self, name: &str) -> Option<(&Declaration, &Location)> {
        let [Some(location)] = self.definitions.get(name)?.as_slice() else {
            return None;
        };
        let declarations = self.roles.get(name)?;
        let first = declarations.first()?;
        let agreed = declarations.iter().all(|d| d.role == first.role);
        (agreed && matches!(first.role, Role::Page | Role::Layout)).then_some((first, location))
    }
}

struct IndexVisitor<'a> {
    file: usize,
    module: Vec<String>,
    blocks: usize,
    index: &'a mut PackageIndex,
}

impl IndexVisitor<'_> {
    fn define(&mut self, name: String, attrs: &[SynAttribute]) {
        let location = (self.blocks == 0).then(|| (self.file, self.module.clone()));
        self.index
            .definitions
            .entry(name.clone())
            .or_default()
            .push(location);
        // A derived component impl is invisible here; record its role so a
        // same-named metadata type elsewhere in the package stays ambiguous.
        if attrs.iter().any(derives_component) {
            self.index.roles.entry(name).or_default().push(Declaration {
                role: Role::Component,
                file: self.file,
                span: Span::call_site(),
            });
        }
    }
}

fn derives_component(attr: &SynAttribute) -> bool {
    if !attr.path().is_ident("derive") {
        return false;
    }
    let mut found = false;
    let _ = attr.parse_nested_meta(|meta| {
        found |= meta
            .path
            .segments
            .last()
            .is_some_and(|seg| seg.ident == "ProaComponent");
        Ok(())
    });
    found
}

impl<'ast> Visit<'ast> for IndexVisitor<'_> {
    fn visit_item_mod(&mut self, node: &'ast syn::ItemMod) {
        if node.content.is_some() {
            self.module.push(node.ident.to_string());
            visit::visit_item_mod(self, node);
            self.module.pop();
        }
    }
    fn visit_block(&mut self, node: &'ast Block) {
        self.blocks += 1;
        visit::visit_block(self, node);
        self.blocks -= 1;
    }
    fn visit_item_struct(&mut self, node: &'ast syn::ItemStruct) {
        self.define(node.ident.to_string(), &node.attrs);
        visit::visit_item_struct(self, node);
    }
    fn visit_item_enum(&mut self, node: &'ast syn::ItemEnum) {
        self.define(node.ident.to_string(), &node.attrs);
        visit::visit_item_enum(self, node);
    }
    fn visit_item_union(&mut self, node: &'ast syn::ItemUnion) {
        self.define(node.ident.to_string(), &node.attrs);
        visit::visit_item_union(self, node);
    }
    fn visit_item_type(&mut self, node: &'ast syn::ItemType) {
        self.define(node.ident.to_string(), &node.attrs);
        visit::visit_item_type(self, node);
    }
    fn visit_item_impl(&mut self, node: &'ast ItemImpl) {
        if render_trait(node).is_some() {
            if let Some(name) = type_path_last_ident(&node.self_ty) {
                let role = Role::of_impl(node);
                let span = node
                    .items
                    .iter()
                    .find_map(|item| match item {
                        ImplItem::Const(item) if item.ident == "ROLE" => Some(item.span()),
                        _ => None,
                    })
                    .unwrap_or_else(|| node.self_ty.span());
                self.index.roles.entry(name).or_default().push(Declaration {
                    role,
                    file: self.file,
                    span,
                });
            }
        }
        visit::visit_item_impl(self, node);
    }
}

/// The names one module binds directly. Rust modules do not inherit their
/// parent's names, so resolution never looks outward.
#[derive(Default)]
struct ModuleScope {
    defined: BTreeSet<String>,
    /// Alias -> (`use` path prefix, original name); `None` when the alias is
    /// bound twice.
    imports: BTreeMap<String, Option<(Vec<String>, String)>>,
    glob: bool,
    children: BTreeSet<String>,
}

impl ModuleScope {
    fn import(&mut self, alias: String, mut prefix: Vec<String>, original: String) {
        // `use a::b::{self}` and `use a::b::{self as c}` import module `b`.
        let (alias, original) = if original == "self" {
            let Some(module) = prefix.pop() else { return };
            let alias = if alias == "self" {
                module.clone()
            } else {
                alias
            };
            (alias, module)
        } else {
            (alias, original)
        };
        if alias == "_" {
            return;
        }
        self.imports
            .entry(alias)
            .and_modify(|target| *target = None)
            .or_insert(Some((prefix, original)));
    }

    fn add_use(&mut self, tree: &syn::UseTree, prefix: Vec<String>) {
        match tree {
            syn::UseTree::Path(path) => {
                let mut prefix = prefix;
                prefix.push(path.ident.to_string());
                self.add_use(&path.tree, prefix);
            }
            syn::UseTree::Name(name) => {
                self.import(name.ident.to_string(), prefix, name.ident.to_string());
            }
            syn::UseTree::Rename(rename) => {
                self.import(rename.rename.to_string(), prefix, rename.ident.to_string());
            }
            syn::UseTree::Group(group) => {
                for tree in &group.items {
                    self.add_use(tree, prefix.clone());
                }
            }
            syn::UseTree::Glob(_) => self.glob = true,
        }
    }
}

fn module_scopes(items: &[Item], path: Vec<String>, out: &mut BTreeMap<Vec<String>, ModuleScope>) {
    let mut scope = ModuleScope::default();
    for item in items {
        if let Some(ident) = type_item_ident(item) {
            scope.defined.insert(ident.to_string());
        }
        match item {
            Item::Use(item) => scope.add_use(&item.tree, Vec::new()),
            Item::Mod(item) => {
                scope.children.insert(item.ident.to_string());
                if let Some((_, items)) = &item.content {
                    let mut child = path.clone();
                    child.push(item.ident.to_string());
                    module_scopes(items, child, out);
                }
            }
            _ => {}
        }
    }
    out.insert(path, scope);
}

fn type_item_ident(item: &Item) -> Option<&syn::Ident> {
    match item {
        Item::Struct(item) => Some(&item.ident),
        Item::Enum(item) => Some(&item.ident),
        Item::Union(item) => Some(&item.ident),
        Item::Type(item) => Some(&item.ident),
        _ => None,
    }
}

/// Names a function body binds anywhere inside it, plus the generic
/// parameters of the impl and function around it. Any of them, or a glob
/// import, may shadow the enclosing module, so resolution gives up on them.
#[derive(Default)]
struct BlockShadow {
    names: BTreeSet<String>,
    glob: bool,
}

impl BlockShadow {
    fn of(generics: &[&syn::Generics], block: &Block) -> Self {
        struct Collector(BlockShadow);
        impl<'ast> Visit<'ast> for Collector {
            // Type and const parameters, on the enclosing items and on any
            // item nested in the body.
            fn visit_generic_param(&mut self, param: &'ast syn::GenericParam) {
                match param {
                    syn::GenericParam::Type(param) => {
                        self.0.names.insert(param.ident.to_string());
                    }
                    syn::GenericParam::Const(param) => {
                        self.0.names.insert(param.ident.to_string());
                    }
                    syn::GenericParam::Lifetime(_) => {}
                }
                visit::visit_generic_param(self, param);
            }
            fn visit_item(&mut self, item: &'ast Item) {
                let ident = match item {
                    Item::Mod(item) => Some(&item.ident),
                    Item::Const(item) => Some(&item.ident),
                    Item::Static(item) => Some(&item.ident),
                    Item::Fn(item) => Some(&item.sig.ident),
                    item => type_item_ident(item),
                };
                if let Some(ident) = ident {
                    self.0.names.insert(ident.to_string());
                }
                if let Item::Use(item) = item {
                    let mut scope = ModuleScope::default();
                    scope.add_use(&item.tree, Vec::new());
                    self.0.glob |= scope.glob;
                    self.0.names.extend(scope.imports.into_keys());
                }
                visit::visit_item(self, item);
            }
        }
        let mut collector = Collector(Self::default());
        for generics in generics {
            collector.visit_generics(generics);
        }
        collector.visit_block(block);
        collector.0
    }
}

/// Which crate a file's `crate::` paths name. Files under `src/` (outside
/// `src/bin/`) share the package's library or main binary module tree; any
/// other file is treated as its own crate root.
#[derive(Clone, Copy, PartialEq, Eq)]
enum CrateRoot {
    Src,
    File(usize),
}

/// Resolves rendered component paths to the module that defines them.
struct Resolver<'a> {
    files: &'a [PreparedFile<'a>],
    by_path: &'a BTreeMap<PathBuf, usize>,
}

impl Resolver<'_> {
    /// The crate-relative module path of an inline module in `file`.
    fn module_path(&self, file: usize, inline: &[String]) -> (CrateRoot, Vec<String>) {
        let prepared = &self.files[file];
        let mut path = prepared.module.clone();
        path.extend(inline.iter().cloned());
        (prepared.root, path)
    }

    /// The absolute module named by `prefix` inside module `inline` of `file`.
    fn resolve_prefix(
        &self,
        file: usize,
        inline: &[String],
        scope: &ModuleScope,
        prefix: &[String],
        depth: usize,
    ) -> Option<(CrateRoot, Vec<String>)> {
        let (first, rest) = prefix.split_first()?;
        let (root, current) = self.module_path(file, inline);
        let (root, mut path) = match first.as_str() {
            "crate" => (root, Vec::new()),
            "self" => (root, current),
            "super" => {
                let mut parent = current;
                parent.pop()?;
                (root, parent)
            }
            name if scope.children.contains(name) => {
                let mut child = current;
                child.push(name.to_owned());
                (root, child)
            }
            name => {
                // A module imported by `use`; bounded against import cycles.
                let Some(Some((target, original))) = scope.imports.get(name) else {
                    return None;
                };
                if depth > 8 {
                    return None;
                }
                let mut full = target.clone();
                full.push(original.clone());
                self.resolve_prefix(file, inline, scope, &full, depth + 1)?
            }
        };
        for segment in rest {
            match segment.as_str() {
                "super" => {
                    path.pop()?;
                }
                "self" | "crate" => return None,
                name => path.push(name.to_owned()),
            }
        }
        Some((root, path))
    }

    /// The file and inline path holding the items of a module.
    fn locate(&self, from: usize, root: CrateRoot, path: Vec<String>) -> Option<Location> {
        let src = match root {
            CrateRoot::File(file) => return Some((file, path)),
            CrateRoot::Src => self.files[from].package.join("src"),
        };
        for split in (1..=path.len()).rev() {
            let relative: PathBuf = path[..split].iter().collect();
            for candidate in [
                src.join(&relative).with_extension("rs"),
                src.join(&relative).join("mod.rs"),
            ] {
                if let Some(&file) = self.by_path.get(&candidate) {
                    return Some((file, path[split..].to_vec()));
                }
            }
        }
        // Both a library and a binary root: `crate` is ambiguous unless the
        // path is written in one of them.
        let roots: Vec<usize> = ["lib.rs", "main.rs"]
            .iter()
            .filter_map(|name| self.by_path.get(&src.join(name)).copied())
            .collect();
        let root = match roots.as_slice() {
            _ if roots.contains(&from) => from,
            [only] => *only,
            _ => return None,
        };
        Some((root, path))
    }

    /// Where the type a rendered path names is defined, and its name there.
    fn resolve(
        &self,
        file: usize,
        scopes: &BTreeMap<Vec<String>, ModuleScope>,
        finding: &Finding,
    ) -> Option<(Location, String)> {
        let path = &finding.path;
        if path.leading_colon.is_some() {
            return None;
        }
        let segments: Vec<String> = path.segments.iter().map(|s| s.ident.to_string()).collect();
        let (last, prefix) = segments.split_last()?;
        let first = segments.first()?;
        if finding.shadow.glob || finding.shadow.names.contains(first) {
            return None;
        }
        let scope = scopes.get(&finding.module)?;
        if prefix.is_empty() {
            if scope.defined.contains(last) {
                if scope.imports.contains_key(last) {
                    return None;
                }
                return Some(((file, finding.module.clone()), last.clone()));
            }
            // A glob import or the prelude may supply anything else.
            let Some(Some((target, original))) = scope.imports.get(last) else {
                return None;
            };
            let (root, module) = self.resolve_prefix(file, &finding.module, scope, target, 0)?;
            return Some((self.locate(file, root, module)?, original.clone()));
        }
        let (root, module) = self.resolve_prefix(file, &finding.module, scope, prefix, 0)?;
        Some((self.locate(file, root, module)?, last.clone()))
    }
}

/// Component expressions a template slot, `render_child`, or `Suspense::new`
/// argument renders, following `proa_macros::render_control::lower`: only a
/// block's tail renders, and control flow directs it into the selected branch
/// or loop body. html templates nested in a slot are visited separately.
fn rendered_slot<'a>(expr: &'a Expr, out: &mut Vec<(&'a SynPath, Span)>) {
    match expr {
        Expr::If(node) => {
            rendered_tail(&node.then_branch, out);
            if let Some((_, otherwise)) = &node.else_branch {
                rendered_slot(otherwise, out);
            }
        }
        Expr::Match(node) => {
            for arm in &node.arms {
                rendered_slot(&arm.body, out);
            }
        }
        Expr::ForLoop(node) => rendered_tail(&node.body, out),
        Expr::While(node) => rendered_tail(&node.body, out),
        // A breaking loop also renders its break value, which stays opaque.
        Expr::Loop(node) => rendered_tail(&node.body, out),
        // A labeled block renders its break value instead of its tail.
        Expr::Block(node) if node.label.is_none() => rendered_tail(&node.block, out),
        Expr::Block(_) | Expr::Break(_) | Expr::Continue(_) | Expr::Return(_) => {}
        _ => rendered_components(expr, out),
    }
}

fn rendered_tail<'a>(block: &'a Block, out: &mut Vec<(&'a SynPath, Span)>) {
    if let Some(syn::Stmt::Expr(tail, None)) = block.stmts.last() {
        rendered_slot(tail, out);
    }
}

/// The component a rendered value constructs. Wrappers that forward their
/// child's role are unwrapped.
fn rendered_components<'a>(expr: &'a Expr, out: &mut Vec<(&'a SynPath, Span)>) {
    match expr {
        Expr::Paren(inner) => rendered_slot(&inner.expr, out),
        Expr::Group(inner) => rendered_slot(&inner.expr, out),
        Expr::Struct(node) => out.push((&node.path, expr.span())),
        Expr::Path(node) if node.qself.is_none() && is_type_like(&node.path) => {
            out.push((&node.path, expr.span()));
        }
        Expr::Call(call) => {
            let Expr::Path(func) = call.func.as_ref() else {
                return;
            };
            let Some(last) = func.path.segments.last() else {
                return;
            };
            let name = last.ident.to_string();
            if matches!(
                name.as_str(),
                "to_async" | "to_send" | "SyncToAsync" | "SendSyncToAsync" | "Some"
            ) && call.args.len() == 1
            {
                rendered_slot(&call.args[0], out);
            } else if matches!(name.as_str(), "new" | "default") && func.path.segments.len() >= 2 {
                // `Type::new(..)` names the type it constructs. `Suspense::new`
                // is a boundary rather than a metadata provider and has no
                // metadata role in the package index.
                out.push((&func.path, expr.span()));
            } else if func.path.segments.len() == 1 && is_type_like(&func.path) {
                out.push((&func.path, expr.span()));
            }
        }
        _ => {}
    }
}

fn is_type_like(path: &SynPath) -> bool {
    path.segments.last().is_some_and(|seg| {
        let name = seg.ident.to_string();
        let mut chars = name.chars();
        chars.next().is_some_and(char::is_uppercase) && chars.any(char::is_lowercase)
    })
}

/// The component name of a path recorded by [`rendered_components`]:
/// `Type::new` and `Type::default` name `Type`.
fn component_path(path: &SynPath) -> SynPath {
    let mut path = path.clone();
    let constructor = path.segments.len() >= 2
        && path
            .segments
            .last()
            .is_some_and(|seg| seg.ident == "new" || seg.ident == "default");
    if constructor {
        let keep = path.segments.len() - 1;
        path.segments = path.segments.iter().take(keep).cloned().collect();
    }
    path
}

fn is_html_macro(mac: &syn::Macro) -> bool {
    mac.path
        .segments
        .last()
        .is_some_and(|seg| seg.ident == "html" || seg.ident == "html_sync")
}

fn html_slot_exprs<'a>(nodes: &'a [Node], out: &mut Vec<&'a Expr>) {
    for node in nodes {
        match node {
            Node::Element(el) => html_slot_exprs(&el.children, out),
            Node::Fragment(children) => html_slot_exprs(children, out),
            Node::Block(expr) => out.push(expr),
            Node::Text(_) | Node::Doctype(_) | Node::XmlDeclaration(_) => {}
        }
    }
}

struct Finding {
    /// The enclosing Page, or `None` for a `Suspense` argument.
    page: Option<String>,
    path: SynPath,
    span: Span,
    /// The inline module holding the usage, within its file.
    module: Vec<String>,
    shadow: Rc<BlockShadow>,
}

/// Collects components rendered inside `Suspense::new(..)` arguments
/// anywhere in a file, and inside the body of a `PAGE` impl.
struct UsageVisitor<'a> {
    page: Option<String>,
    module: &'a [String],
    shadow: Rc<BlockShadow>,
    suspense_depth: usize,
    findings: &'a mut Vec<Finding>,
}

impl UsageVisitor<'_> {
    fn record(&mut self, expr: &Expr) {
        if self.suspense_depth == 0 && self.page.is_none() {
            return;
        }
        let mut found = Vec::new();
        rendered_slot(expr, &mut found);
        for (path, span) in found {
            self.findings.push(Finding {
                page: (self.suspense_depth == 0)
                    .then(|| self.page.clone())
                    .flatten(),
                path: component_path(path),
                span,
                module: self.module.to_vec(),
                shadow: Rc::clone(&self.shadow),
            });
        }
    }

    fn visit_template(&mut self, mac: &syn::Macro) {
        let Ok(root) = syn::parse2::<HtmlRoot>(mac.tokens.clone()) else {
            return;
        };
        let mut slots = Vec::new();
        html_slot_exprs(&root.nodes, &mut slots);
        for expr in slots {
            self.record(expr);
            self.visit_expr(expr);
        }
    }
}

fn is_suspense_new(call: &ExprCall) -> bool {
    let Expr::Path(func) = call.func.as_ref() else {
        return false;
    };
    let segments: Vec<_> = func.path.segments.iter().collect();
    matches!(segments.as_slice(), [.., ty, method] if ty.ident == "Suspense" && method.ident == "new")
}

fn is_render_child(call: &ExprCall) -> bool {
    let Expr::Path(func) = call.func.as_ref() else {
        return false;
    };
    func.path
        .segments
        .last()
        .is_some_and(|seg| seg.ident == "render_child" || seg.ident == "render_send_child")
}

impl<'ast> Visit<'ast> for UsageVisitor<'_> {
    fn visit_expr_call(&mut self, node: &'ast ExprCall) {
        if is_suspense_new(node) {
            self.suspense_depth += 1;
            for arg in &node.args {
                self.record(arg);
                self.visit_expr(arg);
            }
            self.suspense_depth -= 1;
            return;
        }
        if is_render_child(node) && node.args.len() == 2 {
            self.record(&node.args[1]);
        }
        visit::visit_expr_call(self, node);
    }

    fn visit_expr_macro(&mut self, node: &'ast ExprMacro) {
        if is_html_macro(&node.mac) {
            self.visit_template(&node.mac);
        }
        visit::visit_expr_macro(self, node);
    }

    fn visit_stmt_macro(&mut self, node: &'ast syn::StmtMacro) {
        if is_html_macro(&node.mac) {
            self.visit_template(&node.mac);
        }
        visit::visit_stmt_macro(self, node);
    }
}

struct PreparedFile<'a> {
    path: &'a Path,
    source: &'a str,
    file: &'a File,
    package: PathBuf,
    root: CrateRoot,
    /// The file's module path within its crate.
    module: Vec<String>,
    test_ranges: Vec<RangeInclusive<usize>>,
}

/// A file's crate and module path from its location under `src/`.
fn crate_position(absolute: &Path, package: &Path, index: usize) -> (CrateRoot, Vec<String>) {
    let own = (CrateRoot::File(index), Vec::new());
    let Ok(relative) = absolute.strip_prefix(package.join("src")) else {
        return own;
    };
    let mut module: Vec<String> = relative
        .iter()
        .filter_map(|part| part.to_str().map(str::to_owned))
        .collect();
    if module.first().is_some_and(|first| first == "bin") {
        return own;
    }
    match module
        .pop()
        .as_deref()
        .and_then(|file| file.strip_suffix(".rs"))
    {
        Some("lib" | "main") if module.is_empty() => {}
        Some("mod") => {}
        Some(stem) => module.push(stem.to_owned()),
        None => return own,
    }
    (CrateRoot::Src, module)
}

pub(super) fn lint_parsed(
    sources: &[(PathBuf, String)],
    parsed: &[Option<&File>],
    reporting: &BTreeSet<PathBuf>,
    include_tests: bool,
) -> Vec<Diagnostic> {
    let mut package_by_dir: BTreeMap<PathBuf, PathBuf> = BTreeMap::new();
    let mut package_of = |absolute: &Path| {
        let dir = absolute.parent().unwrap_or(absolute).to_path_buf();
        package_by_dir
            .entry(dir.clone())
            .or_insert_with(|| {
                super::asset_urls::package_scope(&dir).unwrap_or(absolute.to_path_buf())
            })
            .clone()
    };
    // An unparsed file could define a same-named type, so its package's
    // index would be incomplete.
    let mut incomplete = BTreeSet::new();
    let mut files: Vec<PreparedFile<'_>> = Vec::new();
    let mut by_path = BTreeMap::new();
    for ((path, source), file) in sources.iter().zip(parsed) {
        if !include_tests && is_test_path(path) {
            continue;
        }
        let absolute = content::absolute(path);
        let package = package_of(&absolute);
        let Some(file) = *file else {
            incomplete.insert(package);
            continue;
        };
        let index = files.len();
        let (root, module) = crate_position(&absolute, &package, index);
        by_path.insert(absolute, index);
        files.push(PreparedFile {
            path,
            source,
            file,
            package,
            root,
            module,
            test_ranges: if include_tests {
                Vec::new()
            } else {
                cfg_test_module_line_ranges(source)
            },
        });
    }

    let mut packages: BTreeMap<&Path, PackageIndex> = BTreeMap::new();
    for (index, prepared) in files.iter().enumerate() {
        IndexVisitor {
            file: index,
            module: Vec::new(),
            blocks: 0,
            index: packages.entry(&prepared.package).or_default(),
        }
        .visit_file(prepared.file);
    }

    let resolver = Resolver {
        files: &files,
        by_path: &by_path,
    };
    let mut diagnostics = Vec::new();
    for (index, prepared) in files.iter().enumerate() {
        if !reporting.contains(&content::absolute(prepared.path))
            || incomplete.contains(&prepared.package)
        {
            continue;
        }
        let Some(package) = packages.get(prepared.package.as_path()) else {
            continue;
        };
        let mut scopes = BTreeMap::new();
        module_scopes(&prepared.file.items, Vec::new(), &mut scopes);
        let mut findings = Vec::new();
        collect_usages(&prepared.file.items, &[], &mut findings);
        for finding in findings {
            let start = finding.span.start();
            if line_in_ranges(start.line, &prepared.test_ranges) {
                continue;
            }
            let Some((location, name)) = resolver.resolve(index, &scopes, &finding) else {
                continue;
            };
            let Some((declaration, defined)) = package.metadata_role(&name) else {
                continue;
            };
            if *defined != location {
                continue;
            }
            diagnostics.push(role_diagnostic(
                prepared,
                &files[declaration.file],
                &finding,
                &name,
                declaration,
            ));
        }
    }
    dedupe_diagnostics(&mut diagnostics);
    diagnostics
}

/// Visit every function body; a `PAGE` impl's body is a Page site.
fn collect_usages(items: &[Item], module: &[String], findings: &mut Vec<Finding>) {
    let visit = |generics: &[&syn::Generics],
                 block: &Block,
                 page: Option<String>,
                 findings: &mut Vec<Finding>| {
        UsageVisitor {
            page,
            module,
            shadow: Rc::new(BlockShadow::of(generics, block)),
            suspense_depth: 0,
            findings,
        }
        .visit_block(block);
    };
    for item in items {
        match item {
            Item::Impl(item_impl) => {
                let page = match (render_trait(item_impl), Role::of_impl(item_impl)) {
                    (Some((_, body)), Role::Page) => {
                        type_path_last_ident(&item_impl.self_ty).map(|name| (name, body))
                    }
                    _ => None,
                };
                for impl_item in &item_impl.items {
                    let ImplItem::Fn(method) = impl_item else {
                        continue;
                    };
                    let site = page
                        .as_ref()
                        .filter(|(_, body)| method.sig.ident == *body)
                        .map(|(name, _)| name.clone());
                    visit(
                        &[&item_impl.generics, &method.sig.generics],
                        &method.block,
                        site,
                        findings,
                    );
                }
            }
            Item::Mod(item_mod) => {
                if let Some((_, items)) = &item_mod.content {
                    let mut child = module.to_vec();
                    child.push(item_mod.ident.to_string());
                    collect_usages(items, &child, findings);
                }
            }
            Item::Fn(item_fn) => visit(&[&item_fn.sig.generics], &item_fn.block, None, findings),
            _ => {}
        }
    }
}

fn role_diagnostic(
    prepared: &PreparedFile<'_>,
    declared_in: &PreparedFile<'_>,
    finding: &Finding,
    name: &str,
    declaration: &Declaration,
) -> Diagnostic {
    let start = finding.span.start();
    let role = declaration.role.constant();
    let display = display_path(prepared.path);
    let (code, message, note, help) = if let Some(page) = &finding.page {
        let help = match declaration.role {
            Role::Layout => format!("layouts belong above the selected Page: render `{page}` inside `{name}`, or give `{name}` the default `COMPONENT` role if it only renders markup"),
            _ => format!("a document selects exactly one Page: render `{name}` from its own route, or extract the shared body into a `COMPONENT`"),
        };
        (
            "render/head-role-in-page",
            format!("`{name}` declares `ComponentRole::{role}` but is rendered inside the Page `{page}`"),
            "the Page seals the document head before its body, so dispatch rejects any later layout or Page with `HeadError::Closed`".to_owned(),
            help,
        )
    } else {
        (
            "render/head-role-in-suspense",
            format!("`{name}` declares `ComponentRole::{role}` but is rendered inside `Suspense`"),
            "Suspense children and fallbacks are body-only, so dispatch rejects a layout or Page there with `HeadError::Excluded`".to_owned(),
            "render the Page and its layouts outside the boundary, and place `Suspense` inside the Page body around the slow content".to_owned(),
        )
    };
    let usage = SourceRange::from_span(&display, finding.span);
    let declared = SourceRange::from_span(&display_path(declared_in.path), declaration.span);
    Diagnostic::new(
        &display,
        start.line,
        start.column + 1,
        Severity::Error,
        code,
        message,
    )
    .with_label(SourceLabel::new(
        usage,
        prepared.source,
        "rendered here",
        true,
    ))
    .with_label(SourceLabel::new(
        declared,
        declared_in.source,
        format!("`{name}` declares `ComponentRole::{role}` here"),
        false,
    ))
    .with_note(note)
    .with_help(help)
}