Skip to main content

fallow_api/
dead_code_codeclimate.rs

1//! Shared dead-code CodeClimate issue construction.
2
3#[path = "dead_code_codeclimate_component_health.rs"]
4mod component_health;
5
6use std::path::Path;
7
8use fallow_config::{RulesConfig, Severity};
9use fallow_output::{
10    CodeClimateIssue, CodeClimateIssueInput, CodeClimateSeverity, build_codeclimate_issue,
11    codeclimate_fingerprint_hash, normalize_uri,
12};
13use fallow_types::envelope::AuditIntroduced;
14use fallow_types::identity::dead_code_finding_id;
15use fallow_types::output_dead_code::{
16    EffectiveSeverity, GatedFinding, ReachabilityCaveat, caveat_suffix,
17};
18use fallow_types::results::AnalysisResults;
19
20#[path = "dead_code_codeclimate_caller_review.rs"]
21mod caller_review;
22#[path = "dead_code_codeclimate_catalog.rs"]
23mod catalog_issues;
24#[path = "dead_code_codeclimate_component_io.rs"]
25mod component_io;
26#[path = "dead_code_codeclimate_namespace_escape.rs"]
27mod namespace_escape;
28use caller_review::{push_absent_component_prop_issues, push_constant_parameter_issues};
29use catalog_issues::{
30    push_empty_catalog_group_issues, push_misconfigured_dependency_override_issues,
31    push_unresolved_catalog_reference_issues, push_unused_catalog_entry_issues,
32    push_unused_dependency_override_issues,
33};
34use component_io::{
35    push_unused_component_input_issues, push_unused_component_output_issues,
36    push_unused_svelte_event_issues,
37};
38
39fn severity_to_codeclimate(s: Severity) -> CodeClimateSeverity {
40    match s {
41        Severity::Error => CodeClimateSeverity::Major,
42        Severity::Warn => CodeClimateSeverity::Minor,
43        Severity::Off => unreachable!(),
44    }
45}
46
47/// The CodeClimate severity for one finding: its gate severity when the
48/// finding carries one, otherwise the configured rule severity (a saved report
49/// from an older version has no gate severity).
50///
51/// A saved finding exists, so its rule was on when it was reported. When the
52/// config at render time sets the rule `off`, the severity is `minor`.
53fn gate_codeclimate(effective: Option<EffectiveSeverity>, rule: Severity) -> CodeClimateSeverity {
54    match effective {
55        Some(EffectiveSeverity::Error) => CodeClimateSeverity::Major,
56        Some(EffectiveSeverity::Warn) => CodeClimateSeverity::Minor,
57        None => match rule {
58            Severity::Off => CodeClimateSeverity::Minor,
59            Severity::Error | Severity::Warn => severity_to_codeclimate(rule),
60        },
61    }
62}
63
64fn finding_codeclimate(finding: &impl GatedFinding, rule: Severity) -> CodeClimateSeverity {
65    gate_codeclimate(finding.effective_severity(), rule)
66}
67
68fn cc_path(path: &Path, root: &Path) -> String {
69    normalize_uri(
70        &path
71            .strip_prefix(root)
72            .unwrap_or(path)
73            .display()
74            .to_string(),
75    )
76}
77
78/// The caveat parenthetical a CodeClimate `description` ends with, or an empty
79/// string when the verdict rests on a fully analyzed run.
80///
81/// `description` is the one field GitLab renders inline on the MR diff, and it
82/// is also what `CiIssue` carries into the PR-comment and review-comment
83/// bodies. Those bodies offer a mutation, so the sentence that offers it has to
84/// say when the evidence behind it is incomplete. The suffix is the same
85/// parenthetical the human report and the SARIF message already use, so one
86/// finding reads identically across every surface.
87///
88/// Deliberately NOT part of the fingerprint: `codeclimate_fingerprint_hash` is
89/// fed rule id plus location by every call site in this file, never the
90/// description, so a finding that gains or loses a caveat keeps its identity
91/// and no previously resolved review thread reopens.
92fn cc_caveat_suffix(caveats: &[ReachabilityCaveat]) -> String {
93    caveat_suffix(caveats).unwrap_or_default()
94}
95
96/// Build one dead-code issue with its stable fingerprint.
97///
98/// `input.fingerprint` is the legacy fingerprint: the value that Fallow gave
99/// this issue before findings had a `finding_id`. For most kinds it holds the
100/// line, so a line shift above the finding changed it.
101///
102/// When the finding has a `finding_id`, the fingerprint is the FNV-1a 64 hash
103/// of that id plus `discriminator`, as 16 lowercase hex digits. The id holds
104/// no line and no column, so a line shift keeps the fingerprint. The hash
105/// covers the full id, not only the hex part of the id, so the `~k` tiebreak
106/// suffix keeps two findings with the same base id apart. The 16-hex form is
107/// the form that GitLab Code Quality and the review marker regex accept.
108/// `discriminator` separates the issues of one finding that emits one issue
109/// per location (duplicate exports, unlisted-dependency import sites). See
110/// [`location_discriminators`].
111///
112/// A finding without an id (a saved report from an older version) keeps the
113/// legacy fingerprint, so its review threads stay matched.
114///
115/// `introduced` is the audit flag of the finding. An audit sets it when it
116/// compares the run with a base snapshot. The issue then carries the
117/// attribution for the inline review comment.
118fn dead_code_issue(
119    finding_id: Option<&str>,
120    introduced: Option<AuditIntroduced>,
121    discriminator: &[&str],
122    input: CodeClimateIssueInput<'_>,
123) -> CodeClimateIssue {
124    let mut issue = build_codeclimate_issue(input);
125    issue.audit = introduced.map(|AuditIntroduced(introduced)| audit_review_context(introduced));
126    if let Some(id) = finding_id {
127        let mut parts = Vec::with_capacity(discriminator.len() + 1);
128        parts.push(id);
129        parts.extend_from_slice(discriminator);
130        let stable = codeclimate_fingerprint_hash(&parts);
131        if stable != issue.fingerprint {
132            issue.legacy_fingerprint = Some(std::mem::replace(&mut issue.fingerprint, stable));
133        }
134    }
135    issue
136}
137
138/// The audit facts of an inline review comment for a finding that an audit
139/// compared with the base snapshot. `introduced` is the audit flag.
140pub(crate) const fn audit_review_context(introduced: bool) -> fallow_output::AuditReviewContext {
141    fallow_output::AuditReviewContext {
142        attribution: if introduced {
143            fallow_output::AuditFindingAttribution::Introduced
144        } else {
145            fallow_output::AuditFindingAttribution::Inherited
146        },
147        gate_exemption: None,
148        gate: None,
149    }
150}
151
152/// The discriminator of each location of one finding, in input order.
153///
154/// A location is named by what it is, not by where it is. The only content a
155/// location carries next to the finding id is its path: the engine reports
156/// one unlisted-dependency import site per file, and every location of a
157/// duplicate export has the same export name, which the id already holds. So
158/// the discriminator is the path. Only locations with the same path (the same
159/// content) also get a position: the first by line keeps the bare path, the
160/// next one gets `~1`, and so on. A location added to or removed from another
161/// file, or after this one in the same file, never changes it.
162fn location_discriminators(locations: &[(String, u32, u32)]) -> Vec<Vec<String>> {
163    locations
164        .iter()
165        .enumerate()
166        .map(|(index, (path, line, col))| {
167            let earlier = locations
168                .iter()
169                .enumerate()
170                .filter(|(other, (other_path, other_line, other_col))| {
171                    other_path == path && (other_line, other_col, *other) < (line, col, index)
172                })
173                .count();
174            if earlier == 0 {
175                vec![path.clone()]
176            } else {
177                vec![path.clone(), format!("~{earlier}")]
178            }
179        })
180        .collect()
181}
182
183/// Push CodeClimate issues for unused dependencies with a shared structure.
184fn push_dep_cc_issues<'a, I>(
185    issues: &mut Vec<CodeClimateIssue>,
186    deps: I,
187    root: &Path,
188    rule_id: &str,
189    location_label: &str,
190    severity: Severity,
191) where
192    I: IntoIterator<
193        Item = (
194            &'a fallow_types::results::UnusedDependency,
195            &'a [ReachabilityCaveat],
196            Option<EffectiveSeverity>,
197            Option<&'a str>,
198            Option<AuditIntroduced>,
199        ),
200    >,
201{
202    for (dep, caveats, effective, finding_id, introduced) in deps {
203        let level = gate_codeclimate(effective, severity);
204        let path = cc_path(&dep.path, root);
205        let line = if dep.line > 0 { Some(dep.line) } else { None };
206        let fp = codeclimate_fingerprint_hash(&[rule_id, &dep.package_name]);
207        let workspace_context = if dep.used_in_workspaces.is_empty() {
208            String::new()
209        } else {
210            let workspaces = dep
211                .used_in_workspaces
212                .iter()
213                .map(|path| cc_path(path, root))
214                .collect::<Vec<_>>()
215                .join(", ");
216            format!("; imported in other workspaces: {workspaces}")
217        };
218        issues.push(dead_code_issue(
219            finding_id,
220            introduced,
221            &[],
222            CodeClimateIssueInput {
223                check_name: rule_id,
224                description: &format!(
225                    "Package '{}' is in {location_label} but never imported{workspace_context}{}",
226                    dep.package_name,
227                    cc_caveat_suffix(caveats)
228                ),
229                severity: level,
230                category: "Bug Risk",
231                path: &path,
232                begin_line: line,
233                fingerprint: &fp,
234            },
235        ));
236    }
237}
238
239fn push_unused_file_issues(
240    issues: &mut Vec<CodeClimateIssue>,
241    files: &[fallow_types::output_dead_code::UnusedFileFinding],
242    root: &Path,
243    severity: Severity,
244) {
245    if files.is_empty() {
246        return;
247    }
248    for entry in files {
249        let level = finding_codeclimate(entry, severity);
250        let path = cc_path(&entry.file.path, root);
251        let fp = codeclimate_fingerprint_hash(&["fallow/unused-file", &path]);
252        issues.push(dead_code_issue(
253            entry.finding_id.as_deref(),
254            entry.introduced,
255            &[],
256            CodeClimateIssueInput {
257                check_name: "fallow/unused-file",
258                description: &format!(
259                    "File is not reachable from any entry point{}",
260                    cc_caveat_suffix(&entry.reachability_caveats)
261                ),
262                severity: level,
263                category: "Bug Risk",
264                path: &path,
265                begin_line: None,
266                fingerprint: &fp,
267            },
268        ));
269    }
270}
271
272/// Push CodeClimate issues for unused exports or unused types.
273///
274/// `direct_label` / `re_export_label` let the same helper produce the right
275/// prose for both `unused-export` (Export / Re-export) and `unused-type`
276/// (Type export / Type re-export) rule ids.
277struct UnusedExportIssuesInput<'a, I> {
278    issues: &'a mut Vec<CodeClimateIssue>,
279    exports: I,
280    root: &'a Path,
281    rule_id: &'a str,
282    direct_label: &'a str,
283    re_export_label: &'a str,
284    severity: Severity,
285}
286
287fn push_unused_export_issues<'a, I>(input: UnusedExportIssuesInput<'a, I>)
288where
289    I: IntoIterator<
290        Item = (
291            &'a fallow_types::results::UnusedExport,
292            &'a [ReachabilityCaveat],
293            Option<EffectiveSeverity>,
294            Option<&'a str>,
295            Option<AuditIntroduced>,
296        ),
297    >,
298{
299    for (export, caveats, effective, finding_id, introduced) in input.exports {
300        let level = gate_codeclimate(effective, input.severity);
301        let path = cc_path(&export.path, input.root);
302        let kind = if export.is_re_export {
303            input.re_export_label
304        } else {
305            input.direct_label
306        };
307        let line_str = export.line.to_string();
308        let fp =
309            codeclimate_fingerprint_hash(&[input.rule_id, &path, &line_str, &export.export_name]);
310        input.issues.push(dead_code_issue(
311            finding_id,
312            introduced,
313            &[],
314            CodeClimateIssueInput {
315                check_name: input.rule_id,
316                description: &format!(
317                    "{kind} '{}' is never imported by other modules{}",
318                    export.export_name,
319                    cc_caveat_suffix(caveats)
320                ),
321                severity: level,
322                category: "Bug Risk",
323                path: &path,
324                begin_line: Some(export.line),
325                fingerprint: &fp,
326            },
327        ));
328    }
329}
330
331fn push_private_type_leak_issues(
332    issues: &mut Vec<CodeClimateIssue>,
333    leaks: &[fallow_types::output_dead_code::PrivateTypeLeakFinding],
334    root: &Path,
335    severity: Severity,
336) {
337    if leaks.is_empty() {
338        return;
339    }
340    for entry in leaks {
341        let level = finding_codeclimate(entry, severity);
342        let leak = &entry.leak;
343        let path = cc_path(&leak.path, root);
344        let line_str = leak.line.to_string();
345        let fp = codeclimate_fingerprint_hash(&[
346            "fallow/private-type-leak",
347            &path,
348            &line_str,
349            &leak.export_name,
350            &leak.type_name,
351        ]);
352        issues.push(dead_code_issue(
353            entry.finding_id.as_deref(),
354            entry.introduced,
355            &[],
356            CodeClimateIssueInput {
357                check_name: "fallow/private-type-leak",
358                description: &format!(
359                    "Export '{}' references private type '{}'",
360                    leak.export_name, leak.type_name
361                ),
362                severity: level,
363                category: "Bug Risk",
364                path: &path,
365                begin_line: Some(leak.line),
366                fingerprint: &fp,
367            },
368        ));
369    }
370}
371
372fn push_deprecated_export_issues(
373    issues: &mut Vec<CodeClimateIssue>,
374    findings: &[fallow_types::output_dead_code::DeprecatedExportInUseFinding],
375    root: &Path,
376    severity: Severity,
377) {
378    for entry in findings {
379        let level = finding_codeclimate(entry, severity);
380        let export = &entry.export;
381        let path = cc_path(&export.path, root);
382        let line_str = export.line.to_string();
383        let fp = codeclimate_fingerprint_hash(&[
384            "fallow/deprecated-export-in-use",
385            &path,
386            &line_str,
387            &export.export_name,
388        ]);
389        issues.push(dead_code_issue(
390            entry.finding_id.as_deref(),
391            entry.introduced,
392            &[],
393            CodeClimateIssueInput {
394                check_name: "fallow/deprecated-export-in-use",
395                description: &export.description(),
396                severity: level,
397                category: "Compatibility",
398                path: &path,
399                begin_line: Some(export.line),
400                fingerprint: &fp,
401            },
402        ));
403    }
404}
405
406fn push_type_only_dep_issues(
407    issues: &mut Vec<CodeClimateIssue>,
408    deps: &[fallow_types::output_dead_code::TypeOnlyDependencyFinding],
409    root: &Path,
410    severity: Severity,
411) {
412    if deps.is_empty() {
413        return;
414    }
415    for entry in deps {
416        let level = finding_codeclimate(entry, severity);
417        let dep = &entry.dep;
418        let path = cc_path(&dep.path, root);
419        let line = if dep.line > 0 { Some(dep.line) } else { None };
420        let fp = codeclimate_fingerprint_hash(&["fallow/type-only-dependency", &dep.package_name]);
421        issues.push(dead_code_issue(
422            entry.finding_id.as_deref(),
423            entry.introduced,
424            &[],
425            CodeClimateIssueInput {
426                check_name: "fallow/type-only-dependency",
427                description: &format!(
428                    "Package '{}' is only imported via type-only imports (consider moving to devDependencies)",
429                    dep.package_name
430                ),
431                severity: level,
432                category: "Bug Risk",
433                path: &path,
434                begin_line: line,
435                fingerprint: &fp,
436            },
437        ));
438    }
439}
440
441fn push_test_only_dep_issues(
442    issues: &mut Vec<CodeClimateIssue>,
443    deps: &[fallow_types::output_dead_code::TestOnlyDependencyFinding],
444    root: &Path,
445    severity: Severity,
446) {
447    if deps.is_empty() {
448        return;
449    }
450    for entry in deps {
451        let level = finding_codeclimate(entry, severity);
452        let dep = &entry.dep;
453        let path = cc_path(&dep.path, root);
454        let line = if dep.line > 0 { Some(dep.line) } else { None };
455        let fp = codeclimate_fingerprint_hash(&["fallow/test-only-dependency", &dep.package_name]);
456        issues.push(dead_code_issue(
457            entry.finding_id.as_deref(),
458            entry.introduced,
459            &[],
460            CodeClimateIssueInput {
461                check_name: "fallow/test-only-dependency",
462                description: &format!(
463                    "Package '{}' is only imported by test files (consider moving to devDependencies)",
464                    dep.package_name
465                ),
466                severity: level,
467                category: "Bug Risk",
468                path: &path,
469                begin_line: line,
470                fingerprint: &fp,
471            },
472        ));
473    }
474}
475
476fn push_dev_dep_in_prod_issues(
477    issues: &mut Vec<CodeClimateIssue>,
478    deps: &[fallow_types::output_dead_code::DevDependencyInProductionFinding],
479    root: &Path,
480    severity: Severity,
481) {
482    if deps.is_empty() {
483        return;
484    }
485    for entry in deps {
486        let level = finding_codeclimate(entry, severity);
487        let dep = &entry.dep;
488        let path = cc_path(&dep.path, root);
489        let line = if dep.line > 0 { Some(dep.line) } else { None };
490        let fp = codeclimate_fingerprint_hash(&[
491            "fallow/dev-dependency-in-production",
492            &dep.package_name,
493        ]);
494        issues.push(dead_code_issue(
495            entry.finding_id.as_deref(),
496            entry.introduced,
497            &[],
498            CodeClimateIssueInput {
499                check_name: "fallow/dev-dependency-in-production",
500                description: &format!(
501                    "devDependency '{}' is imported by production code at runtime (consider moving to dependencies)",
502                    dep.package_name
503                ),
504                severity: level,
505                category: "Bug Risk",
506                path: &path,
507                begin_line: line,
508                fingerprint: &fp,
509            },
510        ));
511    }
512}
513
514/// Push CodeClimate issues for unused enum or class members.
515///
516/// `entity_label` is `"Enum"` or `"Class"` so the rendered description reads
517/// "Enum member ..." or "Class member ..." accordingly.
518fn push_unused_member_issues<'a, I>(
519    issues: &mut Vec<CodeClimateIssue>,
520    members: I,
521    root: &Path,
522    rule_id: &str,
523    entity_label: &str,
524    severity: Severity,
525) where
526    I: IntoIterator<
527        Item = (
528            &'a fallow_types::results::UnusedMember,
529            &'a [ReachabilityCaveat],
530            Option<EffectiveSeverity>,
531            Option<&'a str>,
532            Option<AuditIntroduced>,
533        ),
534    >,
535{
536    for (member, caveats, effective, finding_id, introduced) in members {
537        let level = gate_codeclimate(effective, severity);
538        let path = cc_path(&member.path, root);
539        let line_str = member.line.to_string();
540        let fp = codeclimate_fingerprint_hash(&[
541            rule_id,
542            &path,
543            &line_str,
544            &member.parent_name,
545            &member.member_name,
546        ]);
547        issues.push(dead_code_issue(
548            finding_id,
549            introduced,
550            &[],
551            CodeClimateIssueInput {
552                check_name: rule_id,
553                description: &format!(
554                    "{entity_label} member '{}.{}' is never referenced{}",
555                    member.parent_name,
556                    member.member_name,
557                    cc_caveat_suffix(caveats)
558                ),
559                severity: level,
560                category: "Bug Risk",
561                path: &path,
562                begin_line: Some(member.line),
563                fingerprint: &fp,
564            },
565        ));
566    }
567}
568
569fn push_unresolved_import_issues(
570    issues: &mut Vec<CodeClimateIssue>,
571    imports: &[fallow_types::output_dead_code::UnresolvedImportFinding],
572    root: &Path,
573    severity: Severity,
574) {
575    if imports.is_empty() {
576        return;
577    }
578    for entry in imports {
579        let level = finding_codeclimate(entry, severity);
580        let import = &entry.import;
581        let path = cc_path(&import.path, root);
582        let line_str = import.line.to_string();
583        let fp = codeclimate_fingerprint_hash(&[
584            "fallow/unresolved-import",
585            &path,
586            &line_str,
587            &import.specifier,
588        ]);
589        issues.push(dead_code_issue(
590            entry.finding_id.as_deref(),
591            entry.introduced,
592            &[],
593            CodeClimateIssueInput {
594                check_name: "fallow/unresolved-import",
595                description: &format!("Import '{}' could not be resolved", import.specifier),
596                severity: level,
597                category: "Bug Risk",
598                path: &path,
599                begin_line: Some(import.line),
600                fingerprint: &fp,
601            },
602        ));
603    }
604}
605
606fn push_unlisted_dep_issues(
607    issues: &mut Vec<CodeClimateIssue>,
608    deps: &[fallow_types::output_dead_code::UnlistedDependencyFinding],
609    root: &Path,
610    severity: Severity,
611) {
612    if deps.is_empty() {
613        return;
614    }
615    for entry in deps {
616        let level = finding_codeclimate(entry, severity);
617        let dep = &entry.dep;
618        let sites: Vec<(String, u32, u32)> = dep
619            .imported_from
620            .iter()
621            .map(|site| (cc_path(&site.path, root), site.line, site.col))
622            .collect();
623        let discriminators = location_discriminators(&sites);
624        for ((path, line, _), discriminator) in sites.iter().zip(&discriminators) {
625            let line_str = line.to_string();
626            let discriminator: Vec<&str> = discriminator.iter().map(String::as_str).collect();
627            let fp = codeclimate_fingerprint_hash(&[
628                "fallow/unlisted-dependency",
629                path,
630                &line_str,
631                &dep.package_name,
632            ]);
633            issues.push(dead_code_issue(
634                entry.finding_id.as_deref(),
635                entry.introduced,
636                &discriminator,
637                CodeClimateIssueInput {
638                    check_name: "fallow/unlisted-dependency",
639                    description: &format!(
640                        "Package '{}' is imported but not listed in package.json",
641                        dep.package_name
642                    ),
643                    severity: level,
644                    category: "Bug Risk",
645                    path,
646                    begin_line: Some(*line),
647                    fingerprint: &fp,
648                },
649            ));
650        }
651    }
652}
653
654fn push_unlisted_binary_issues(
655    issues: &mut Vec<CodeClimateIssue>,
656    binaries: &[fallow_types::output_dead_code::UnlistedBinaryFinding],
657    root: &Path,
658    severity: Severity,
659) {
660    for entry in binaries {
661        let level = finding_codeclimate(entry, severity);
662        let binary = &entry.binary;
663        let sites: Vec<(String, u32, u32)> = binary
664            .used_in
665            .iter()
666            .map(|site| (cc_path(&site.path, root), site.line, site.col))
667            .collect();
668        let discriminators = location_discriminators(&sites);
669        for ((path, line, _), discriminator) in sites.iter().zip(&discriminators) {
670            let line_str = line.to_string();
671            let discriminator: Vec<&str> = discriminator.iter().map(String::as_str).collect();
672            let fp = codeclimate_fingerprint_hash(&[
673                "fallow/unlisted-binary",
674                path,
675                &line_str,
676                &binary.binary_name,
677            ]);
678            issues.push(dead_code_issue(
679                entry.finding_id.as_deref(),
680                entry.introduced,
681                &discriminator,
682                CodeClimateIssueInput {
683                    check_name: "fallow/unlisted-binary",
684                    description: &format!(
685                        "Binary '{}' is used but no installed or listed package provides it",
686                        binary.binary_name
687                    ),
688                    severity: level,
689                    category: "Bug Risk",
690                    path,
691                    begin_line: Some(*line),
692                    fingerprint: &fp,
693                },
694            ));
695        }
696    }
697}
698
699fn push_boundary_coverage_issues(
700    issues: &mut Vec<CodeClimateIssue>,
701    violations: &[fallow_types::output_dead_code::BoundaryCoverageViolationFinding],
702    root: &Path,
703    severity: Severity,
704) {
705    if violations.is_empty() {
706        return;
707    }
708    for entry in violations {
709        let level = finding_codeclimate(entry, severity);
710        let v = &entry.violation;
711        let path = cc_path(&v.path, root);
712        let fp = codeclimate_fingerprint_hash(&["fallow/boundary-coverage", &path]);
713        let line = if v.line > 0 { Some(v.line) } else { None };
714        issues.push(dead_code_issue(
715            entry.finding_id.as_deref(),
716            entry.introduced,
717            &[],
718            CodeClimateIssueInput {
719                check_name: "fallow/boundary-coverage",
720                description: &format!("Boundary coverage: {path} matches no configured zone"),
721                severity: level,
722                category: "Bug Risk",
723                path: &path,
724                begin_line: line,
725                fingerprint: &fp,
726            },
727        ));
728    }
729}
730
731fn push_boundary_call_issues(
732    issues: &mut Vec<CodeClimateIssue>,
733    violations: &[fallow_types::output_dead_code::BoundaryCallViolationFinding],
734    root: &Path,
735    severity: Severity,
736) {
737    if violations.is_empty() {
738        return;
739    }
740    for entry in violations {
741        let level = finding_codeclimate(entry, severity);
742        let v = &entry.violation;
743        let path = cc_path(&v.path, root);
744        let fp =
745            codeclimate_fingerprint_hash(&["fallow/boundary-call-violation", &path, &v.callee]);
746        let line = if v.line > 0 { Some(v.line) } else { None };
747        issues.push(dead_code_issue(
748            entry.finding_id.as_deref(),
749            entry.introduced,
750            &[],
751            CodeClimateIssueInput {
752                check_name: "fallow/boundary-call-violation",
753                description: &format!(
754                    "Boundary call: `{}` matches forbidden pattern `{}` in zone '{}'",
755                    v.callee, v.pattern, v.zone
756                ),
757                severity: level,
758                category: "Bug Risk",
759                path: &path,
760                begin_line: line,
761                fingerprint: &fp,
762            },
763        ));
764    }
765}
766
767fn push_policy_violation_issues(
768    issues: &mut Vec<CodeClimateIssue>,
769    violations: &[fallow_types::output_dead_code::PolicyViolationFinding],
770    root: &Path,
771) {
772    use fallow_types::results::PolicyViolationSeverity;
773
774    for entry in violations {
775        let v = &entry.violation;
776        let path = cc_path(&v.path, root);
777        let rule = format!("{}/{}", v.pack, v.rule_id);
778        let fp =
779            codeclimate_fingerprint_hash(&["fallow/policy-violation", &path, &rule, &v.matched]);
780        let line = if v.line > 0 { Some(v.line) } else { None };
781        // Severity comes from the EFFECTIVE per-finding value, not the
782        // policy-violation master, so a severity: "error" rule under a warn
783        // master maps to blocker-level just like the exit-code gate.
784        let level = severity_to_codeclimate(match v.severity {
785            PolicyViolationSeverity::Error => Severity::Error,
786            PolicyViolationSeverity::Warn => Severity::Warn,
787        });
788        let message = match &v.message {
789            Some(message) => format!(
790                "Policy violation: `{}` is banned by `{rule}`. {message}",
791                v.matched
792            ),
793            None => format!("Policy violation: `{}` is banned by `{rule}`", v.matched),
794        };
795        issues.push(dead_code_issue(
796            entry.finding_id.as_deref(),
797            entry.introduced,
798            &[],
799            CodeClimateIssueInput {
800                check_name: "fallow/policy-violation",
801                description: &message,
802                severity: level,
803                category: "Bug Risk",
804                path: &path,
805                begin_line: line,
806                fingerprint: &fp,
807            },
808        ));
809    }
810}
811
812fn push_invalid_client_export_issues(
813    issues: &mut Vec<CodeClimateIssue>,
814    findings: &[fallow_types::output_dead_code::InvalidClientExportFinding],
815    root: &Path,
816    severity: Severity,
817) {
818    if findings.is_empty() {
819        return;
820    }
821    for entry in findings {
822        let level = finding_codeclimate(entry, severity);
823        let e = &entry.export;
824        let path = cc_path(&e.path, root);
825        let fp =
826            codeclimate_fingerprint_hash(&["fallow/invalid-client-export", &path, &e.export_name]);
827        let line = if e.line > 0 { Some(e.line) } else { None };
828        let message = format!(
829            "Export `{}` is not allowed in a \"{}\" file (Next.js server-only / route-config name)",
830            e.export_name, e.directive
831        );
832        issues.push(dead_code_issue(
833            entry.finding_id.as_deref(),
834            entry.introduced,
835            &[],
836            CodeClimateIssueInput {
837                check_name: "fallow/invalid-client-export",
838                description: &message,
839                severity: level,
840                category: "Bug Risk",
841                path: &path,
842                begin_line: line,
843                fingerprint: &fp,
844            },
845        ));
846    }
847}
848
849fn push_mixed_client_server_barrel_issues(
850    issues: &mut Vec<CodeClimateIssue>,
851    findings: &[fallow_types::output_dead_code::MixedClientServerBarrelFinding],
852    root: &Path,
853    severity: Severity,
854) {
855    if findings.is_empty() {
856        return;
857    }
858    for entry in findings {
859        let level = finding_codeclimate(entry, severity);
860        let b = &entry.barrel;
861        let path = cc_path(&b.path, root);
862        let fp = codeclimate_fingerprint_hash(&[
863            "fallow/mixed-client-server-barrel",
864            &path,
865            &b.client_origin,
866            &b.server_origin,
867        ]);
868        let line = if b.line > 0 { Some(b.line) } else { None };
869        let message = format!(
870            "Barrel re-exports both a \"use client\" module (`{}`) and a server-only module (`{}`); one import drags the other's directive across the boundary",
871            b.client_origin, b.server_origin
872        );
873        issues.push(dead_code_issue(
874            entry.finding_id.as_deref(),
875            entry.introduced,
876            &[],
877            CodeClimateIssueInput {
878                check_name: "fallow/mixed-client-server-barrel",
879                description: &message,
880                severity: level,
881                category: "Bug Risk",
882                path: &path,
883                begin_line: line,
884                fingerprint: &fp,
885            },
886        ));
887    }
888}
889
890fn push_misplaced_directive_issues(
891    issues: &mut Vec<CodeClimateIssue>,
892    findings: &[fallow_types::output_dead_code::MisplacedDirectiveFinding],
893    root: &Path,
894    severity: Severity,
895) {
896    if findings.is_empty() {
897        return;
898    }
899    for entry in findings {
900        let level = finding_codeclimate(entry, severity);
901        let d = &entry.directive_site;
902        let path = cc_path(&d.path, root);
903        let fp = codeclimate_fingerprint_hash(&[
904            "fallow/misplaced-directive",
905            &path,
906            &d.line.to_string(),
907            &d.directive,
908        ]);
909        let line = if d.line > 0 { Some(d.line) } else { None };
910        let message = format!(
911            "Directive `\"{}\"` is not in the leading position, so the RSC bundler ignores it; move it to the top of the file",
912            d.directive
913        );
914        issues.push(dead_code_issue(
915            entry.finding_id.as_deref(),
916            entry.introduced,
917            &[],
918            CodeClimateIssueInput {
919                check_name: "fallow/misplaced-directive",
920                description: &message,
921                severity: level,
922                category: "Bug Risk",
923                path: &path,
924                begin_line: line,
925                fingerprint: &fp,
926            },
927        ));
928    }
929}
930
931fn push_unprovided_inject_issues(
932    issues: &mut Vec<CodeClimateIssue>,
933    findings: &[fallow_types::output_dead_code::UnprovidedInjectFinding],
934    root: &Path,
935    severity: Severity,
936) {
937    if findings.is_empty() {
938        return;
939    }
940    for entry in findings {
941        let level = finding_codeclimate(entry, severity);
942        let i = &entry.inject;
943        let path = cc_path(&i.path, root);
944        let fp = codeclimate_fingerprint_hash(&[
945            "fallow/unprovided-inject",
946            &path,
947            &i.line.to_string(),
948            &i.key_name,
949        ]);
950        let line = if i.line > 0 { Some(i.line) } else { None };
951        let message = format!(
952            "inject(`{}`) has no matching provide(`{}`) in this project; at runtime it returns undefined (provide the key or remove this inject)",
953            i.key_name, i.key_name
954        );
955        issues.push(dead_code_issue(
956            entry.finding_id.as_deref(),
957            entry.introduced,
958            &[],
959            CodeClimateIssueInput {
960                check_name: "fallow/unprovided-inject",
961                description: &message,
962                severity: level,
963                category: "Bug Risk",
964                path: &path,
965                begin_line: line,
966                fingerprint: &fp,
967            },
968        ));
969    }
970}
971
972fn push_unrendered_component_issues(
973    issues: &mut Vec<CodeClimateIssue>,
974    findings: &[fallow_types::output_dead_code::UnrenderedComponentFinding],
975    root: &Path,
976    severity: Severity,
977) {
978    if findings.is_empty() {
979        return;
980    }
981    for entry in findings {
982        let level = finding_codeclimate(entry, severity);
983        let c = &entry.component;
984        let path = cc_path(&c.path, root);
985        let fp = codeclimate_fingerprint_hash(&[
986            "fallow/unrendered-component",
987            &path,
988            &c.line.to_string(),
989            &c.component_name,
990        ]);
991        let line = if c.line > 0 { Some(c.line) } else { None };
992        let message = format!(
993            "component `{}` is reachable but rendered nowhere in this project (render it somewhere or remove it)",
994            c.component_name
995        );
996        issues.push(dead_code_issue(
997            entry.finding_id.as_deref(),
998            entry.introduced,
999            &[],
1000            CodeClimateIssueInput {
1001                check_name: "fallow/unrendered-component",
1002                description: &message,
1003                severity: level,
1004                category: "Bug Risk",
1005                path: &path,
1006                begin_line: line,
1007                fingerprint: &fp,
1008            },
1009        ));
1010    }
1011}
1012
1013fn push_unused_component_prop_issues(
1014    issues: &mut Vec<CodeClimateIssue>,
1015    findings: &[fallow_types::output_dead_code::UnusedComponentPropFinding],
1016    root: &Path,
1017    severity: Severity,
1018) {
1019    if findings.is_empty() {
1020        return;
1021    }
1022    for entry in findings {
1023        let level = finding_codeclimate(entry, severity);
1024        let p = &entry.prop;
1025        let path = cc_path(&p.path, root);
1026        let fp = codeclimate_fingerprint_hash(&[
1027            "fallow/unused-component-prop",
1028            &path,
1029            &p.line.to_string(),
1030            &p.prop_name,
1031        ]);
1032        let line = if p.line > 0 { Some(p.line) } else { None };
1033        let message = format!(
1034            "prop `{}` is declared but referenced nowhere in component `{}` (remove it or use it)",
1035            p.prop_name, p.component_name
1036        );
1037        issues.push(dead_code_issue(
1038            entry.finding_id.as_deref(),
1039            entry.introduced,
1040            &[],
1041            CodeClimateIssueInput {
1042                check_name: "fallow/unused-component-prop",
1043                description: &message,
1044                severity: level,
1045                category: "Bug Risk",
1046                path: &path,
1047                begin_line: line,
1048                fingerprint: &fp,
1049            },
1050        ));
1051    }
1052}
1053
1054fn push_unused_component_emit_issues(
1055    issues: &mut Vec<CodeClimateIssue>,
1056    findings: &[fallow_types::output_dead_code::UnusedComponentEmitFinding],
1057    root: &Path,
1058    severity: Severity,
1059) {
1060    if findings.is_empty() {
1061        return;
1062    }
1063    for entry in findings {
1064        let level = finding_codeclimate(entry, severity);
1065        let e = &entry.emit;
1066        let path = cc_path(&e.path, root);
1067        let fp = codeclimate_fingerprint_hash(&[
1068            "fallow/unused-component-emit",
1069            &path,
1070            &e.line.to_string(),
1071            &e.emit_name,
1072        ]);
1073        let line = if e.line > 0 { Some(e.line) } else { None };
1074        let message = format!(
1075            "emit `{}` is declared but emitted nowhere in component `{}` (remove it or emit it)",
1076            e.emit_name, e.component_name
1077        );
1078        issues.push(dead_code_issue(
1079            entry.finding_id.as_deref(),
1080            entry.introduced,
1081            &[],
1082            CodeClimateIssueInput {
1083                check_name: "fallow/unused-component-emit",
1084                description: &message,
1085                severity: level,
1086                category: "Bug Risk",
1087                path: &path,
1088                begin_line: line,
1089                fingerprint: &fp,
1090            },
1091        ));
1092    }
1093}
1094
1095fn push_unused_effect_layer_issues(
1096    issues: &mut Vec<CodeClimateIssue>,
1097    findings: &[fallow_types::output_dead_code::UnusedEffectLayerFinding],
1098    root: &Path,
1099    severity: Severity,
1100) {
1101    for entry in findings {
1102        let level = finding_codeclimate(entry, severity);
1103        let f = &entry.layer;
1104        let path = cc_path(&f.path, root);
1105        let fp = codeclimate_fingerprint_hash(&[
1106            "fallow/unused-effect-layer",
1107            &path,
1108            &f.line.to_string(),
1109            &f.name,
1110        ]);
1111        let line = if f.line > 0 { Some(f.line) } else { None };
1112        let message = format!(
1113            "layer `{}` is composed only into layers that nothing uses ({}); compose it into a live layer or remove it",
1114            f.name,
1115            f.dead_consumers.join(", ")
1116        );
1117        issues.push(dead_code_issue(
1118            entry.finding_id.as_deref(),
1119            entry.introduced,
1120            &[],
1121            CodeClimateIssueInput {
1122                check_name: "fallow/unused-effect-layer",
1123                description: &message,
1124                severity: level,
1125                category: "Bug Risk",
1126                path: &path,
1127                begin_line: line,
1128                fingerprint: &fp,
1129            },
1130        ));
1131    }
1132}
1133
1134fn push_duplicate_export_alias_issues(
1135    issues: &mut Vec<CodeClimateIssue>,
1136    findings: &[fallow_types::output_dead_code::DuplicateExportAliasFinding],
1137    root: &Path,
1138    severity: Severity,
1139) {
1140    for entry in findings {
1141        let level = finding_codeclimate(entry, severity);
1142        let f = &entry.alias;
1143        let path = cc_path(&f.path, root);
1144        let names = f.export_names.join(",");
1145        let fp = codeclimate_fingerprint_hash(&[
1146            "fallow/duplicate-export-alias",
1147            &path,
1148            &f.local_name,
1149            &names,
1150        ]);
1151        let line = if f.line > 0 { Some(f.line) } else { None };
1152        let message = format!(
1153            "`{}` is exported under {} names ({}); keep one name or add the names to ignoreExports",
1154            f.local_name,
1155            f.export_names.len(),
1156            f.export_names.join(", ")
1157        );
1158        issues.push(dead_code_issue(
1159            entry.finding_id.as_deref(),
1160            entry.introduced,
1161            &[],
1162            CodeClimateIssueInput {
1163                check_name: "fallow/duplicate-export-alias",
1164                description: &message,
1165                severity: level,
1166                category: "Duplication",
1167                path: &path,
1168                begin_line: line,
1169                fingerprint: &fp,
1170            },
1171        ));
1172    }
1173}
1174
1175fn push_unused_tagged_error_issues(
1176    issues: &mut Vec<CodeClimateIssue>,
1177    findings: &[fallow_types::output_dead_code::UnusedTaggedErrorFinding],
1178    root: &Path,
1179    severity: Severity,
1180) {
1181    for entry in findings {
1182        let level = finding_codeclimate(entry, severity);
1183        let f = &entry.error;
1184        let path = cc_path(&f.path, root);
1185        let fp = codeclimate_fingerprint_hash(&[
1186            "fallow/unused-tagged-error",
1187            &path,
1188            &f.line.to_string(),
1189            &f.name,
1190        ]);
1191        let line = if f.line > 0 { Some(f.line) } else { None };
1192        let message = format!(
1193            "tagged error `{}` (tag `{}`) is never constructed or failed with; fail with it or remove it",
1194            f.name, f.tag
1195        );
1196        issues.push(dead_code_issue(
1197            entry.finding_id.as_deref(),
1198            entry.introduced,
1199            &[],
1200            CodeClimateIssueInput {
1201                check_name: "fallow/unused-tagged-error",
1202                description: &message,
1203                severity: level,
1204                category: "Bug Risk",
1205                path: &path,
1206                begin_line: line,
1207                fingerprint: &fp,
1208            },
1209        ));
1210    }
1211}
1212
1213fn push_unproduced_catch_tag_issues(
1214    issues: &mut Vec<CodeClimateIssue>,
1215    findings: &[fallow_types::output_dead_code::UnproducedCatchTagFinding],
1216    root: &Path,
1217    severity: Severity,
1218) {
1219    for entry in findings {
1220        let level = finding_codeclimate(entry, severity);
1221        let f = &entry.catch_tag;
1222        let path = cc_path(&f.path, root);
1223        let fp = codeclimate_fingerprint_hash(&[
1224            "fallow/unproduced-catch-tag",
1225            &path,
1226            &f.line.to_string(),
1227            &f.tag,
1228        ]);
1229        let line = if f.line > 0 { Some(f.line) } else { None };
1230        let message = format!(
1231            "catchTag handler for `{}` never runs: no code produces {}",
1232            f.tag,
1233            f.candidate_classes.join(", ")
1234        );
1235        issues.push(dead_code_issue(
1236            entry.finding_id.as_deref(),
1237            entry.introduced,
1238            &[],
1239            CodeClimateIssueInput {
1240                check_name: "fallow/unproduced-catch-tag",
1241                description: &message,
1242                severity: level,
1243                category: "Bug Risk",
1244                path: &path,
1245                begin_line: line,
1246                fingerprint: &fp,
1247            },
1248        ));
1249    }
1250}
1251
1252fn push_unused_server_action_issues(
1253    issues: &mut Vec<CodeClimateIssue>,
1254    findings: &[fallow_types::output_dead_code::UnusedServerActionFinding],
1255    root: &Path,
1256    severity: Severity,
1257) {
1258    if findings.is_empty() {
1259        return;
1260    }
1261    for entry in findings {
1262        let level = finding_codeclimate(entry, severity);
1263        let a = &entry.action;
1264        let path = cc_path(&a.path, root);
1265        let fp = codeclimate_fingerprint_hash(&[
1266            "fallow/unused-server-action",
1267            &path,
1268            &a.line.to_string(),
1269            &a.action_name,
1270        ]);
1271        let line = if a.line > 0 { Some(a.line) } else { None };
1272        let message = format!(
1273            "server action `{}` is exported from a \"use server\" file but no code in this project references it (wire it to a consumer or remove it)",
1274            a.action_name
1275        );
1276        issues.push(dead_code_issue(
1277            entry.finding_id.as_deref(),
1278            entry.introduced,
1279            &[],
1280            CodeClimateIssueInput {
1281                check_name: "fallow/unused-server-action",
1282                description: &message,
1283                severity: level,
1284                category: "Bug Risk",
1285                path: &path,
1286                begin_line: line,
1287                fingerprint: &fp,
1288            },
1289        ));
1290    }
1291}
1292
1293fn push_unused_load_data_key_issues(
1294    issues: &mut Vec<CodeClimateIssue>,
1295    findings: &[fallow_types::output_dead_code::UnusedLoadDataKeyFinding],
1296    root: &Path,
1297    severity: Severity,
1298) {
1299    if findings.is_empty() {
1300        return;
1301    }
1302    for entry in findings {
1303        let level = finding_codeclimate(entry, severity);
1304        let k = &entry.key;
1305        let path = cc_path(&k.path, root);
1306        let fp = codeclimate_fingerprint_hash(&[
1307            "fallow/unused-load-data-key",
1308            &path,
1309            &k.line.to_string(),
1310            &k.key_name,
1311        ]);
1312        let line = if k.line > 0 { Some(k.line) } else { None };
1313        let message = format!(
1314            "load() return key `{}` is read by no consumer (sibling +page.svelte data.<key> or project-wide page.data.<key>); delete the key or wire a consumer",
1315            k.key_name
1316        );
1317        issues.push(dead_code_issue(
1318            entry.finding_id.as_deref(),
1319            entry.introduced,
1320            &[],
1321            CodeClimateIssueInput {
1322                check_name: "fallow/unused-load-data-key",
1323                description: &message,
1324                severity: level,
1325                category: "Bug Risk",
1326                path: &path,
1327                begin_line: line,
1328                fingerprint: &fp,
1329            },
1330        ));
1331    }
1332}
1333
1334fn push_route_collision_issues(
1335    issues: &mut Vec<CodeClimateIssue>,
1336    findings: &[fallow_types::output_dead_code::RouteCollisionFinding],
1337    root: &Path,
1338    severity: Severity,
1339) {
1340    if findings.is_empty() {
1341        return;
1342    }
1343    for entry in findings {
1344        let level = finding_codeclimate(entry, severity);
1345        let c = &entry.collision;
1346        let path = cc_path(&c.path, root);
1347        let fp = codeclimate_fingerprint_hash(&["fallow/route-collision", &path, &c.url]);
1348        let line = if c.line > 0 { Some(c.line) } else { None };
1349        let message = format!(
1350            "Route file resolves to `{}`, also owned by {} other file(s); Next.js fails the build because a URL can have only one owner",
1351            c.url,
1352            c.conflicting_paths.len()
1353        );
1354        issues.push(dead_code_issue(
1355            entry.finding_id.as_deref(),
1356            entry.introduced,
1357            &[],
1358            CodeClimateIssueInput {
1359                check_name: "fallow/route-collision",
1360                description: &message,
1361                severity: level,
1362                category: "Bug Risk",
1363                path: &path,
1364                begin_line: line,
1365                fingerprint: &fp,
1366            },
1367        ));
1368    }
1369}
1370
1371fn push_dynamic_segment_name_conflict_issues(
1372    issues: &mut Vec<CodeClimateIssue>,
1373    findings: &[fallow_types::output_dead_code::DynamicSegmentNameConflictFinding],
1374    root: &Path,
1375    severity: Severity,
1376) {
1377    if findings.is_empty() {
1378        return;
1379    }
1380    for entry in findings {
1381        let level = finding_codeclimate(entry, severity);
1382        let c = &entry.conflict;
1383        let path = cc_path(&c.path, root);
1384        let fp = codeclimate_fingerprint_hash(&[
1385            "fallow/dynamic-segment-name-conflict",
1386            &path,
1387            &c.position,
1388        ]);
1389        let line = if c.line > 0 { Some(c.line) } else { None };
1390        let message = format!(
1391            "Dynamic segments at `{}` use different slug names ({}); Next.js requires one consistent name per dynamic path",
1392            c.position,
1393            c.conflicting_segments.join(", ")
1394        );
1395        issues.push(dead_code_issue(
1396            entry.finding_id.as_deref(),
1397            entry.introduced,
1398            &[],
1399            CodeClimateIssueInput {
1400                check_name: "fallow/dynamic-segment-name-conflict",
1401                description: &message,
1402                severity: level,
1403                category: "Bug Risk",
1404                path: &path,
1405                begin_line: line,
1406                fingerprint: &fp,
1407            },
1408        ));
1409    }
1410}
1411
1412fn push_stale_suppression_issues(
1413    issues: &mut Vec<CodeClimateIssue>,
1414    suppressions: &[fallow_types::results::StaleSuppression],
1415    root: &Path,
1416    rules: &RulesConfig,
1417) {
1418    if suppressions.is_empty() {
1419        return;
1420    }
1421    for s in suppressions {
1422        let severity = if s.missing_reason {
1423            rules.require_suppression_reason
1424        } else {
1425            rules.stale_suppressions
1426        };
1427        let level = finding_codeclimate(s, severity);
1428        let path = cc_path(&s.path, root);
1429        let line_str = s.line.to_string();
1430        let check_name = if s.missing_reason {
1431            "fallow/missing-suppression-reason"
1432        } else {
1433            "fallow/stale-suppression"
1434        };
1435        let fp = codeclimate_fingerprint_hash(&[check_name, &path, &line_str]);
1436        issues.push(dead_code_issue(
1437            s.finding_id.as_deref(),
1438            // The audit sets this flag with `set_stale_suppression_audit_attribution`.
1439            None,
1440            &[],
1441            CodeClimateIssueInput {
1442                check_name,
1443                description: &s.display_message(),
1444                severity: level,
1445                category: "Bug Risk",
1446                path: &path,
1447                begin_line: Some(s.line),
1448                fingerprint: &fp,
1449            },
1450        ));
1451    }
1452}
1453
1454/// Build CodeClimate issues from dead-code analysis results.
1455///
1456/// Returns the typed [`CodeClimateIssue`] vec; callers that emit the wire
1457/// shape convert via [`fallow_output::codeclimate_issues_to_value`]. The schema
1458/// drift gate locks the per-issue shape against
1459/// [`fallow_output::CodeClimateOutput`].
1460#[must_use]
1461pub fn build_codeclimate(
1462    results: &AnalysisResults,
1463    root: &Path,
1464    rules: &RulesConfig,
1465) -> Vec<CodeClimateIssue> {
1466    CodeClimateBuilder {
1467        issues: Vec::new(),
1468        results,
1469        root,
1470        rules,
1471    }
1472    .build()
1473}
1474
1475struct CodeClimateBuilder<'a> {
1476    issues: Vec<CodeClimateIssue>,
1477    results: &'a AnalysisResults,
1478    root: &'a Path,
1479    rules: &'a RulesConfig,
1480}
1481
1482impl CodeClimateBuilder<'_> {
1483    fn build(mut self) -> Vec<CodeClimateIssue> {
1484        self.push_file_and_export_issues();
1485        self.push_private_type_leak_issues();
1486        push_deprecated_export_issues(
1487            &mut self.issues,
1488            &self.results.deprecated_exports_in_use,
1489            self.root,
1490            self.rules.deprecated_exports_in_use,
1491        );
1492        self.push_package_dependency_issues();
1493        self.push_type_test_dependency_issues();
1494        self.push_member_issues();
1495        self.push_import_and_duplicate_issues();
1496        self.push_graph_issues();
1497        self.push_boundary_issues();
1498        self.push_suppression_and_catalog_issues();
1499        self.push_override_issues();
1500        self.push_prop_drilling_issues();
1501        self.push_component_shape_issues();
1502        self.issues
1503    }
1504
1505    fn push_file_and_export_issues(&mut self) {
1506        push_unused_file_issues(
1507            &mut self.issues,
1508            &self.results.unused_files,
1509            self.root,
1510            self.rules.unused_files,
1511        );
1512        push_unused_export_issues(UnusedExportIssuesInput {
1513            issues: &mut self.issues,
1514            exports: self.results.unused_exports.iter().map(|e| {
1515                (
1516                    &e.export,
1517                    e.reachability_caveats.as_slice(),
1518                    e.effective_severity,
1519                    e.finding_id.as_deref(),
1520                    e.introduced,
1521                )
1522            }),
1523            root: self.root,
1524            rule_id: "fallow/unused-export",
1525            direct_label: "Export",
1526            re_export_label: "Re-export",
1527            severity: self.rules.unused_exports,
1528        });
1529        push_unused_export_issues(UnusedExportIssuesInput {
1530            issues: &mut self.issues,
1531            exports: self.results.unused_types.iter().map(|e| {
1532                (
1533                    &e.export,
1534                    e.reachability_caveats.as_slice(),
1535                    e.effective_severity,
1536                    e.finding_id.as_deref(),
1537                    e.introduced,
1538                )
1539            }),
1540            root: self.root,
1541            rule_id: "fallow/unused-type",
1542            direct_label: "Type export",
1543            re_export_label: "Type re-export",
1544            severity: self.rules.unused_types,
1545        });
1546    }
1547
1548    fn push_private_type_leak_issues(&mut self) {
1549        push_private_type_leak_issues(
1550            &mut self.issues,
1551            &self.results.private_type_leaks,
1552            self.root,
1553            self.rules.private_type_leaks,
1554        );
1555    }
1556
1557    fn push_package_dependency_issues(&mut self) {
1558        push_dep_cc_issues(
1559            &mut self.issues,
1560            self.results.unused_dependencies.iter().map(|f| {
1561                (
1562                    &f.dep,
1563                    f.reachability_caveats.as_slice(),
1564                    f.effective_severity,
1565                    f.finding_id.as_deref(),
1566                    f.introduced,
1567                )
1568            }),
1569            self.root,
1570            "fallow/unused-dependency",
1571            "dependencies",
1572            self.rules.unused_dependencies,
1573        );
1574        push_dep_cc_issues(
1575            &mut self.issues,
1576            self.results.unused_dev_dependencies.iter().map(|f| {
1577                (
1578                    &f.dep,
1579                    f.reachability_caveats.as_slice(),
1580                    f.effective_severity,
1581                    f.finding_id.as_deref(),
1582                    f.introduced,
1583                )
1584            }),
1585            self.root,
1586            "fallow/unused-dev-dependency",
1587            "devDependencies",
1588            self.rules.unused_dev_dependencies,
1589        );
1590        push_dep_cc_issues(
1591            &mut self.issues,
1592            self.results.unused_optional_dependencies.iter().map(|f| {
1593                (
1594                    &f.dep,
1595                    f.reachability_caveats.as_slice(),
1596                    f.effective_severity,
1597                    f.finding_id.as_deref(),
1598                    f.introduced,
1599                )
1600            }),
1601            self.root,
1602            "fallow/unused-optional-dependency",
1603            "optionalDependencies",
1604            self.rules.unused_optional_dependencies,
1605        );
1606    }
1607
1608    fn push_type_test_dependency_issues(&mut self) {
1609        push_type_only_dep_issues(
1610            &mut self.issues,
1611            &self.results.type_only_dependencies,
1612            self.root,
1613            self.rules.type_only_dependencies,
1614        );
1615        push_test_only_dep_issues(
1616            &mut self.issues,
1617            &self.results.test_only_dependencies,
1618            self.root,
1619            self.rules.test_only_dependencies,
1620        );
1621        push_dev_dep_in_prod_issues(
1622            &mut self.issues,
1623            &self.results.dev_dependencies_in_production,
1624            self.root,
1625            self.rules.dev_dependencies_in_production,
1626        );
1627    }
1628
1629    fn push_member_issues(&mut self) {
1630        push_unused_member_issues(
1631            &mut self.issues,
1632            self.results.unused_enum_members.iter().map(|m| {
1633                (
1634                    &m.member,
1635                    m.reachability_caveats.as_slice(),
1636                    m.effective_severity,
1637                    m.finding_id.as_deref(),
1638                    m.introduced,
1639                )
1640            }),
1641            self.root,
1642            "fallow/unused-enum-member",
1643            "Enum",
1644            self.rules.unused_enum_members,
1645        );
1646        push_unused_member_issues(
1647            &mut self.issues,
1648            self.results.unused_class_members.iter().map(|m| {
1649                (
1650                    &m.member,
1651                    m.reachability_caveats.as_slice(),
1652                    m.effective_severity,
1653                    m.finding_id.as_deref(),
1654                    m.introduced,
1655                )
1656            }),
1657            self.root,
1658            "fallow/unused-class-member",
1659            "Class",
1660            self.rules.unused_class_members,
1661        );
1662        push_unused_member_issues(
1663            &mut self.issues,
1664            self.results.unused_store_members.iter().map(|m| {
1665                (
1666                    &m.member,
1667                    m.reachability_caveats.as_slice(),
1668                    m.effective_severity,
1669                    m.finding_id.as_deref(),
1670                    m.introduced,
1671                )
1672            }),
1673            self.root,
1674            "fallow/unused-store-member",
1675            "Store",
1676            self.rules.unused_store_members,
1677        );
1678        push_unused_member_issues(
1679            &mut self.issues,
1680            self.results.unused_namespace_members.iter().map(|m| {
1681                (
1682                    &m.member,
1683                    m.reachability_caveats.as_slice(),
1684                    m.effective_severity,
1685                    m.finding_id.as_deref(),
1686                    m.introduced,
1687                )
1688            }),
1689            self.root,
1690            "fallow/unused-namespace-member",
1691            "Namespace",
1692            self.rules.unused_namespace_members,
1693        );
1694        push_unused_member_issues(
1695            &mut self.issues,
1696            self.results.unused_protected_class_members.iter().map(|m| {
1697                (
1698                    &m.member,
1699                    m.reachability_caveats.as_slice(),
1700                    m.effective_severity,
1701                    m.finding_id.as_deref(),
1702                    m.introduced,
1703                )
1704            }),
1705            self.root,
1706            "fallow/unused-protected-class-member",
1707            "Protected class",
1708            self.rules.unused_protected_class_members,
1709        );
1710        namespace_escape::push_namespace_escape_issues(
1711            &mut self.issues,
1712            &self.results.namespace_escapes,
1713            self.root,
1714            self.rules.namespace_escapes,
1715        );
1716    }
1717
1718    fn push_import_and_duplicate_issues(&mut self) {
1719        push_unresolved_import_issues(
1720            &mut self.issues,
1721            &self.results.unresolved_imports,
1722            self.root,
1723            self.rules.unresolved_imports,
1724        );
1725        push_unlisted_dep_issues(
1726            &mut self.issues,
1727            &self.results.unlisted_dependencies,
1728            self.root,
1729            self.rules.unlisted_dependencies,
1730        );
1731        push_unlisted_binary_issues(
1732            &mut self.issues,
1733            &self.results.unlisted_binaries,
1734            self.root,
1735            self.rules.unlisted_binaries,
1736        );
1737        push_duplicate_export_issues(
1738            &mut self.issues,
1739            &self.results.duplicate_exports,
1740            self.root,
1741            self.rules.duplicate_exports,
1742        );
1743    }
1744
1745    fn push_graph_issues(&mut self) {
1746        push_circular_dep_issues(
1747            &mut self.issues,
1748            &self.results.circular_dependencies,
1749            self.root,
1750            self.rules.circular_dependencies,
1751        );
1752        push_re_export_cycle_issues(
1753            &mut self.issues,
1754            &self.results.re_export_cycles,
1755            self.root,
1756            self.rules.re_export_cycle,
1757        );
1758        push_package_cycle_issues(
1759            &mut self.issues,
1760            &self.results.package_cycles,
1761            self.root,
1762            self.rules.package_cycle,
1763        );
1764    }
1765
1766    fn push_boundary_issues(&mut self) {
1767        self.push_architecture_boundary_issues();
1768        self.push_client_server_boundary_issues();
1769        self.push_component_boundary_issues();
1770        self.push_framework_route_issues();
1771    }
1772
1773    fn push_architecture_boundary_issues(&mut self) {
1774        push_boundary_violation_issues(
1775            &mut self.issues,
1776            &self.results.boundary_violations,
1777            self.root,
1778            self.rules.boundary_violation,
1779        );
1780        push_boundary_coverage_issues(
1781            &mut self.issues,
1782            &self.results.boundary_coverage_violations,
1783            self.root,
1784            self.rules.boundary_violation,
1785        );
1786        push_boundary_call_issues(
1787            &mut self.issues,
1788            &self.results.boundary_call_violations,
1789            self.root,
1790            self.rules.boundary_violation,
1791        );
1792        push_policy_violation_issues(&mut self.issues, &self.results.policy_violations, self.root);
1793    }
1794
1795    fn push_client_server_boundary_issues(&mut self) {
1796        push_invalid_client_export_issues(
1797            &mut self.issues,
1798            &self.results.invalid_client_exports,
1799            self.root,
1800            self.rules.invalid_client_export,
1801        );
1802        push_mixed_client_server_barrel_issues(
1803            &mut self.issues,
1804            &self.results.mixed_client_server_barrels,
1805            self.root,
1806            self.rules.mixed_client_server_barrel,
1807        );
1808        push_misplaced_directive_issues(
1809            &mut self.issues,
1810            &self.results.misplaced_directives,
1811            self.root,
1812            self.rules.misplaced_directive,
1813        );
1814    }
1815
1816    fn push_component_boundary_issues(&mut self) {
1817        push_unprovided_inject_issues(
1818            &mut self.issues,
1819            &self.results.unprovided_injects,
1820            self.root,
1821            self.rules.unprovided_injects,
1822        );
1823        push_unrendered_component_issues(
1824            &mut self.issues,
1825            &self.results.unrendered_components,
1826            self.root,
1827            self.rules.unrendered_components,
1828        );
1829        push_absent_component_prop_issues(
1830            &mut self.issues,
1831            &self.results.absent_component_props,
1832            self.root,
1833            self.rules.absent_component_props,
1834        );
1835        push_constant_parameter_issues(
1836            &mut self.issues,
1837            &self.results.constant_parameters,
1838            self.root,
1839            self.rules.constant_parameters,
1840        );
1841        push_unused_component_prop_issues(
1842            &mut self.issues,
1843            &self.results.unused_component_props,
1844            self.root,
1845            self.rules.unused_component_props,
1846        );
1847        push_unused_component_emit_issues(
1848            &mut self.issues,
1849            &self.results.unused_component_emits,
1850            self.root,
1851            self.rules.unused_component_emits,
1852        );
1853        push_unused_component_input_issues(
1854            &mut self.issues,
1855            &self.results.unused_component_inputs,
1856            self.root,
1857            self.rules.unused_component_inputs,
1858        );
1859        push_unused_component_output_issues(
1860            &mut self.issues,
1861            &self.results.unused_component_outputs,
1862            self.root,
1863            self.rules.unused_component_outputs,
1864        );
1865        push_unused_svelte_event_issues(
1866            &mut self.issues,
1867            &self.results.unused_svelte_events,
1868            self.root,
1869            self.rules.unused_svelte_events,
1870        );
1871        push_unused_effect_layer_issues(
1872            &mut self.issues,
1873            &self.results.unused_effect_layers,
1874            self.root,
1875            self.rules.unused_effect_layers,
1876        );
1877        push_duplicate_export_alias_issues(
1878            &mut self.issues,
1879            &self.results.duplicate_export_aliases,
1880            self.root,
1881            self.rules.duplicate_export_aliases,
1882        );
1883        push_unused_tagged_error_issues(
1884            &mut self.issues,
1885            &self.results.unused_tagged_errors,
1886            self.root,
1887            self.rules.unused_tagged_errors,
1888        );
1889        push_unproduced_catch_tag_issues(
1890            &mut self.issues,
1891            &self.results.unproduced_catch_tags,
1892            self.root,
1893            self.rules.unproduced_catch_tags,
1894        );
1895    }
1896
1897    fn push_framework_route_issues(&mut self) {
1898        push_unused_server_action_issues(
1899            &mut self.issues,
1900            &self.results.unused_server_actions,
1901            self.root,
1902            self.rules.unused_server_actions,
1903        );
1904        push_unused_load_data_key_issues(
1905            &mut self.issues,
1906            &self.results.unused_load_data_keys,
1907            self.root,
1908            self.rules.unused_load_data_keys,
1909        );
1910        push_route_collision_issues(
1911            &mut self.issues,
1912            &self.results.route_collisions,
1913            self.root,
1914            self.rules.route_collision,
1915        );
1916        push_dynamic_segment_name_conflict_issues(
1917            &mut self.issues,
1918            &self.results.dynamic_segment_name_conflicts,
1919            self.root,
1920            self.rules.dynamic_segment_name_conflict,
1921        );
1922    }
1923
1924    fn push_suppression_and_catalog_issues(&mut self) {
1925        push_stale_suppression_issues(
1926            &mut self.issues,
1927            &self.results.stale_suppressions,
1928            self.root,
1929            self.rules,
1930        );
1931        push_unused_catalog_entry_issues(
1932            &mut self.issues,
1933            &self.results.unused_catalog_entries,
1934            self.root,
1935            self.rules.unused_catalog_entries,
1936        );
1937        push_empty_catalog_group_issues(
1938            &mut self.issues,
1939            &self.results.empty_catalog_groups,
1940            self.root,
1941            self.rules.empty_catalog_groups,
1942        );
1943        push_unresolved_catalog_reference_issues(
1944            &mut self.issues,
1945            &self.results.unresolved_catalog_references,
1946            self.root,
1947            self.rules.unresolved_catalog_references,
1948        );
1949    }
1950
1951    fn push_override_issues(&mut self) {
1952        push_unused_dependency_override_issues(
1953            &mut self.issues,
1954            &self.results.unused_dependency_overrides,
1955            self.root,
1956            self.rules.unused_dependency_overrides,
1957        );
1958        push_misconfigured_dependency_override_issues(
1959            &mut self.issues,
1960            &self.results.misconfigured_dependency_overrides,
1961            self.root,
1962            self.rules.misconfigured_dependency_overrides,
1963        );
1964    }
1965}
1966
1967#[path = "dead_code_codeclimate_duplicates.rs"]
1968mod dead_code_codeclimate_duplicates;
1969use dead_code_codeclimate_duplicates::push_duplicate_export_issues;
1970
1971#[path = "dead_code_codeclimate_boundary.rs"]
1972mod boundary_render;
1973use boundary_render::push_boundary_violation_issues;
1974
1975#[path = "dead_code_codeclimate_cycles.rs"]
1976mod cycles;
1977use cycles::{push_circular_dep_issues, push_package_cycle_issues, push_re_export_cycle_issues};
1978
1979#[cfg(test)]
1980#[path = "dead_code_codeclimate_tests.rs"]
1981mod tests;