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