fallow_types/output_dead_code.rs
1//! Typed envelope wrappers for the simple 1:1 dead-code findings whose
2//! actions are entirely determined by the wrapper type (no per-instance
3//! discriminants beyond what the bare finding already exposes).
4//!
5//! Each wrapper flattens the bare finding via `#[serde(flatten)]` so the
6//! wire shape matches the previous `actions`-grafted output byte-for-byte.
7//! `actions` is populated at construction time via each wrapper's
8//! `with_actions` constructor and replaces the per-finding `inject_actions`
9//! post-pass in `crates/cli/src/report/json.rs`. `introduced` carries the optional audit
10//! breadcrumb that `crates/cli/src/audit.rs::annotate_issue_array` inserts
11//! into the JSON object via `map.insert`; the wrapper-level field stays
12//! `None` when serialized directly from Rust and is set by the audit pass
13//! only when the issue was introduced relative to the merge-base.
14//!
15//! All nine wrappers ship with `IssueAction` arrays today; they pay the
16//! `serde_json` dependency cost because `IssueAction` transitively
17//! references `AddToConfigValue::RuleObject(serde_json::Map<...>)`. The
18//! variants the wrappers actually emit (`Fix`, `SuppressLine`,
19//! `SuppressFile`, `AddToConfig`) are small, but reusing the existing enum
20//! keeps the wire-shape contract identical to the legacy post-pass.
21//!
22//! `introduced` is typed as `Option<AuditIntroduced>` (transparent newtype
23//! over `bool`) so the regenerated schema renders the field via
24//! `$ref: #/definitions/AuditIntroduced`, matching the reference the prior
25//! post-pass augmentation graft used. The audit pass continues to inject a
26//! bare bool via `map.insert("introduced", ...)`; serde reads it back into
27//! `AuditIntroduced` transparently. The field stays absent at the wire when
28//! `None` (`skip_serializing_if`).
29
30use serde::{Deserialize, Serialize};
31
32use crate::catalog_source::is_pnpm_catalog_source;
33use crate::envelope::AuditIntroduced;
34use crate::output::{
35 AddToConfigAction, AddToConfigKind, AddToConfigValue, FixAction, FixActionType,
36 IgnoreExportsRule, IssueAction, SuppressFileAction, SuppressFileKind, SuppressLineAction,
37 SuppressLineKind, SuppressLineScope,
38};
39pub use crate::results::AbsentComponentPropFinding;
40use crate::results::{
41 BoundaryCallViolation, BoundaryCoverageViolation, BoundaryViolation, CircularDependency,
42 DependencyOverrideSource, DeprecatedExportInUse, DevDependencyInProduction, DuplicateExport,
43 DuplicateExportAlias, DuplicatePropShape, DynamicSegmentNameConflict, EmptyCatalogGroup,
44 InvalidClientExport, MisconfiguredDependencyOverride, MisplacedDirective,
45 MixedClientServerBarrel, PackageCycle, PolicyViolation, PrivateTypeLeak, PropDrillingChain,
46 ReExportCycle, ReExportCycleKind, RouteCollision, TestOnlyDependency, ThinWrapper,
47 TypeOnlyDependency, UnlistedBinary, UnlistedDependency, UnproducedCatchTag, UnprovidedInject,
48 UnrenderedComponent, UnresolvedCatalogReference, UnresolvedImport, UnusedCatalogEntry,
49 UnusedComponentEmit, UnusedComponentInput, UnusedComponentOutput, UnusedComponentProp,
50 UnusedDependency, UnusedDependencyOverride, UnusedEffectLayer, UnusedExport, UnusedFile,
51 UnusedLoadDataKey, UnusedMember, UnusedServerAction, UnusedSvelteEvent, UnusedTaggedError,
52};
53use crate::semantic::{
54 SemanticCandidateDecision, SemanticCandidateDecisionKind, SemanticCompleteness,
55};
56
57/// Shared note for the `duplicate-exports` fix action. This const is the
58/// single source of truth: `crates/cli/src/report/shared.rs` aliases it for
59/// the human report.
60pub const NAMESPACE_BARREL_HINT: &str = "If every location is the sole `index.*` of its directory, this is likely an intentional namespace-barrel API. Prefer adding these files to `ignoreExports` over removing exports.";
61
62/// JSON Schema fragment URL for the `add-to-config` `ignoreExports` action's
63/// `value` payload. Pinned to the main branch so users browsing the action
64/// value can navigate directly to the rule shape.
65pub const IGNORE_EXPORTS_VALUE_SCHEMA: &str =
66 "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreExports";
67
68/// JSON Schema fragment URL for the `ignoreCatalogReferences` rule items
69/// referenced by `add-to-config` actions on `unresolved-catalog-references`.
70const IGNORE_CATALOG_REFERENCES_VALUE_SCHEMA: &str = "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreCatalogReferences/items";
71
72/// JSON Schema fragment URL for the `ignoreDependencyOverrides` rule items
73/// referenced by `add-to-config` actions on both the unused- and
74/// misconfigured-override findings.
75const IGNORE_DEPENDENCY_OVERRIDES_VALUE_SCHEMA: &str = "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreDependencyOverrides/items";
76
77pub(crate) fn manual_framework_fix(
78 kind: FixActionType,
79 description: &str,
80 note: &str,
81) -> IssueAction {
82 IssueAction::Fix(FixAction {
83 kind,
84 auto_fixable: false,
85 description: description.to_string(),
86 note: Some(note.to_string()),
87 available_in_catalogs: None,
88 suggested_target: None,
89 })
90}
91
92pub(crate) fn suppress_line(comment: &str) -> IssueAction {
93 IssueAction::SuppressLine(SuppressLineAction {
94 kind: SuppressLineKind::SuppressLine,
95 auto_fixable: false,
96 description: "Suppress with an inline comment above the line".to_string(),
97 comment: comment.to_string(),
98 scope: None,
99 })
100}
101
102/// A per-finding caveat on a dead-code verdict that a file this run never
103/// fully analyzed can distort.
104///
105/// Advisory provenance, in the same spirit as the fix path's
106/// `low_confidence_off_graph` / `low_confidence_unresolved_imports` skip
107/// reasons: a caveat never withholds, reorders, downgrades, or re-severities
108/// the finding, and never changes an exit code. It records that the verdict
109/// was computed over an import graph fallow already knows is incomplete, so a
110/// reader who sees the finding also sees the caveat instead of having to
111/// notice a diagnostic at the other end of the envelope.
112///
113/// Deliberately NOT named `confidence`: `health --targets` already emits a
114/// `confidence` key holding an enum string, and a shared consumer helper that
115/// met both would see the same key change type. Emitted on every finding type
116/// that registers it: the reachability arrays (`unused_files[]`,
117/// `unused_exports[]`, `unused_types[]`), the member arrays
118/// (`unused_enum_members[]`, `unused_class_members[]`, `unused_store_members[]`),
119/// and the three dependency arrays. Sorted and deduplicated, absent from the
120/// wire when empty. The set is open in the same sense
121/// `workspace_diagnostics[].kind` is: treat an unrecognised value as "some
122/// caveat" rather than as an error.
123#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
124#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
125#[serde(rename_all = "kebab-case")]
126pub enum ReachabilityCaveat {
127 /// This finding's own file is one the run did not fully analyze, so the
128 /// export and import lists extracted from it may stop short of the real
129 /// ones. That reaches an `unused-file` verdict directly, because the
130 /// "is any export of this file referenced from a reachable module" test
131 /// reads exactly that truncated export list.
132 ///
133 /// Three workspace diagnostics put a file in this state: a partial parse
134 /// (`source-parse-degraded`), no parse (`source-nesting-too-deep`), or no
135 /// read (`source-read-failure`). The token names the consequence rather than
136 /// either cause, so a future kind that leaves a discovered file partially
137 /// extracted carries the same value.
138 ///
139 /// Dependency findings never carry this value: the file they name is a
140 /// `package.json`, not a parsed source module.
141 IncompleteFileAnalysis,
142 /// A module whose import list feeds this verdict was not analyzed, so the
143 /// import that would have credited this finding may never have been seen.
144 ///
145 /// The cause is any workspace diagnostic that leaves a source file's
146 /// imports unseen: a partial parse (`source-parse-degraded`), no parse
147 /// (`source-nesting-too-deep`), no read (`source-read-failure`), or a skip
148 /// by discovery before the read (`skipped-large-file`,
149 /// `skipped-minified-file`, `skipped-source-dotdir`). The token names the
150 /// class rather than any one cause.
151 ///
152 /// Which modules feed the verdict differs by array, and the caveat is
153 /// emitted only when a degraded module is actually one of them:
154 ///
155 /// - `unused_files[]`, `unused_exports[]`, and `unused_types[]` rest on
156 /// reachability, so only a degraded module that is itself observed
157 /// reachable can change the verdict. When every degraded module is
158 /// unreachable the caveat is absent, and soundly: the first missing edge
159 /// on any entry-point path leaves from a module whose every predecessor
160 /// edge was observed, so that module is observed reachable. A file the
161 /// run never read has no module and no graph node, so its reachability
162 /// is not observable at all and that narrowing cannot be applied: any
163 /// skipped or unreadable source caveats every reachability verdict in
164 /// the run.
165 /// - the member arrays (`unused_enum_members[]`, `unused_class_members[]`,
166 /// `unused_store_members[]`) do not rest on reachability at all: member
167 /// usage is collected by walking every module the run resolved,
168 /// reachable or not, so this narrowing does not apply to them either.
169 /// Same unnarrowed condition as the dependency arrays below, plus the
170 /// per-finding value above when the member's own file is the one that
171 /// was incompletely analyzed.
172 /// - the dependency arrays rest on whether ANY module in the project
173 /// imports the package specifier, reachable or not, so any degraded
174 /// parse anywhere can hide the import that would have credited the
175 /// package. Reachability does not narrow that one.
176 ///
177 /// The limit, stated because an approximation presented as exact is worse
178 /// than nothing: this is a RUN-level condition, not proof that a degraded
179 /// module imports this path or package. An import the parser never saw
180 /// cannot be attributed to a target, so the link cannot be narrowed
181 /// further without re-reading the source. Read `workspace_diagnostics[]`
182 /// for which files degraded.
183 IncompleteImportGraph,
184}
185
186impl ReachabilityCaveat {
187 /// The wire token.
188 #[must_use]
189 pub const fn token(self) -> &'static str {
190 match self {
191 Self::IncompleteFileAnalysis => "incomplete-file-analysis",
192 Self::IncompleteImportGraph => "incomplete-import-graph",
193 }
194 }
195
196 /// A one-line explanation for human and agent-facing renderers.
197 ///
198 /// Neither sentence names a single cause. A degraded parse is only one of
199 /// the ways a file goes unread: it may also have been unreadable, or
200 /// skipped before it was ever opened (oversized, minified, in a dotdir).
201 /// Naming the parse case alone sent a reader whose run was degraded by the
202 /// size guard hunting for parse errors that do not exist, so both messages
203 /// point at `workspace_diagnostics[]`, which names the actual files.
204 #[must_use]
205 pub const fn message(self) -> &'static str {
206 match self {
207 Self::IncompleteFileAnalysis => {
208 "low: this file was not fully analyzed, so its extracted exports and imports may be incomplete; see workspace_diagnostics[]"
209 }
210 Self::IncompleteImportGraph => {
211 "low: a module this run did not fully read may hold an import that would credit this; see workspace_diagnostics[]"
212 }
213 }
214 }
215
216 /// A compact label for a one-line human renderer, where the full
217 /// [`Self::message`] would not fit next to the finding.
218 #[must_use]
219 pub const fn short_label(self) -> &'static str {
220 match self {
221 Self::IncompleteFileAnalysis => "incomplete file analysis",
222 Self::IncompleteImportGraph => "incomplete import graph",
223 }
224 }
225}
226
227/// The compact labels of `caveats`, joined for a one-line renderer, or `None`
228/// when there is nothing to say.
229#[must_use]
230pub fn caveat_labels(caveats: &[ReachabilityCaveat]) -> Option<String> {
231 if caveats.is_empty() {
232 return None;
233 }
234 let labels: Vec<&str> = caveats
235 .iter()
236 .map(|caveat| ReachabilityCaveat::short_label(*caveat))
237 .collect();
238 Some(labels.join(", "))
239}
240
241/// The compact parenthetical a one-line human renderer appends to a finding
242/// carrying `caveats`, or `None` when there is nothing to say. Shared by every
243/// dead-code section so the suffix reads the same everywhere.
244#[must_use]
245pub fn caveat_suffix(caveats: &[ReachabilityCaveat]) -> Option<String> {
246 caveat_labels(caveats).map(|labels| format!("{CAVEAT_SUFFIX_MARKER}{labels})"))
247}
248
249/// The opening of the parenthetical [`caveat_suffix`] renders. Public because
250/// one consumer can only see the rendered description: the CI review formats
251/// build their comments from CodeClimate issues, whose `description` is the
252/// only place the caveat survives (the CodeClimate wire is a published
253/// contract with no field for it). Recognising the marker is what lets those
254/// formats withhold a one-click mutation.
255pub const CAVEAT_SUFFIX_MARKER: &str = " (caveat: ";
256
257/// Whether a rendered finding description already carries a caveat
258/// parenthetical, for a surface holding the string rather than the typed
259/// finding.
260///
261/// Lives here, next to the renderer, so the producer and the recogniser cannot
262/// drift; `a_rendered_suffix_is_recognised_by_the_marker` pins the pair.
263#[must_use]
264pub fn description_carries_caveat(description: &str) -> bool {
265 description.contains(CAVEAT_SUFFIX_MARKER)
266}
267
268/// The compact label for one wire token, for a renderer that reads
269/// `reachability_caveats[]` back off a serialized envelope instead of holding
270/// the typed findings.
271///
272/// The value set is OPEN, exactly as the wire documentation says: a token this
273/// build does not recognise is still a caveat, so it is rendered as itself with
274/// its separators relaxed into spaces rather than dropped. Dropping it would
275/// turn a finding whose evidence is incomplete back into a confident one,
276/// which is the failure this whole mechanism exists to prevent.
277#[must_use]
278pub fn caveat_label_for_token(token: &str) -> String {
279 match token {
280 "incomplete-file-analysis" => {
281 ReachabilityCaveat::short_label(ReachabilityCaveat::IncompleteFileAnalysis).to_owned()
282 }
283 "incomplete-import-graph" => {
284 ReachabilityCaveat::short_label(ReachabilityCaveat::IncompleteImportGraph).to_owned()
285 }
286 other => other.replace('-', " "),
287 }
288}
289
290/// The joined compact labels for wire tokens, or `None` when there are none.
291/// The token-side twin of [`caveat_labels`], for renderers driven by a
292/// serialized envelope rather than by typed findings.
293#[must_use]
294pub fn caveat_labels_for_tokens<'a>(tokens: impl IntoIterator<Item = &'a str>) -> Option<String> {
295 let labels: Vec<String> = tokens.into_iter().map(caveat_label_for_token).collect();
296 if labels.is_empty() {
297 return None;
298 }
299 Some(labels.join(", "))
300}
301
302/// The token-side twin of [`caveat_suffix`], so an envelope-driven renderer
303/// appends the same parenthetical as a findings-driven one.
304#[must_use]
305pub fn caveat_suffix_for_tokens<'a>(tokens: impl IntoIterator<Item = &'a str>) -> Option<String> {
306 caveat_labels_for_tokens(tokens).map(|labels| format!("{CAVEAT_SUFFIX_MARKER}{labels})"))
307}
308
309/// The note every mutating action carries once [`MutationEvidence`] withholds
310/// it. One string, so the CLI action array, the LSP diagnostic, and the MCP
311/// tool contract all say the same thing about the same finding.
312pub const INCOMPLETE_EVIDENCE_NOTE: &str = "Evidence is incomplete: a file this run did not fully analyze may hold the reference that \
313 credits this finding, so this mutation is not applied automatically. Resolve the files named \
314 in workspace_diagnostics[] and re-run, or confirm and remove it by hand.";
315
316/// The one question every mutation surface asks before it offers, plans, or
317/// performs a dead-code finding's removal.
318///
319/// A finding whose reachability verdict rests on a file the run never fully
320/// read is still REPORTED, always: a caveat withholds no finding, changes no
321/// severity, and moves no exit code. What it withholds is the automation. The
322/// predicate lives here, next to the findings, rather than in any one consumer,
323/// because it was re-derived per surface three times and a fourth door opened
324/// every time: `fallow fix`, the LSP quick fix, and the `auto_fixable` flag an
325/// agent plans against each answered it differently. Every one of those now
326/// calls [`Self::may_auto_apply_mutation`], so a sixth finding type or a fourth
327/// mutation surface cannot silently opt out.
328///
329/// Implemented only by the findings that can carry a caveat. A finding type
330/// that exposes an auto-fixable mutation and does NOT implement this trait is
331/// the bug this trait exists to make visible; `every_auto_fixable_dead_code_
332/// mutation_is_gated` in this module's tests pins that.
333pub trait MutationEvidence {
334 /// The advisory caveats recorded on the reachability verdict behind this
335 /// finding. Empty when the run analyzed every file it discovered.
336 fn reachability_caveats(&self) -> &[ReachabilityCaveat];
337
338 /// Whether this finding's mutation may be applied without a human first
339 /// being told the evidence is incomplete. THE gate: never re-derive it,
340 /// never widen it per surface.
341 fn may_auto_apply_mutation(&self) -> bool {
342 self.reachability_caveats().is_empty()
343 }
344}
345
346/// Record a run's caveats on a finding, enforcing [`MutationEvidence`] on its
347/// typed `actions` in the same step.
348///
349/// Separate from [`MutationEvidence`] so a read-only consumer (the fixer, the
350/// LSP, a renderer) depends only on the question and never on the answer's
351/// setter. `annotate` in the analysis layer is the single writer.
352pub trait CaveatedFinding: MutationEvidence {
353 /// Store `caveats` and downgrade every mutating action the gate now
354 /// withholds. The field itself stays `pub` (a renderer test builds an
355 /// already-caveated fixture directly, without running the annotation
356 /// pass); every non-test writer goes through this setter instead of the
357 /// field so the downgrade travels with the write.
358 fn set_reachability_caveats(&mut self, caveats: Vec<ReachabilityCaveat>);
359}
360
361/// Downgrade every `Fix` action in `actions` when `caveats` is non-empty, so
362/// the `auto_fixable` flag an agent plans against matches what `fallow fix`
363/// will actually do. Only ever downgrades: a surface that has already decided
364/// a mutation is unsafe for its own reasons keeps that decision.
365fn withhold_caveated_mutations(actions: &mut [IssueAction], caveats: &[ReachabilityCaveat]) {
366 if caveats.is_empty() {
367 return;
368 }
369 for action in actions {
370 let IssueAction::Fix(fix) = action else {
371 continue;
372 };
373 fix.auto_fixable = false;
374 fix.note = Some(match fix.note.take() {
375 Some(existing) => format!("{existing}. {INCOMPLETE_EVIDENCE_NOTE}"),
376 None => INCOMPLETE_EVIDENCE_NOTE.to_string(),
377 });
378 }
379}
380
381/// Implement the gate for a finding wrapper carrying a `reachability_caveats`
382/// field alongside a typed `actions` array. A new caveated finding type adds
383/// one line here rather than a new per-surface branch.
384macro_rules! impl_caveated_finding {
385 ($($finding:ty),+ $(,)?) => {
386 $(
387 impl MutationEvidence for $finding {
388 fn reachability_caveats(&self) -> &[ReachabilityCaveat] {
389 &self.reachability_caveats
390 }
391 }
392
393 impl CaveatedFinding for $finding {
394 fn set_reachability_caveats(&mut self, caveats: Vec<ReachabilityCaveat>) {
395 withhold_caveated_mutations(&mut self.actions, &caveats);
396 self.reachability_caveats = caveats;
397 }
398 }
399 )+
400 };
401}
402
403/// Wire-shape envelope for an [`UnusedFile`] finding. The bare finding
404/// flattens in via `#[serde(flatten)]`, with a typed `actions` array
405/// populated at construction time and the audit-pass `introduced` flag
406/// attached as an optional sibling.
407#[derive(Debug, Clone, Serialize, Deserialize)]
408#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
409pub struct UnusedFileFinding {
410 /// The underlying dead-code entry.
411 #[serde(flatten)]
412 pub file: UnusedFile,
413 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
414 /// `~<k>` suffix when several findings of one type share an identity.
415 /// Line and column are not inputs, so the id survives line shifts,
416 /// reformats and reorders. A rename of the file or the symbol gives a
417 /// new id. Absent in output from older versions.
418 #[serde(default, skip_serializing_if = "Option::is_none")]
419 pub finding_id: Option<String>,
420 /// Suggested next steps: a `delete-file` primary and a `suppress-file`
421 /// secondary. Always emitted (possibly empty for forward-compat).
422 pub actions: Vec<IssueAction>,
423 /// Set by the audit pass when this finding is introduced relative to
424 /// the merge-base. `None` when serialized directly from Rust.
425 #[serde(default, skip_serializing_if = "Option::is_none")]
426 pub introduced: Option<AuditIntroduced>,
427 /// Gate severity of this finding after `rules` and `overrides[].rules`
428 /// resolve for its path. CI formats read it for the annotation, SARIF
429 /// and CodeClimate level. Absent in output from older versions. Not
430 /// part of the finding identity, baseline keys or fingerprints.
431 #[serde(
432 default,
433 skip_serializing_if = "Option::is_none",
434 deserialize_with = "deserialize_effective_severity"
435 )]
436 pub effective_severity: Option<EffectiveSeverity>,
437 /// Advisory caveats on the reachability verdict behind this finding.
438 /// Sorted, deduplicated, and omitted from the wire when empty, so a run
439 /// that analyzed every discovered file is byte-identical. Never gates the
440 /// finding or the `delete-file` action, though `fallow fix` does withhold
441 /// the removal of a caveated finding as low confidence.
442 #[serde(default, skip_serializing_if = "Vec::is_empty")]
443 pub reachability_caveats: Vec<ReachabilityCaveat>,
444}
445
446impl UnusedFileFinding {
447 /// Build the wrapper from a raw [`UnusedFile`], computing the typed
448 /// `actions` array inline. `introduced` stays `None` and is set later
449 /// by `annotate_dead_code_json` if the audit pass runs.
450 #[must_use]
451 pub fn with_actions(file: UnusedFile) -> Self {
452 let actions = vec![
453 IssueAction::Fix(FixAction {
454 kind: FixActionType::DeleteFile,
455 auto_fixable: false,
456 description: "Delete this file".to_string(),
457 note: Some(
458 "File deletion may remove runtime functionality not visible to static analysis"
459 .to_string(),
460 ),
461 available_in_catalogs: None,
462 suggested_target: None,
463 }),
464 IssueAction::SuppressFile(SuppressFileAction {
465 kind: SuppressFileKind::SuppressFile,
466 auto_fixable: false,
467 description: "Suppress with a file-level comment at the top of the file"
468 .to_string(),
469 comment: "// fallow-ignore-file unused-file".to_string(),
470 }),
471 ];
472 Self {
473 finding_id: None,
474 file,
475 actions,
476 introduced: None,
477 effective_severity: None,
478 reachability_caveats: Vec::new(),
479 }
480 }
481}
482
483/// Wire-shape envelope for a [`PrivateTypeLeak`] finding. Mirrors
484/// [`UnusedFileFinding`]: flattens the bare finding and carries a typed
485/// `actions` array (`export-type` primary plus `suppress-line` secondary).
486#[derive(Debug, Clone, Serialize, Deserialize)]
487#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
488pub struct PrivateTypeLeakFinding {
489 /// The underlying dead-code entry.
490 #[serde(flatten)]
491 pub leak: PrivateTypeLeak,
492 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
493 /// `~<k>` suffix when several findings of one type share an identity.
494 /// Line and column are not inputs, so the id survives line shifts,
495 /// reformats and reorders. A rename of the file or the symbol gives a
496 /// new id. Absent in output from older versions.
497 #[serde(default, skip_serializing_if = "Option::is_none")]
498 pub finding_id: Option<String>,
499 /// Suggested next steps. Always emitted (possibly empty for
500 /// forward-compat).
501 pub actions: Vec<IssueAction>,
502 /// Set by the audit pass when this finding is introduced relative to
503 /// the merge-base.
504 #[serde(default, skip_serializing_if = "Option::is_none")]
505 pub introduced: Option<AuditIntroduced>,
506 /// Gate severity of this finding after `rules` and `overrides[].rules`
507 /// resolve for its path. CI formats read it for the annotation, SARIF
508 /// and CodeClimate level. Absent in output from older versions. Not
509 /// part of the finding identity, baseline keys or fingerprints.
510 #[serde(
511 default,
512 skip_serializing_if = "Option::is_none",
513 deserialize_with = "deserialize_effective_severity"
514 )]
515 pub effective_severity: Option<EffectiveSeverity>,
516}
517
518impl PrivateTypeLeakFinding {
519 /// Build the wrapper from a raw [`PrivateTypeLeak`].
520 #[must_use]
521 pub fn with_actions(leak: PrivateTypeLeak) -> Self {
522 let actions = vec![
523 IssueAction::Fix(FixAction {
524 kind: FixActionType::ExportType,
525 auto_fixable: false,
526 description: "Export the referenced private type by name".to_string(),
527 note: Some(
528 "Keep the type exported while it is part of a public signature".to_string(),
529 ),
530 available_in_catalogs: None,
531 suggested_target: None,
532 }),
533 IssueAction::SuppressLine(SuppressLineAction {
534 kind: SuppressLineKind::SuppressLine,
535 auto_fixable: false,
536 description: "Suppress with an inline comment above the line".to_string(),
537 comment: "// fallow-ignore-next-line private-type-leak".to_string(),
538 scope: None,
539 }),
540 ];
541 Self {
542 finding_id: None,
543 leak,
544 actions,
545 introduced: None,
546 effective_severity: None,
547 }
548 }
549}
550
551/// Wire-shape envelope for a [`DeprecatedExportInUse`] finding. Carries a
552/// manual `migrate-deprecated-export` primary action plus a `suppress-line`
553/// secondary. Never auto-fixable: fallow does not rewrite consumers.
554#[derive(Debug, Clone, Serialize, Deserialize)]
555#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
556pub struct DeprecatedExportInUseFinding {
557 /// The underlying dead-code entry.
558 #[serde(flatten)]
559 pub export: DeprecatedExportInUse,
560 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
561 /// `~<k>` suffix when several findings of one type share an identity.
562 /// Line and column are not inputs, so the id survives line shifts,
563 /// reformats and reorders. A rename of the file or the symbol gives a
564 /// new id. Absent in output from older versions.
565 #[serde(default, skip_serializing_if = "Option::is_none")]
566 pub finding_id: Option<String>,
567 /// Suggested next steps. Always emitted (possibly empty for
568 /// forward-compat).
569 pub actions: Vec<IssueAction>,
570 /// Set by the audit pass when this finding is introduced relative to
571 /// the merge-base.
572 #[serde(default, skip_serializing_if = "Option::is_none")]
573 pub introduced: Option<AuditIntroduced>,
574 /// Gate severity of this finding after `rules` and `overrides[].rules`
575 /// resolve for its path. CI formats read it for the annotation, SARIF
576 /// and CodeClimate level. Absent in output from older versions. Not
577 /// part of the finding identity, baseline keys or fingerprints.
578 #[serde(
579 default,
580 skip_serializing_if = "Option::is_none",
581 deserialize_with = "deserialize_effective_severity"
582 )]
583 pub effective_severity: Option<EffectiveSeverity>,
584}
585
586impl DeprecatedExportInUseFinding {
587 /// Build the wrapper from a raw [`DeprecatedExportInUse`].
588 #[must_use]
589 pub fn with_actions(export: DeprecatedExportInUse) -> Self {
590 let trace_hint = format!(
591 "For the full consumer list, run `fallow dead-code --trace <path>:{}` with the `path` of this finding.",
592 export.export_name
593 );
594 let note = if export.public_api {
595 format!(
596 "This export is public API. External consumers are not visible, so do not remove it on this evidence alone. {trace_hint}"
597 )
598 } else {
599 format!(
600 "Move each consumer to the replacement that the deprecation message names, then remove the export. {trace_hint}"
601 )
602 };
603 let actions = vec![
604 IssueAction::Fix(FixAction {
605 kind: FixActionType::MigrateDeprecatedExport,
606 auto_fixable: false,
607 description: "Move the consumers off the deprecated export".to_string(),
608 note: Some(note),
609 available_in_catalogs: None,
610 suggested_target: None,
611 }),
612 suppress_line("// fallow-ignore-next-line deprecated-export-in-use"),
613 ];
614 Self {
615 finding_id: None,
616 export,
617 actions,
618 introduced: None,
619 effective_severity: None,
620 }
621 }
622}
623
624/// Wire-shape envelope for an [`UnresolvedImport`] finding. Mirrors
625/// [`UnusedFileFinding`]: flattens the bare finding and carries a typed
626/// `actions` array (`resolve-import` primary plus config and inline
627/// suppression actions).
628#[derive(Debug, Clone, Serialize, Deserialize)]
629#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
630pub struct UnresolvedImportFinding {
631 /// The underlying dead-code entry.
632 #[serde(flatten)]
633 pub import: UnresolvedImport,
634 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
635 /// `~<k>` suffix when several findings of one type share an identity.
636 /// Line and column are not inputs, so the id survives line shifts,
637 /// reformats and reorders. A rename of the file or the symbol gives a
638 /// new id. Absent in output from older versions.
639 #[serde(default, skip_serializing_if = "Option::is_none")]
640 pub finding_id: Option<String>,
641 /// Suggested next steps. Always emitted (possibly empty for
642 /// forward-compat).
643 pub actions: Vec<IssueAction>,
644 /// Set by the audit pass when this finding is introduced relative to
645 /// the merge-base.
646 #[serde(default, skip_serializing_if = "Option::is_none")]
647 pub introduced: Option<AuditIntroduced>,
648 /// Gate severity of this finding after `rules` and `overrides[].rules`
649 /// resolve for its path. CI formats read it for the annotation, SARIF
650 /// and CodeClimate level. Absent in output from older versions. Not
651 /// part of the finding identity, baseline keys or fingerprints.
652 #[serde(
653 default,
654 skip_serializing_if = "Option::is_none",
655 deserialize_with = "deserialize_effective_severity"
656 )]
657 pub effective_severity: Option<EffectiveSeverity>,
658}
659
660impl UnresolvedImportFinding {
661 /// Build the wrapper from a raw [`UnresolvedImport`].
662 #[must_use]
663 pub fn with_actions(import: UnresolvedImport) -> Self {
664 let actions = vec![
665 IssueAction::Fix(FixAction {
666 kind: FixActionType::ResolveImport,
667 auto_fixable: false,
668 description: "Fix the import specifier or install the missing module".to_string(),
669 note: Some(
670 "Verify the module path and check tsconfig paths configuration".to_string(),
671 ),
672 available_in_catalogs: None,
673 suggested_target: None,
674 }),
675 IssueAction::AddToConfig(AddToConfigAction {
676 kind: AddToConfigKind::AddToConfig,
677 auto_fixable: false,
678 description: format!(
679 "Add \"{}\" to ignoreUnresolvedImports in fallow config",
680 import.specifier
681 ),
682 config_key: "ignoreUnresolvedImports".to_string(),
683 value: AddToConfigValue::Scalar(import.specifier.clone()),
684 value_schema: Some(
685 "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreUnresolvedImports/items"
686 .to_string(),
687 ),
688 }),
689 IssueAction::SuppressLine(SuppressLineAction {
690 kind: SuppressLineKind::SuppressLine,
691 auto_fixable: false,
692 description: "Suppress with an inline comment above the line".to_string(),
693 comment: "// fallow-ignore-next-line unresolved-import".to_string(),
694 scope: None,
695 }),
696 ];
697 Self {
698 finding_id: None,
699 import,
700 actions,
701 introduced: None,
702 effective_severity: None,
703 }
704 }
705}
706
707/// Wire-shape envelope for a [`CircularDependency`] finding. Mirrors
708/// [`UnusedFileFinding`]: flattens the bare finding and carries a typed
709/// `actions` array (`refactor-cycle` primary plus `suppress-line`
710/// secondary).
711#[derive(Debug, Clone, Serialize, Deserialize)]
712#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
713pub struct CircularDependencyFinding {
714 /// The underlying dead-code entry.
715 #[serde(flatten)]
716 pub cycle: CircularDependency,
717 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
718 /// `~<k>` suffix when several findings of one type share an identity.
719 /// Line and column are not inputs, so the id survives line shifts,
720 /// reformats and reorders. A rename of the file or the symbol gives a
721 /// new id. Absent in output from older versions.
722 #[serde(default, skip_serializing_if = "Option::is_none")]
723 pub finding_id: Option<String>,
724 /// Suggested next steps. Always emitted (possibly empty for
725 /// forward-compat).
726 pub actions: Vec<IssueAction>,
727 /// Set by the audit pass when this finding is introduced relative to
728 /// the merge-base.
729 #[serde(default, skip_serializing_if = "Option::is_none")]
730 pub introduced: Option<AuditIntroduced>,
731 /// Gate severity of this finding after `rules` and `overrides[].rules`
732 /// resolve for its path. CI formats read it for the annotation, SARIF
733 /// and CodeClimate level. Absent in output from older versions. Not
734 /// part of the finding identity, baseline keys or fingerprints.
735 #[serde(
736 default,
737 skip_serializing_if = "Option::is_none",
738 deserialize_with = "deserialize_effective_severity"
739 )]
740 pub effective_severity: Option<EffectiveSeverity>,
741}
742
743impl CircularDependencyFinding {
744 /// Build the wrapper from a raw [`CircularDependency`].
745 #[must_use]
746 pub fn with_actions(cycle: CircularDependency) -> Self {
747 let actions = vec![
748 IssueAction::Fix(FixAction {
749 kind: FixActionType::RefactorCycle,
750 auto_fixable: false,
751 description: "Extract shared logic into a separate module to break the cycle"
752 .to_string(),
753 note: Some(
754 "Circular imports can cause initialization issues and make code harder to reason about"
755 .to_string(),
756 ),
757 available_in_catalogs: None,
758 suggested_target: None,
759 }),
760 IssueAction::SuppressLine(SuppressLineAction {
761 kind: SuppressLineKind::SuppressLine,
762 auto_fixable: false,
763 description: "Suppress with an inline comment above the line".to_string(),
764 comment: "// fallow-ignore-next-line circular-dependency".to_string(),
765 scope: None,
766 }),
767 ];
768 Self {
769 finding_id: None,
770 cycle,
771 actions,
772 introduced: None,
773 effective_severity: None,
774 }
775 }
776}
777
778/// Wire-shape envelope for a [`PackageCycle`] finding. Mirrors
779/// [`CircularDependencyFinding`]: flattens the bare finding and carries a
780/// typed `actions` array (`refactor-cycle` primary plus `suppress-line`
781/// secondary).
782#[derive(Debug, Clone, Serialize, Deserialize)]
783#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
784pub struct PackageCycleFinding {
785 /// The underlying dead-code entry.
786 #[serde(flatten)]
787 pub cycle: PackageCycle,
788 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
789 /// `~<k>` suffix when several findings of one type share an identity.
790 /// Line and column are not inputs, so the id survives line shifts,
791 /// reformats and reorders. A rename of the file or the symbol gives a
792 /// new id. Absent in output from older versions.
793 #[serde(default, skip_serializing_if = "Option::is_none")]
794 pub finding_id: Option<String>,
795 /// Suggested next steps. Always emitted (possibly empty for
796 /// forward-compat).
797 pub actions: Vec<IssueAction>,
798 /// Set by the audit pass when this finding is introduced relative to
799 /// the merge-base.
800 #[serde(default, skip_serializing_if = "Option::is_none")]
801 pub introduced: Option<AuditIntroduced>,
802 /// Gate severity of this finding after `rules` and `overrides[].rules`
803 /// resolve for its path. CI formats read it for the annotation, SARIF
804 /// and CodeClimate level. Absent in output from older versions. Not
805 /// part of the finding identity, baseline keys or fingerprints.
806 #[serde(
807 default,
808 skip_serializing_if = "Option::is_none",
809 deserialize_with = "deserialize_effective_severity"
810 )]
811 pub effective_severity: Option<EffectiveSeverity>,
812}
813
814impl PackageCycleFinding {
815 /// Build the wrapper from a raw [`PackageCycle`].
816 #[must_use]
817 pub fn with_actions(cycle: PackageCycle) -> Self {
818 let actions = vec![
819 IssueAction::Fix(FixAction {
820 kind: FixActionType::RefactorCycle,
821 auto_fixable: false,
822 description: "Remove the imports on one hop of the cycle, for example by \
823 moving the shared code to a package that both packages import"
824 .to_string(),
825 note: Some(
826 "Packages that import each other cannot be built in dependency order"
827 .to_string(),
828 ),
829 available_in_catalogs: None,
830 suggested_target: None,
831 }),
832 IssueAction::SuppressLine(SuppressLineAction {
833 kind: SuppressLineKind::SuppressLine,
834 auto_fixable: false,
835 description: "Suppress with an inline comment above the import. The cycle \
836 is gone when every import on one hop is suppressed"
837 .to_string(),
838 comment: "// fallow-ignore-next-line package-cycle".to_string(),
839 scope: None,
840 }),
841 ];
842 Self {
843 cycle,
844 finding_id: None,
845 actions,
846 introduced: None,
847 effective_severity: None,
848 }
849 }
850}
851
852/// Wire-shape envelope for a [`BoundaryViolation`] finding. Mirrors
853/// [`UnusedFileFinding`]: flattens the bare finding and carries a typed
854/// `actions` array (`refactor-boundary` primary plus `suppress-line`
855/// secondary).
856#[derive(Debug, Clone, Serialize, Deserialize)]
857#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
858pub struct BoundaryViolationFinding {
859 /// The underlying dead-code entry.
860 #[serde(flatten)]
861 pub violation: BoundaryViolation,
862 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
863 /// `~<k>` suffix when several findings of one type share an identity.
864 /// Line and column are not inputs, so the id survives line shifts,
865 /// reformats and reorders. A rename of the file or the symbol gives a
866 /// new id. Absent in output from older versions.
867 #[serde(default, skip_serializing_if = "Option::is_none")]
868 pub finding_id: Option<String>,
869 /// Suggested next steps. Always emitted (possibly empty for
870 /// forward-compat).
871 pub actions: Vec<IssueAction>,
872 /// Set by the audit pass when this finding is introduced relative to
873 /// the merge-base.
874 #[serde(default, skip_serializing_if = "Option::is_none")]
875 pub introduced: Option<AuditIntroduced>,
876 /// Gate severity of this finding after `rules` and `overrides[].rules`
877 /// resolve for its path. CI formats read it for the annotation, SARIF
878 /// and CodeClimate level. Absent in output from older versions. Not
879 /// part of the finding identity, baseline keys or fingerprints.
880 #[serde(
881 default,
882 skip_serializing_if = "Option::is_none",
883 deserialize_with = "deserialize_effective_severity"
884 )]
885 pub effective_severity: Option<EffectiveSeverity>,
886}
887
888impl BoundaryViolationFinding {
889 /// Build the wrapper from a raw [`BoundaryViolation`].
890 #[must_use]
891 pub fn with_actions(violation: BoundaryViolation) -> Self {
892 let (description, note) = violation.refactor_action_text();
893 let actions = vec![
894 IssueAction::Fix(FixAction {
895 kind: FixActionType::RefactorBoundary,
896 auto_fixable: false,
897 description: description.to_string(),
898 note: Some(note.to_string()),
899 available_in_catalogs: None,
900 suggested_target: None,
901 }),
902 IssueAction::SuppressLine(SuppressLineAction {
903 kind: SuppressLineKind::SuppressLine,
904 auto_fixable: false,
905 description: "Suppress with an inline comment above the line".to_string(),
906 comment: "// fallow-ignore-next-line boundary-violation".to_string(),
907 scope: None,
908 }),
909 ];
910 Self {
911 finding_id: None,
912 violation,
913 actions,
914 introduced: None,
915 effective_severity: None,
916 }
917 }
918}
919
920/// Wire-shape envelope for a [`BoundaryCoverageViolation`] finding. Carries
921/// actions for assigning the file to a zone or explicitly allowing it to stay
922/// unmatched.
923#[derive(Debug, Clone, Serialize, Deserialize)]
924#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
925pub struct BoundaryCoverageViolationFinding {
926 /// The underlying coverage entry.
927 #[serde(flatten)]
928 pub violation: BoundaryCoverageViolation,
929 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
930 /// `~<k>` suffix when several findings of one type share an identity.
931 /// Line and column are not inputs, so the id survives line shifts,
932 /// reformats and reorders. A rename of the file or the symbol gives a
933 /// new id. Absent in output from older versions.
934 #[serde(default, skip_serializing_if = "Option::is_none")]
935 pub finding_id: Option<String>,
936 /// Suggested next steps.
937 pub actions: Vec<IssueAction>,
938 /// Set by the audit pass when this finding is introduced relative to
939 /// the merge-base.
940 #[serde(default, skip_serializing_if = "Option::is_none")]
941 pub introduced: Option<AuditIntroduced>,
942 /// Gate severity of this finding after `rules` and `overrides[].rules`
943 /// resolve for its path. CI formats read it for the annotation, SARIF
944 /// and CodeClimate level. Absent in output from older versions. Not
945 /// part of the finding identity, baseline keys or fingerprints.
946 #[serde(
947 default,
948 skip_serializing_if = "Option::is_none",
949 deserialize_with = "deserialize_effective_severity"
950 )]
951 pub effective_severity: Option<EffectiveSeverity>,
952}
953
954impl BoundaryCoverageViolationFinding {
955 /// Build the wrapper from a raw [`BoundaryCoverageViolation`].
956 #[must_use]
957 pub fn with_actions(violation: BoundaryCoverageViolation) -> Self {
958 let path = violation.path.to_string_lossy().replace('\\', "/");
959 let actions = vec![
960 IssueAction::Fix(FixAction {
961 kind: FixActionType::RefactorBoundary,
962 auto_fixable: false,
963 description: "Add this file to a boundary zone pattern or move it under an existing zone"
964 .to_string(),
965 note: Some(
966 "Boundary coverage is enabled, so every analyzed source file must match a zone unless allow-listed"
967 .to_string(),
968 ),
969 available_in_catalogs: None,
970 suggested_target: None,
971 }),
972 IssueAction::AddToConfig(AddToConfigAction {
973 kind: AddToConfigKind::AddToConfig,
974 auto_fixable: false,
975 description: format!(
976 "Add \"{path}\" to boundaries.coverage.allowUnmatched in fallow config"
977 ),
978 config_key: "boundaries.coverage.allowUnmatched".to_string(),
979 value: AddToConfigValue::Scalar(path),
980 value_schema: Some(
981 "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/boundaries/properties/coverage/properties/allowUnmatched/items"
982 .to_string(),
983 ),
984 }),
985 IssueAction::SuppressFile(SuppressFileAction {
986 kind: SuppressFileKind::SuppressFile,
987 auto_fixable: false,
988 description: "Suppress with a file-level comment at the top of the file"
989 .to_string(),
990 comment: "// fallow-ignore-file boundary-violation".to_string(),
991 }),
992 ];
993 Self {
994 finding_id: None,
995 violation,
996 actions,
997 introduced: None,
998 effective_severity: None,
999 }
1000 }
1001}
1002
1003/// Wire-shape envelope for a [`BoundaryCallViolation`] finding. Carries
1004/// actions for refactoring the forbidden call out of the zone or suppressing
1005/// it with the shared `boundary-violation` token.
1006#[derive(Debug, Clone, Serialize, Deserialize)]
1007#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1008pub struct BoundaryCallViolationFinding {
1009 /// The underlying forbidden-call entry.
1010 #[serde(flatten)]
1011 pub violation: BoundaryCallViolation,
1012 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1013 /// `~<k>` suffix when several findings of one type share an identity.
1014 /// Line and column are not inputs, so the id survives line shifts,
1015 /// reformats and reorders. A rename of the file or the symbol gives a
1016 /// new id. Absent in output from older versions.
1017 #[serde(default, skip_serializing_if = "Option::is_none")]
1018 pub finding_id: Option<String>,
1019 /// Suggested next steps.
1020 pub actions: Vec<IssueAction>,
1021 /// Set by the audit pass when this finding is introduced relative to
1022 /// the merge-base.
1023 #[serde(default, skip_serializing_if = "Option::is_none")]
1024 pub introduced: Option<AuditIntroduced>,
1025 /// Gate severity of this finding after `rules` and `overrides[].rules`
1026 /// resolve for its path. CI formats read it for the annotation, SARIF
1027 /// and CodeClimate level. Absent in output from older versions. Not
1028 /// part of the finding identity, baseline keys or fingerprints.
1029 #[serde(
1030 default,
1031 skip_serializing_if = "Option::is_none",
1032 deserialize_with = "deserialize_effective_severity"
1033 )]
1034 pub effective_severity: Option<EffectiveSeverity>,
1035}
1036
1037impl BoundaryCallViolationFinding {
1038 /// Build the wrapper from a raw [`BoundaryCallViolation`].
1039 #[must_use]
1040 pub fn with_actions(violation: BoundaryCallViolation) -> Self {
1041 let actions = vec![
1042 IssueAction::Fix(FixAction {
1043 kind: FixActionType::RefactorBoundary,
1044 auto_fixable: false,
1045 description: format!(
1046 "Move the `{}` call out of zone '{}' or behind an allowed abstraction",
1047 violation.callee, violation.zone,
1048 ),
1049 note: Some(format!(
1050 "`boundaries.calls.forbidden` bans callees matching `{}` from zone '{}'. The check is syntactic: it applies only to files classified into a zone and does not follow aliased or re-bound callees",
1051 violation.pattern, violation.zone,
1052 )),
1053 available_in_catalogs: None,
1054 suggested_target: None,
1055 }),
1056 IssueAction::SuppressLine(SuppressLineAction {
1057 kind: SuppressLineKind::SuppressLine,
1058 auto_fixable: false,
1059 description: "Suppress with an inline comment above the line".to_string(),
1060 comment: "// fallow-ignore-next-line boundary-violation".to_string(),
1061 scope: None,
1062 }),
1063 IssueAction::SuppressFile(SuppressFileAction {
1064 kind: SuppressFileKind::SuppressFile,
1065 auto_fixable: false,
1066 description: "Suppress with a file-level comment at the top of the file"
1067 .to_string(),
1068 comment: "// fallow-ignore-file boundary-violation".to_string(),
1069 }),
1070 ];
1071 Self {
1072 finding_id: None,
1073 violation,
1074 actions,
1075 introduced: None,
1076 effective_severity: None,
1077 }
1078 }
1079}
1080
1081/// Wire-shape envelope for a [`PolicyViolation`] finding. Carries actions for
1082/// replacing the banned call, import, or effect, or suppressing it with a scoped
1083/// `policy-violation:<pack>/<rule-id>` token.
1084#[derive(Debug, Clone, Serialize, Deserialize)]
1085#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1086pub struct PolicyViolationFinding {
1087 /// The underlying rule-pack policy entry.
1088 #[serde(flatten)]
1089 pub violation: PolicyViolation,
1090 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1091 /// `~<k>` suffix when several findings of one type share an identity.
1092 /// Line and column are not inputs, so the id survives line shifts,
1093 /// reformats and reorders. A rename of the file or the symbol gives a
1094 /// new id. Absent in output from older versions.
1095 #[serde(default, skip_serializing_if = "Option::is_none")]
1096 pub finding_id: Option<String>,
1097 /// Suggested next steps.
1098 pub actions: Vec<IssueAction>,
1099 /// Set by the audit pass when this finding is introduced relative to
1100 /// the merge-base.
1101 #[serde(default, skip_serializing_if = "Option::is_none")]
1102 pub introduced: Option<AuditIntroduced>,
1103}
1104
1105impl PolicyViolationFinding {
1106 /// Build the wrapper from a raw [`PolicyViolation`].
1107 #[must_use]
1108 pub fn with_actions(violation: PolicyViolation) -> Self {
1109 let what = match violation.kind {
1110 crate::results::PolicyRuleKind::BannedCall => "call",
1111 crate::results::PolicyRuleKind::BannedImport => "import",
1112 crate::results::PolicyRuleKind::BannedEffect => "effect",
1113 crate::results::PolicyRuleKind::BannedExport => "export",
1114 crate::results::PolicyRuleKind::GdpProofProducer => "proof producer",
1115 };
1116 let description = match &violation.message {
1117 Some(message) => format!("Replace the `{}` {what}: {message}", violation.matched),
1118 None => format!("Replace the `{}` {what}", violation.matched),
1119 };
1120 let suppress_token = format!("policy-violation:{}/{}", violation.pack, violation.rule_id);
1121 let note = if violation.kind == crate::results::PolicyRuleKind::GdpProofProducer {
1122 "This check resolves the gdp-ts factory through static imports and unambiguous re-exports. Move proof creation to an allowed module. It does not verify authorization logic or follow arbitrary wrappers.".to_owned()
1123 } else {
1124 format!(
1125 "Rule `{}/{}` from the configured rule packs bans this {what}. The check is syntactic: it does not follow aliased or re-bound callees, and import matching uses the raw specifier",
1126 violation.pack, violation.rule_id,
1127 )
1128 };
1129 let actions = vec![
1130 IssueAction::Fix(FixAction {
1131 kind: FixActionType::ResolvePolicyViolation,
1132 auto_fixable: false,
1133 description,
1134 note: Some(note),
1135 available_in_catalogs: None,
1136 suggested_target: None,
1137 }),
1138 IssueAction::SuppressLine(SuppressLineAction {
1139 kind: SuppressLineKind::SuppressLine,
1140 auto_fixable: false,
1141 description: "Suppress this rule-pack rule with an inline comment above the line"
1142 .to_string(),
1143 comment: format!("// fallow-ignore-next-line {suppress_token}"),
1144 scope: None,
1145 }),
1146 IssueAction::SuppressFile(SuppressFileAction {
1147 kind: SuppressFileKind::SuppressFile,
1148 auto_fixable: false,
1149 description:
1150 "Suppress this rule-pack rule with a file-level comment at the top of the file"
1151 .to_string(),
1152 comment: format!("// fallow-ignore-file {suppress_token}"),
1153 }),
1154 ];
1155 Self {
1156 finding_id: None,
1157 violation,
1158 actions,
1159 introduced: None,
1160 }
1161 }
1162}
1163
1164/// Wire-shape envelope for an [`UnusedExport`] finding consumed under the
1165/// `unused_exports` key. Same Rust struct as [`UnusedTypeFinding`], with a
1166/// different fix description so consumers can tell value-export from
1167/// type-export removal at the action level.
1168#[derive(Debug, Clone, Serialize, Deserialize)]
1169#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1170pub struct UnusedExportFinding {
1171 /// The underlying dead-code entry.
1172 #[serde(flatten)]
1173 pub export: UnusedExport,
1174 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1175 /// `~<k>` suffix when several findings of one type share an identity.
1176 /// Line and column are not inputs, so the id survives line shifts,
1177 /// reformats and reorders. A rename of the file or the symbol gives a
1178 /// new id. Absent in output from older versions.
1179 #[serde(default, skip_serializing_if = "Option::is_none")]
1180 pub finding_id: Option<String>,
1181 /// Suggested next steps. Always emitted (possibly empty for
1182 /// forward-compat).
1183 pub actions: Vec<IssueAction>,
1184 /// Type-aware evidence for this exact candidate when requested.
1185 #[serde(default, skip_serializing_if = "Option::is_none")]
1186 pub semantic: Option<SemanticCandidateDecision>,
1187 /// Set by the audit pass when this finding is introduced relative to
1188 /// the merge-base.
1189 #[serde(default, skip_serializing_if = "Option::is_none")]
1190 pub introduced: Option<AuditIntroduced>,
1191 /// Gate severity of this finding after `rules` and `overrides[].rules`
1192 /// resolve for its path. CI formats read it for the annotation, SARIF
1193 /// and CodeClimate level. Absent in output from older versions. Not
1194 /// part of the finding identity, baseline keys or fingerprints.
1195 #[serde(
1196 default,
1197 skip_serializing_if = "Option::is_none",
1198 deserialize_with = "deserialize_effective_severity"
1199 )]
1200 pub effective_severity: Option<EffectiveSeverity>,
1201 /// Advisory caveats on the reachability verdict behind this finding.
1202 /// Sorted, deduplicated, and omitted from the wire when empty. Never gates
1203 /// the finding or the `remove-export` action, though `fallow fix` does
1204 /// withhold the removal of a caveated export as low confidence.
1205 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1206 pub reachability_caveats: Vec<ReachabilityCaveat>,
1207}
1208
1209impl UnusedExportFinding {
1210 /// Build the wrapper. When `export.is_re_export` is true, the fix
1211 /// action's `note` warns about possible public-API surface; otherwise
1212 /// `note` is absent on the fix action.
1213 #[must_use]
1214 pub fn with_actions(export: UnusedExport) -> Self {
1215 let note = if export.is_re_export {
1216 Some(
1217 "This finding originates from a re-export; verify it is not part of your public API before removing"
1218 .to_string(),
1219 )
1220 } else {
1221 None
1222 };
1223 let actions = vec![
1224 IssueAction::Fix(FixAction {
1225 kind: FixActionType::RemoveExport,
1226 auto_fixable: true,
1227 description: "Remove the unused export from the public API".to_string(),
1228 note,
1229 available_in_catalogs: None,
1230 suggested_target: None,
1231 }),
1232 IssueAction::SuppressLine(SuppressLineAction {
1233 kind: SuppressLineKind::SuppressLine,
1234 auto_fixable: false,
1235 description: "Suppress with an inline comment above the line".to_string(),
1236 comment: "// fallow-ignore-next-line unused-export".to_string(),
1237 scope: None,
1238 }),
1239 ];
1240 Self {
1241 finding_id: None,
1242 export,
1243 actions,
1244 semantic: None,
1245 introduced: None,
1246 effective_severity: None,
1247 reachability_caveats: Vec::new(),
1248 }
1249 }
1250
1251 /// Attach type-aware evidence and disable the syntactic fix when semantic
1252 /// analysis could not establish complete negative evidence.
1253 pub fn set_semantic_decision(&mut self, decision: SemanticCandidateDecision) {
1254 set_export_semantic_action(&mut self.actions, &decision, &self.reachability_caveats);
1255 self.semantic = Some(decision);
1256 }
1257}
1258
1259/// Wire-shape envelope for an [`UnusedExport`] finding consumed under the
1260/// `unused_types` key. Wraps the same bare [`UnusedExport`] struct as
1261/// [`UnusedExportFinding`] but emits a fix action targeted at type-only
1262/// declarations, with the same `is_re_export`-aware note swap.
1263#[derive(Debug, Clone, Serialize, Deserialize)]
1264#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1265pub struct UnusedTypeFinding {
1266 /// The underlying dead-code entry.
1267 #[serde(flatten)]
1268 pub export: UnusedExport,
1269 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1270 /// `~<k>` suffix when several findings of one type share an identity.
1271 /// Line and column are not inputs, so the id survives line shifts,
1272 /// reformats and reorders. A rename of the file or the symbol gives a
1273 /// new id. Absent in output from older versions.
1274 #[serde(default, skip_serializing_if = "Option::is_none")]
1275 pub finding_id: Option<String>,
1276 /// Suggested next steps. Always emitted (possibly empty for
1277 /// forward-compat).
1278 pub actions: Vec<IssueAction>,
1279 /// Type-aware evidence for this exact candidate when requested.
1280 #[serde(default, skip_serializing_if = "Option::is_none")]
1281 pub semantic: Option<SemanticCandidateDecision>,
1282 /// Set by the audit pass when this finding is introduced relative to
1283 /// the merge-base.
1284 #[serde(default, skip_serializing_if = "Option::is_none")]
1285 pub introduced: Option<AuditIntroduced>,
1286 /// Gate severity of this finding after `rules` and `overrides[].rules`
1287 /// resolve for its path. CI formats read it for the annotation, SARIF
1288 /// and CodeClimate level. Absent in output from older versions. Not
1289 /// part of the finding identity, baseline keys or fingerprints.
1290 #[serde(
1291 default,
1292 skip_serializing_if = "Option::is_none",
1293 deserialize_with = "deserialize_effective_severity"
1294 )]
1295 pub effective_severity: Option<EffectiveSeverity>,
1296 /// Advisory caveats on the reachability verdict behind this finding.
1297 /// A type export rests on exactly the reachability test an
1298 /// `unused_exports[]` entry does, and the LSP offers the same
1299 /// remove-the-`export`-keyword quick fix for both, so the two must render
1300 /// with the same confidence. Sorted, deduplicated, omitted when empty.
1301 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1302 pub reachability_caveats: Vec<ReachabilityCaveat>,
1303}
1304
1305impl UnusedTypeFinding {
1306 /// Build the wrapper. `is_re_export` swaps the fix note the same way as
1307 /// [`UnusedExportFinding::with_actions`].
1308 #[must_use]
1309 pub fn with_actions(export: UnusedExport) -> Self {
1310 let note = if export.is_re_export {
1311 Some(
1312 "This finding originates from a re-export; verify it is not part of your public API before removing"
1313 .to_string(),
1314 )
1315 } else {
1316 None
1317 };
1318 let actions = vec![
1319 IssueAction::Fix(FixAction {
1320 kind: FixActionType::RemoveExport,
1321 auto_fixable: true,
1322 description:
1323 "Remove the `export` (or `export type`) keyword from the type declaration"
1324 .to_string(),
1325 note,
1326 available_in_catalogs: None,
1327 suggested_target: None,
1328 }),
1329 IssueAction::SuppressLine(SuppressLineAction {
1330 kind: SuppressLineKind::SuppressLine,
1331 auto_fixable: false,
1332 description: "Suppress with an inline comment above the line".to_string(),
1333 comment: "// fallow-ignore-next-line unused-type".to_string(),
1334 scope: None,
1335 }),
1336 ];
1337 Self {
1338 finding_id: None,
1339 export,
1340 actions,
1341 semantic: None,
1342 introduced: None,
1343 effective_severity: None,
1344 reachability_caveats: Vec::new(),
1345 }
1346 }
1347
1348 /// Attach type-aware evidence and disable the syntactic fix when semantic
1349 /// analysis could not establish complete negative evidence.
1350 pub fn set_semantic_decision(&mut self, decision: SemanticCandidateDecision) {
1351 set_export_semantic_action(&mut self.actions, &decision, &self.reachability_caveats);
1352 self.semantic = Some(decision);
1353 }
1354}
1355
1356/// The semantic pass runs in the API layer, AFTER the analysis layer stamped
1357/// this run's caveats, and it is the one code path that RAISES `auto_fixable`.
1358/// It therefore has to ask the gate too, or a `Complete` semantic verdict would
1359/// silently re-open a mutation the incomplete run had already withheld.
1360fn set_export_semantic_action(
1361 actions: &mut [IssueAction],
1362 decision: &SemanticCandidateDecision,
1363 caveats: &[ReachabilityCaveat],
1364) {
1365 let complete_negative = decision.decision
1366 == SemanticCandidateDecisionKind::ConfirmedNoStaticReferences
1367 && decision.status == SemanticCompleteness::Complete;
1368 let Some(IssueAction::Fix(action)) = actions.first_mut() else {
1369 return;
1370 };
1371 action.auto_fixable = complete_negative && caveats.is_empty();
1372 if !complete_negative {
1373 action.note = Some(
1374 "Type-aware analysis retained this candidate because complete negative evidence was not available"
1375 .to_string(),
1376 );
1377 }
1378 if !caveats.is_empty() {
1379 action.note = Some(INCOMPLETE_EVIDENCE_NOTE.to_string());
1380 }
1381}
1382
1383/// Wire-shape envelope for an [`InvalidClientExport`] finding. There is no safe
1384/// auto-fix: the export itself may be a legitimate client-component value
1385/// export that happens to collide with a Next.js server-only name, so removing
1386/// it could break the component. Actions are a manual `move-to-server-module`
1387/// fix (the real remediation) plus a line-level suppress.
1388#[derive(Debug, Clone, Serialize, Deserialize)]
1389#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1390pub struct InvalidClientExportFinding {
1391 /// The underlying dead-code entry.
1392 #[serde(flatten)]
1393 pub export: InvalidClientExport,
1394 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1395 /// `~<k>` suffix when several findings of one type share an identity.
1396 /// Line and column are not inputs, so the id survives line shifts,
1397 /// reformats and reorders. A rename of the file or the symbol gives a
1398 /// new id. Absent in output from older versions.
1399 #[serde(default, skip_serializing_if = "Option::is_none")]
1400 pub finding_id: Option<String>,
1401 /// Suggested next steps. Always emitted (possibly empty for
1402 /// forward-compat).
1403 pub actions: Vec<IssueAction>,
1404 /// Set by the audit pass when this finding is introduced relative to
1405 /// the merge-base.
1406 #[serde(default, skip_serializing_if = "Option::is_none")]
1407 pub introduced: Option<AuditIntroduced>,
1408 /// Gate severity of this finding after `rules` and `overrides[].rules`
1409 /// resolve for its path. CI formats read it for the annotation, SARIF
1410 /// and CodeClimate level. Absent in output from older versions. Not
1411 /// part of the finding identity, baseline keys or fingerprints.
1412 #[serde(
1413 default,
1414 skip_serializing_if = "Option::is_none",
1415 deserialize_with = "deserialize_effective_severity"
1416 )]
1417 pub effective_severity: Option<EffectiveSeverity>,
1418}
1419
1420impl InvalidClientExportFinding {
1421 /// Build the wrapper from a raw [`InvalidClientExport`]. Emits a manual
1422 /// fix action (move the server-only export to a non-client module) plus a
1423 /// line-level suppress: there is no safe auto-fix because removing the
1424 /// export could break a legitimate client component.
1425 #[must_use]
1426 pub fn with_actions(export: InvalidClientExport) -> Self {
1427 let actions = vec![
1428 IssueAction::Fix(FixAction {
1429 kind: FixActionType::MoveToServerModule,
1430 auto_fixable: false,
1431 description: "Move the server-only export to a non-client module and import it from there"
1432 .to_string(),
1433 note: Some(
1434 "A \"use client\" file cannot export a Next.js server-only or route-config name; Next.js rejects it at build time"
1435 .to_string(),
1436 ),
1437 available_in_catalogs: None,
1438 suggested_target: None,
1439 }),
1440 IssueAction::SuppressLine(SuppressLineAction {
1441 kind: SuppressLineKind::SuppressLine,
1442 auto_fixable: false,
1443 description: "Suppress with an inline comment above the line".to_string(),
1444 comment: "// fallow-ignore-next-line invalid-client-export".to_string(),
1445 scope: None,
1446 }),
1447 ];
1448 Self {
1449 finding_id: None,
1450 export,
1451 actions,
1452 introduced: None,
1453 effective_severity: None,
1454 }
1455 }
1456}
1457
1458/// Wire-shape envelope for a [`MixedClientServerBarrel`] finding. There is no
1459/// safe auto-fix: splitting a barrel into separate client and server modules is
1460/// a human decision (the barrel may intentionally aggregate both surfaces).
1461/// Actions are a manual `split-mixed-barrel` fix (the real remediation) plus a
1462/// line-level suppress.
1463#[derive(Debug, Clone, Serialize, Deserialize)]
1464#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1465pub struct MixedClientServerBarrelFinding {
1466 /// The underlying dead-code entry.
1467 #[serde(flatten)]
1468 pub barrel: MixedClientServerBarrel,
1469 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1470 /// `~<k>` suffix when several findings of one type share an identity.
1471 /// Line and column are not inputs, so the id survives line shifts,
1472 /// reformats and reorders. A rename of the file or the symbol gives a
1473 /// new id. Absent in output from older versions.
1474 #[serde(default, skip_serializing_if = "Option::is_none")]
1475 pub finding_id: Option<String>,
1476 /// Suggested next steps. Always emitted (possibly empty for
1477 /// forward-compat).
1478 pub actions: Vec<IssueAction>,
1479 /// Set by the audit pass when this finding is introduced relative to
1480 /// the merge-base.
1481 #[serde(default, skip_serializing_if = "Option::is_none")]
1482 pub introduced: Option<AuditIntroduced>,
1483 /// Gate severity of this finding after `rules` and `overrides[].rules`
1484 /// resolve for its path. CI formats read it for the annotation, SARIF
1485 /// and CodeClimate level. Absent in output from older versions. Not
1486 /// part of the finding identity, baseline keys or fingerprints.
1487 #[serde(
1488 default,
1489 skip_serializing_if = "Option::is_none",
1490 deserialize_with = "deserialize_effective_severity"
1491 )]
1492 pub effective_severity: Option<EffectiveSeverity>,
1493}
1494
1495impl MixedClientServerBarrelFinding {
1496 /// Build the wrapper from a raw [`MixedClientServerBarrel`]. Emits a manual
1497 /// fix action (split the barrel into separate client and server halves)
1498 /// plus a line-level suppress: there is no safe auto-fix because splitting
1499 /// the barrel is a human decision.
1500 #[must_use]
1501 pub fn with_actions(barrel: MixedClientServerBarrel) -> Self {
1502 let actions = vec![
1503 IssueAction::Fix(FixAction {
1504 kind: FixActionType::SplitMixedBarrel,
1505 auto_fixable: false,
1506 description: "Split the barrel so client and server-only modules are re-exported from separate files"
1507 .to_string(),
1508 note: Some(
1509 "Importing one name from this barrel drags the other's directive across the client/server boundary"
1510 .to_string(),
1511 ),
1512 available_in_catalogs: None,
1513 suggested_target: None,
1514 }),
1515 IssueAction::SuppressLine(SuppressLineAction {
1516 kind: SuppressLineKind::SuppressLine,
1517 auto_fixable: false,
1518 description: "Suppress with an inline comment above the line".to_string(),
1519 comment: "// fallow-ignore-next-line mixed-client-server-barrel".to_string(),
1520 scope: None,
1521 }),
1522 ];
1523 Self {
1524 finding_id: None,
1525 barrel,
1526 actions,
1527 introduced: None,
1528 effective_severity: None,
1529 }
1530 }
1531}
1532
1533/// Wire-shape envelope for a [`MisplacedDirective`] finding. There is no safe
1534/// auto-fix: moving a directive to the leading prologue is a small but
1535/// judgement-bearing edit (the author may have intended the file to be a
1536/// server module after all). Actions are a manual `hoist-directive` fix (the
1537/// real remediation) plus a line-level suppress.
1538#[derive(Debug, Clone, Serialize, Deserialize)]
1539#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1540pub struct MisplacedDirectiveFinding {
1541 /// The underlying dead-code entry.
1542 #[serde(flatten)]
1543 pub directive_site: MisplacedDirective,
1544 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1545 /// `~<k>` suffix when several findings of one type share an identity.
1546 /// Line and column are not inputs, so the id survives line shifts,
1547 /// reformats and reorders. A rename of the file or the symbol gives a
1548 /// new id. Absent in output from older versions.
1549 #[serde(default, skip_serializing_if = "Option::is_none")]
1550 pub finding_id: Option<String>,
1551 /// Suggested next steps. Always emitted (possibly empty for
1552 /// forward-compat).
1553 pub actions: Vec<IssueAction>,
1554 /// Set by the audit pass when this finding is introduced relative to
1555 /// the merge-base.
1556 #[serde(default, skip_serializing_if = "Option::is_none")]
1557 pub introduced: Option<AuditIntroduced>,
1558 /// Gate severity of this finding after `rules` and `overrides[].rules`
1559 /// resolve for its path. CI formats read it for the annotation, SARIF
1560 /// and CodeClimate level. Absent in output from older versions. Not
1561 /// part of the finding identity, baseline keys or fingerprints.
1562 #[serde(
1563 default,
1564 skip_serializing_if = "Option::is_none",
1565 deserialize_with = "deserialize_effective_severity"
1566 )]
1567 pub effective_severity: Option<EffectiveSeverity>,
1568}
1569
1570impl MisplacedDirectiveFinding {
1571 /// Build the wrapper from a raw [`MisplacedDirective`]. Emits a manual fix
1572 /// action (hoist the directive to the leading prologue) plus a line-level
1573 /// suppress: there is no safe auto-fix because moving a directive can
1574 /// change module semantics and is a human decision.
1575 #[must_use]
1576 pub fn with_actions(directive_site: MisplacedDirective) -> Self {
1577 let actions = vec![
1578 IssueAction::Fix(FixAction {
1579 kind: FixActionType::HoistDirective,
1580 auto_fixable: false,
1581 description: "Move the directive to the very top of the file, above all imports and statements"
1582 .to_string(),
1583 note: Some(
1584 "An RSC bundler honors the directive only in the leading prologue; here it precedes other statements and is silently ignored"
1585 .to_string(),
1586 ),
1587 available_in_catalogs: None,
1588 suggested_target: None,
1589 }),
1590 IssueAction::SuppressLine(SuppressLineAction {
1591 kind: SuppressLineKind::SuppressLine,
1592 auto_fixable: false,
1593 description: "Suppress with an inline comment above the line".to_string(),
1594 comment: "// fallow-ignore-next-line misplaced-directive".to_string(),
1595 scope: None,
1596 }),
1597 ];
1598 Self {
1599 finding_id: None,
1600 directive_site,
1601 actions,
1602 introduced: None,
1603 effective_severity: None,
1604 }
1605 }
1606}
1607
1608/// Wire-shape envelope for an [`UnprovidedInject`] finding. There is no safe
1609/// auto-fix: the fix is binary but judgement-bearing (add a `provide` for the
1610/// key, or delete the dead inject). Actions are manual remediation guidance
1611/// plus a line-level suppress.
1612#[derive(Debug, Clone, Serialize, Deserialize)]
1613#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1614pub struct UnprovidedInjectFinding {
1615 /// The underlying finding.
1616 #[serde(flatten)]
1617 pub inject: UnprovidedInject,
1618 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1619 /// `~<k>` suffix when several findings of one type share an identity.
1620 /// Line and column are not inputs, so the id survives line shifts,
1621 /// reformats and reorders. A rename of the file or the symbol gives a
1622 /// new id. Absent in output from older versions.
1623 #[serde(default, skip_serializing_if = "Option::is_none")]
1624 pub finding_id: Option<String>,
1625 /// Suggested next steps. Always emitted (possibly empty for
1626 /// forward-compat).
1627 pub actions: Vec<IssueAction>,
1628 /// Set by the audit pass when this finding is introduced relative to
1629 /// the merge-base.
1630 #[serde(default, skip_serializing_if = "Option::is_none")]
1631 pub introduced: Option<AuditIntroduced>,
1632 /// Gate severity of this finding after `rules` and `overrides[].rules`
1633 /// resolve for its path. CI formats read it for the annotation, SARIF
1634 /// and CodeClimate level. Absent in output from older versions. Not
1635 /// part of the finding identity, baseline keys or fingerprints.
1636 #[serde(
1637 default,
1638 skip_serializing_if = "Option::is_none",
1639 deserialize_with = "deserialize_effective_severity"
1640 )]
1641 pub effective_severity: Option<EffectiveSeverity>,
1642}
1643
1644impl UnprovidedInjectFinding {
1645 /// Build the wrapper from a raw [`UnprovidedInject`]. Emits a manual fix
1646 /// action plus a line-level suppress.
1647 #[must_use]
1648 pub fn with_actions(inject: UnprovidedInject) -> Self {
1649 let actions = vec![
1650 manual_framework_fix(
1651 FixActionType::ProvideInject,
1652 "Provide this injected key, or remove the inject / getContext call",
1653 "Manual review required: dependency-injection keys can be provided by framework wiring, tests, or package consumers outside this project.",
1654 ),
1655 suppress_line("// fallow-ignore-next-line unprovided-inject"),
1656 ];
1657 Self {
1658 finding_id: None,
1659 inject,
1660 actions,
1661 introduced: None,
1662 effective_severity: None,
1663 }
1664 }
1665}
1666
1667/// Wire-shape envelope for an [`UnusedServerAction`] finding. There is no safe
1668/// auto-fix: the fix is binary but judgement-bearing (wire the action up to a
1669/// consumer, or delete it). Actions are manual remediation guidance plus a
1670/// line-level suppress.
1671#[derive(Debug, Clone, Serialize, Deserialize)]
1672#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1673pub struct UnusedServerActionFinding {
1674 /// The underlying finding.
1675 #[serde(flatten)]
1676 pub action: UnusedServerAction,
1677 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1678 /// `~<k>` suffix when several findings of one type share an identity.
1679 /// Line and column are not inputs, so the id survives line shifts,
1680 /// reformats and reorders. A rename of the file or the symbol gives a
1681 /// new id. Absent in output from older versions.
1682 #[serde(default, skip_serializing_if = "Option::is_none")]
1683 pub finding_id: Option<String>,
1684 /// Suggested next steps. Always emitted (possibly empty for
1685 /// forward-compat).
1686 pub actions: Vec<IssueAction>,
1687 /// Set by the audit pass when this finding is introduced relative to
1688 /// the merge-base.
1689 #[serde(default, skip_serializing_if = "Option::is_none")]
1690 pub introduced: Option<AuditIntroduced>,
1691 /// Gate severity of this finding after `rules` and `overrides[].rules`
1692 /// resolve for its path. CI formats read it for the annotation, SARIF
1693 /// and CodeClimate level. Absent in output from older versions. Not
1694 /// part of the finding identity, baseline keys or fingerprints.
1695 #[serde(
1696 default,
1697 skip_serializing_if = "Option::is_none",
1698 deserialize_with = "deserialize_effective_severity"
1699 )]
1700 pub effective_severity: Option<EffectiveSeverity>,
1701}
1702
1703impl UnusedServerActionFinding {
1704 /// Build the wrapper from a raw [`UnusedServerAction`]. Emits a manual fix
1705 /// action plus a line-level suppress.
1706 #[must_use]
1707 pub fn with_actions(action: UnusedServerAction) -> Self {
1708 let actions = vec![
1709 manual_framework_fix(
1710 FixActionType::WireServerAction,
1711 "Wire the server action to a caller or form action, or remove it",
1712 "Manual review required: server actions may still be POST-able by action id or invoked reflectively outside the static project graph.",
1713 ),
1714 suppress_line("// fallow-ignore-next-line unused-server-action"),
1715 ];
1716 Self {
1717 finding_id: None,
1718 action,
1719 actions,
1720 introduced: None,
1721 effective_severity: None,
1722 }
1723 }
1724}
1725
1726/// Wire-shape envelope for an [`UnusedLoadDataKey`] finding. There is no safe
1727/// auto-fix: a `load()` fetch can have side effects, so deleting the key is a
1728/// human call. Actions are manual remediation guidance plus a line-level
1729/// suppress.
1730#[derive(Debug, Clone, Serialize, Deserialize)]
1731#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1732pub struct UnusedLoadDataKeyFinding {
1733 /// The underlying finding.
1734 #[serde(flatten)]
1735 pub key: UnusedLoadDataKey,
1736 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1737 /// `~<k>` suffix when several findings of one type share an identity.
1738 /// Line and column are not inputs, so the id survives line shifts,
1739 /// reformats and reorders. A rename of the file or the symbol gives a
1740 /// new id. Absent in output from older versions.
1741 #[serde(default, skip_serializing_if = "Option::is_none")]
1742 pub finding_id: Option<String>,
1743 /// Suggested next steps. Always emitted (possibly empty for
1744 /// forward-compat).
1745 pub actions: Vec<IssueAction>,
1746 /// Set by the audit pass when this finding is introduced relative to
1747 /// the merge-base.
1748 #[serde(default, skip_serializing_if = "Option::is_none")]
1749 pub introduced: Option<AuditIntroduced>,
1750 /// Gate severity of this finding after `rules` and `overrides[].rules`
1751 /// resolve for its path. CI formats read it for the annotation, SARIF
1752 /// and CodeClimate level. Absent in output from older versions. Not
1753 /// part of the finding identity, baseline keys or fingerprints.
1754 #[serde(
1755 default,
1756 skip_serializing_if = "Option::is_none",
1757 deserialize_with = "deserialize_effective_severity"
1758 )]
1759 pub effective_severity: Option<EffectiveSeverity>,
1760}
1761
1762impl UnusedLoadDataKeyFinding {
1763 /// Build the wrapper from a raw [`UnusedLoadDataKey`]. Emits a manual fix
1764 /// action plus a line-level suppress.
1765 #[must_use]
1766 pub fn with_actions(key: UnusedLoadDataKey) -> Self {
1767 let actions = vec![
1768 manual_framework_fix(
1769 FixActionType::UseLoadData,
1770 "Read this load data key from the route UI, or remove it from the load return",
1771 "Manual review required: load functions can perform real server or database work, so verify side effects before deleting the producer.",
1772 ),
1773 suppress_line("// fallow-ignore-next-line unused-load-data-key"),
1774 ];
1775 Self {
1776 finding_id: None,
1777 key,
1778 actions,
1779 introduced: None,
1780 effective_severity: None,
1781 }
1782 }
1783}
1784
1785/// Wire-shape envelope for an [`UnrenderedComponent`] finding. There is no safe
1786/// auto-fix: the fix is binary but judgement-bearing (render the component
1787/// somewhere, or delete the dead component). Actions are manual remediation
1788/// guidance plus a line-level suppress.
1789#[derive(Debug, Clone, Serialize, Deserialize)]
1790#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1791pub struct UnrenderedComponentFinding {
1792 /// The underlying finding.
1793 #[serde(flatten)]
1794 pub component: UnrenderedComponent,
1795 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1796 /// `~<k>` suffix when several findings of one type share an identity.
1797 /// Line and column are not inputs, so the id survives line shifts,
1798 /// reformats and reorders. A rename of the file or the symbol gives a
1799 /// new id. Absent in output from older versions.
1800 #[serde(default, skip_serializing_if = "Option::is_none")]
1801 pub finding_id: Option<String>,
1802 /// Suggested next steps. Always emitted (possibly empty for
1803 /// forward-compat).
1804 pub actions: Vec<IssueAction>,
1805 /// Set by the audit pass when this finding is introduced relative to
1806 /// the merge-base.
1807 #[serde(default, skip_serializing_if = "Option::is_none")]
1808 pub introduced: Option<AuditIntroduced>,
1809 /// Gate severity of this finding after `rules` and `overrides[].rules`
1810 /// resolve for its path. CI formats read it for the annotation, SARIF
1811 /// and CodeClimate level. Absent in output from older versions. Not
1812 /// part of the finding identity, baseline keys or fingerprints.
1813 #[serde(
1814 default,
1815 skip_serializing_if = "Option::is_none",
1816 deserialize_with = "deserialize_effective_severity"
1817 )]
1818 pub effective_severity: Option<EffectiveSeverity>,
1819}
1820
1821impl UnrenderedComponentFinding {
1822 /// Build the wrapper from a raw [`UnrenderedComponent`]. Emits a manual
1823 /// fix action plus a line-level suppress.
1824 #[must_use]
1825 pub fn with_actions(component: UnrenderedComponent) -> Self {
1826 let actions = vec![
1827 manual_framework_fix(
1828 FixActionType::RenderComponent,
1829 "Render the reachable component from project code, or remove it",
1830 "Manual review required: exported library components and dynamic render registries can be intentionally reachable without static template usage.",
1831 ),
1832 suppress_line("// fallow-ignore-next-line unrendered-component"),
1833 ];
1834 Self {
1835 finding_id: None,
1836 component,
1837 actions,
1838 introduced: None,
1839 effective_severity: None,
1840 }
1841 }
1842}
1843
1844/// Wire-shape envelope for an [`UnusedComponentProp`] finding. There is no safe
1845/// auto-fix: removing a declared prop is judgement-bearing (the prop may be part
1846/// of a deliberately-stable public component API). Actions are manual
1847/// remediation guidance plus a line-level suppress at the prop declaration.
1848#[derive(Debug, Clone, Serialize, Deserialize)]
1849#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1850pub struct UnusedComponentPropFinding {
1851 /// The underlying finding.
1852 #[serde(flatten)]
1853 pub prop: UnusedComponentProp,
1854 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1855 /// `~<k>` suffix when several findings of one type share an identity.
1856 /// Line and column are not inputs, so the id survives line shifts,
1857 /// reformats and reorders. A rename of the file or the symbol gives a
1858 /// new id. Absent in output from older versions.
1859 #[serde(default, skip_serializing_if = "Option::is_none")]
1860 pub finding_id: Option<String>,
1861 /// Suggested next steps. Always emitted (possibly empty for
1862 /// forward-compat).
1863 pub actions: Vec<IssueAction>,
1864 /// Set by the audit pass when this finding is introduced relative to
1865 /// the merge-base.
1866 #[serde(default, skip_serializing_if = "Option::is_none")]
1867 pub introduced: Option<AuditIntroduced>,
1868 /// Gate severity of this finding after `rules` and `overrides[].rules`
1869 /// resolve for its path. CI formats read it for the annotation, SARIF
1870 /// and CodeClimate level. Absent in output from older versions. Not
1871 /// part of the finding identity, baseline keys or fingerprints.
1872 #[serde(
1873 default,
1874 skip_serializing_if = "Option::is_none",
1875 deserialize_with = "deserialize_effective_severity"
1876 )]
1877 pub effective_severity: Option<EffectiveSeverity>,
1878}
1879
1880impl UnusedComponentPropFinding {
1881 /// Build the wrapper from a raw [`UnusedComponentProp`]. Emits a manual
1882 /// fix action plus a line-level suppress.
1883 #[must_use]
1884 pub fn with_actions(prop: UnusedComponentProp) -> Self {
1885 let actions = vec![
1886 manual_framework_fix(
1887 FixActionType::UseComponentProp,
1888 "Use the declared prop in the component, or remove it from the component API",
1889 "Manual review required: public component APIs can intentionally keep stable props for external consumers.",
1890 ),
1891 suppress_line("// fallow-ignore-next-line unused-component-prop"),
1892 ];
1893 Self {
1894 finding_id: None,
1895 prop,
1896 actions,
1897 introduced: None,
1898 effective_severity: None,
1899 }
1900 }
1901}
1902
1903/// Wire-shape envelope for an [`UnusedComponentEmit`] finding. There is no safe
1904/// auto-fix: removing a declared emit is judgement-bearing (the event may be
1905/// part of a deliberately-stable public component API). Actions are manual
1906/// remediation guidance plus a line-level suppress at the emit declaration.
1907#[derive(Debug, Clone, Serialize, Deserialize)]
1908#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1909pub struct UnusedComponentEmitFinding {
1910 /// The underlying finding.
1911 #[serde(flatten)]
1912 pub emit: UnusedComponentEmit,
1913 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1914 /// `~<k>` suffix when several findings of one type share an identity.
1915 /// Line and column are not inputs, so the id survives line shifts,
1916 /// reformats and reorders. A rename of the file or the symbol gives a
1917 /// new id. Absent in output from older versions.
1918 #[serde(default, skip_serializing_if = "Option::is_none")]
1919 pub finding_id: Option<String>,
1920 /// Suggested next steps. Always emitted (possibly empty for
1921 /// forward-compat).
1922 pub actions: Vec<IssueAction>,
1923 /// Set by the audit pass when this finding is introduced relative to
1924 /// the merge-base.
1925 #[serde(default, skip_serializing_if = "Option::is_none")]
1926 pub introduced: Option<AuditIntroduced>,
1927 /// Gate severity of this finding after `rules` and `overrides[].rules`
1928 /// resolve for its path. CI formats read it for the annotation, SARIF
1929 /// and CodeClimate level. Absent in output from older versions. Not
1930 /// part of the finding identity, baseline keys or fingerprints.
1931 #[serde(
1932 default,
1933 skip_serializing_if = "Option::is_none",
1934 deserialize_with = "deserialize_effective_severity"
1935 )]
1936 pub effective_severity: Option<EffectiveSeverity>,
1937}
1938
1939impl UnusedComponentEmitFinding {
1940 /// Build the wrapper from a raw [`UnusedComponentEmit`]. Emits a manual
1941 /// fix action plus a line-level suppress.
1942 #[must_use]
1943 pub fn with_actions(emit: UnusedComponentEmit) -> Self {
1944 let actions = vec![
1945 manual_framework_fix(
1946 FixActionType::EmitComponentEvent,
1947 "Emit the declared event from the component, or remove it from the component API",
1948 "Manual review required: public component APIs can intentionally keep stable events for external listeners.",
1949 ),
1950 suppress_line("// fallow-ignore-next-line unused-component-emit"),
1951 ];
1952 Self {
1953 finding_id: None,
1954 emit,
1955 actions,
1956 introduced: None,
1957 effective_severity: None,
1958 }
1959 }
1960}
1961
1962/// Wire-shape envelope for an [`UnusedSvelteEvent`] finding. There is no safe
1963/// auto-fix: removing a dispatched event is judgement-bearing (the event may be
1964/// part of a deliberately-stable public component API, or a listener may be
1965/// added later). Actions are manual remediation guidance plus a line-level
1966/// suppress at the `dispatch` call.
1967#[derive(Debug, Clone, Serialize, Deserialize)]
1968#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1969pub struct UnusedSvelteEventFinding {
1970 /// The underlying finding.
1971 #[serde(flatten)]
1972 pub event: UnusedSvelteEvent,
1973 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
1974 /// `~<k>` suffix when several findings of one type share an identity.
1975 /// Line and column are not inputs, so the id survives line shifts,
1976 /// reformats and reorders. A rename of the file or the symbol gives a
1977 /// new id. Absent in output from older versions.
1978 #[serde(default, skip_serializing_if = "Option::is_none")]
1979 pub finding_id: Option<String>,
1980 /// Suggested next steps. Always emitted (possibly empty for
1981 /// forward-compat).
1982 pub actions: Vec<IssueAction>,
1983 /// Set by the audit pass when this finding is introduced relative to
1984 /// the merge-base.
1985 #[serde(default, skip_serializing_if = "Option::is_none")]
1986 pub introduced: Option<AuditIntroduced>,
1987 /// Gate severity of this finding after `rules` and `overrides[].rules`
1988 /// resolve for its path. CI formats read it for the annotation, SARIF
1989 /// and CodeClimate level. Absent in output from older versions. Not
1990 /// part of the finding identity, baseline keys or fingerprints.
1991 #[serde(
1992 default,
1993 skip_serializing_if = "Option::is_none",
1994 deserialize_with = "deserialize_effective_severity"
1995 )]
1996 pub effective_severity: Option<EffectiveSeverity>,
1997}
1998
1999impl UnusedSvelteEventFinding {
2000 /// Build the wrapper from a raw [`UnusedSvelteEvent`]. Emits a manual fix
2001 /// action plus a line-level suppress.
2002 #[must_use]
2003 pub fn with_actions(event: UnusedSvelteEvent) -> Self {
2004 let actions = vec![
2005 manual_framework_fix(
2006 FixActionType::WireSvelteEvent,
2007 "Add or forward a listener for this custom event, or remove the dispatch",
2008 "Manual review required: public Svelte component APIs can intentionally dispatch events for package consumers outside this project.",
2009 ),
2010 suppress_line("// fallow-ignore-next-line unused-svelte-event"),
2011 ];
2012 Self {
2013 finding_id: None,
2014 event,
2015 actions,
2016 introduced: None,
2017 effective_severity: None,
2018 }
2019 }
2020}
2021
2022/// Wire-shape envelope for a [`DuplicateExportAlias`] finding. There is no
2023/// safe auto-fix: a consumer outside the project can import any of the
2024/// names. Actions are manual remediation guidance plus a line-level
2025/// suppress.
2026#[derive(Debug, Clone, Serialize, Deserialize)]
2027#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2028pub struct DuplicateExportAliasFinding {
2029 /// The underlying finding.
2030 #[serde(flatten)]
2031 pub alias: DuplicateExportAlias,
2032 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2033 /// `~<k>` suffix when several findings of one type share an identity.
2034 /// Line and column are not inputs, so the id survives line shifts,
2035 /// reformats and reorders. A rename of the file or the binding gives a
2036 /// new id. Absent in output from older versions.
2037 #[serde(default, skip_serializing_if = "Option::is_none")]
2038 pub finding_id: Option<String>,
2039 /// Suggested next steps. Always emitted (possibly empty for
2040 /// forward-compat).
2041 pub actions: Vec<IssueAction>,
2042 /// Set by the audit pass when this finding is introduced relative to
2043 /// the merge-base.
2044 #[serde(default, skip_serializing_if = "Option::is_none")]
2045 pub introduced: Option<AuditIntroduced>,
2046 /// Gate severity of this finding after `rules` and `overrides[].rules`
2047 /// resolve for its path. CI formats read it for the annotation, SARIF
2048 /// and CodeClimate level. Absent in output from older versions. Not
2049 /// part of the finding identity, baseline keys or fingerprints.
2050 #[serde(
2051 default,
2052 skip_serializing_if = "Option::is_none",
2053 deserialize_with = "deserialize_effective_severity"
2054 )]
2055 pub effective_severity: Option<EffectiveSeverity>,
2056}
2057
2058impl DuplicateExportAliasFinding {
2059 /// Build the wrapper from a raw [`DuplicateExportAlias`]. Emits a manual
2060 /// fix action plus a line-level suppress.
2061 #[must_use]
2062 pub fn with_actions(alias: DuplicateExportAlias) -> Self {
2063 let actions = vec![
2064 manual_framework_fix(
2065 FixActionType::RemoveDuplicate,
2066 "Keep one export name for the binding and remove the other names",
2067 "Manual review required: update the importers of a removed name first. Code outside the analyzed project can import any of the names. If the names are an intentional public API, add them to ignoreExports.",
2068 ),
2069 suppress_line("// fallow-ignore-next-line duplicate-export-alias"),
2070 ];
2071 Self {
2072 finding_id: None,
2073 alias,
2074 actions,
2075 introduced: None,
2076 effective_severity: None,
2077 }
2078 }
2079}
2080
2081/// Wire-shape envelope for an [`UnusedEffectLayer`] finding. There is no safe auto-fix: a test or a script outside the project graph can still use the layer. Actions are manual
2082/// remediation guidance plus a line-level suppress.
2083#[derive(Debug, Clone, Serialize, Deserialize)]
2084#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2085pub struct UnusedEffectLayerFinding {
2086 /// The underlying finding.
2087 #[serde(flatten)]
2088 pub layer: UnusedEffectLayer,
2089 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2090 /// `~<k>` suffix when several findings of one type share an identity.
2091 /// Line and column are not inputs, so the id survives line shifts,
2092 /// reformats and reorders. A rename of the file or the symbol gives a
2093 /// new id. Absent in output from older versions.
2094 #[serde(default, skip_serializing_if = "Option::is_none")]
2095 pub finding_id: Option<String>,
2096 /// Suggested next steps. Always emitted (possibly empty for
2097 /// forward-compat).
2098 pub actions: Vec<IssueAction>,
2099 /// Set by the audit pass when this finding is introduced relative to
2100 /// the merge-base.
2101 #[serde(default, skip_serializing_if = "Option::is_none")]
2102 pub introduced: Option<AuditIntroduced>,
2103 /// Gate severity of this finding after `rules` and `overrides[].rules`
2104 /// resolve for its path. CI formats read it for the annotation, SARIF
2105 /// and CodeClimate level. Absent in output from older versions. Not
2106 /// part of the finding identity, baseline keys or fingerprints.
2107 #[serde(
2108 default,
2109 skip_serializing_if = "Option::is_none",
2110 deserialize_with = "deserialize_effective_severity"
2111 )]
2112 pub effective_severity: Option<EffectiveSeverity>,
2113}
2114
2115impl UnusedEffectLayerFinding {
2116 /// Build the wrapper from a raw [`UnusedEffectLayer`]. Emits a manual fix action plus
2117 /// a line-level suppress.
2118 #[must_use]
2119 pub fn with_actions(layer: UnusedEffectLayer) -> Self {
2120 let actions = vec![
2121 manual_framework_fix(
2122 FixActionType::ComposeEffectLayer,
2123 "Compose the layer into a layer that reaches a runtime, or remove it with its unused consumers",
2124 "Manual review required: remove the unused consumer layers first, then this layer. Code outside the analyzed project can still compose it.",
2125 ),
2126 suppress_line("// fallow-ignore-next-line unused-effect-layer"),
2127 ];
2128 Self {
2129 finding_id: None,
2130 layer,
2131 actions,
2132 introduced: None,
2133 effective_severity: None,
2134 }
2135 }
2136}
2137
2138/// Wire-shape envelope for an [`UnusedTaggedError`] finding. There is no safe auto-fix: the error can be part of a public API contract. Actions are manual
2139/// remediation guidance plus a line-level suppress.
2140#[derive(Debug, Clone, Serialize, Deserialize)]
2141#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2142pub struct UnusedTaggedErrorFinding {
2143 /// The underlying finding.
2144 #[serde(flatten)]
2145 pub error: UnusedTaggedError,
2146 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2147 /// `~<k>` suffix when several findings of one type share an identity.
2148 /// Line and column are not inputs, so the id survives line shifts,
2149 /// reformats and reorders. A rename of the file or the symbol gives a
2150 /// new id. Absent in output from older versions.
2151 #[serde(default, skip_serializing_if = "Option::is_none")]
2152 pub finding_id: Option<String>,
2153 /// Suggested next steps. Always emitted (possibly empty for
2154 /// forward-compat).
2155 pub actions: Vec<IssueAction>,
2156 /// Set by the audit pass when this finding is introduced relative to
2157 /// the merge-base.
2158 #[serde(default, skip_serializing_if = "Option::is_none")]
2159 pub introduced: Option<AuditIntroduced>,
2160 /// Gate severity of this finding after `rules` and `overrides[].rules`
2161 /// resolve for its path. CI formats read it for the annotation, SARIF
2162 /// and CodeClimate level. Absent in output from older versions. Not
2163 /// part of the finding identity, baseline keys or fingerprints.
2164 #[serde(
2165 default,
2166 skip_serializing_if = "Option::is_none",
2167 deserialize_with = "deserialize_effective_severity"
2168 )]
2169 pub effective_severity: Option<EffectiveSeverity>,
2170}
2171
2172impl UnusedTaggedErrorFinding {
2173 /// Build the wrapper from a raw [`UnusedTaggedError`]. Emits a manual fix action plus
2174 /// a line-level suppress.
2175 #[must_use]
2176 pub fn with_actions(error: UnusedTaggedError) -> Self {
2177 let actions = vec![
2178 manual_framework_fix(
2179 FixActionType::FailTaggedError,
2180 "Fail with this error where the condition occurs, or remove the class and its catchTag handlers",
2181 "Manual review required: consumers outside the analyzed project can construct or decode the error.",
2182 ),
2183 suppress_line("// fallow-ignore-next-line unused-tagged-error"),
2184 ];
2185 Self {
2186 finding_id: None,
2187 error,
2188 actions,
2189 introduced: None,
2190 effective_severity: None,
2191 }
2192 }
2193}
2194
2195/// Wire-shape envelope for an [`UnproducedCatchTag`] finding. There is no safe auto-fix: the handler can guard against a future producer. Actions are manual
2196/// remediation guidance plus a line-level suppress.
2197#[derive(Debug, Clone, Serialize, Deserialize)]
2198#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2199pub struct UnproducedCatchTagFinding {
2200 /// The underlying finding.
2201 #[serde(flatten)]
2202 pub catch_tag: UnproducedCatchTag,
2203 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2204 /// `~<k>` suffix when several findings of one type share an identity.
2205 /// Line and column are not inputs, so the id survives line shifts,
2206 /// reformats and reorders. A rename of the file or the symbol gives a
2207 /// new id. Absent in output from older versions.
2208 #[serde(default, skip_serializing_if = "Option::is_none")]
2209 pub finding_id: Option<String>,
2210 /// Suggested next steps. Always emitted (possibly empty for
2211 /// forward-compat).
2212 pub actions: Vec<IssueAction>,
2213 /// Set by the audit pass when this finding is introduced relative to
2214 /// the merge-base.
2215 #[serde(default, skip_serializing_if = "Option::is_none")]
2216 pub introduced: Option<AuditIntroduced>,
2217 /// Gate severity of this finding after `rules` and `overrides[].rules`
2218 /// resolve for its path. CI formats read it for the annotation, SARIF
2219 /// and CodeClimate level. Absent in output from older versions. Not
2220 /// part of the finding identity, baseline keys or fingerprints.
2221 #[serde(
2222 default,
2223 skip_serializing_if = "Option::is_none",
2224 deserialize_with = "deserialize_effective_severity"
2225 )]
2226 pub effective_severity: Option<EffectiveSeverity>,
2227}
2228
2229impl UnproducedCatchTagFinding {
2230 /// Build the wrapper from a raw [`UnproducedCatchTag`]. Emits a manual fix action plus
2231 /// a line-level suppress.
2232 #[must_use]
2233 pub fn with_actions(catch_tag: UnproducedCatchTag) -> Self {
2234 let actions = vec![
2235 manual_framework_fix(
2236 FixActionType::RemoveCatchTagHandler,
2237 "Remove the handler for this tag, or fail with the error where the condition occurs",
2238 "Manual review required: a package or code outside the analyzed project can produce the tag.",
2239 ),
2240 suppress_line("// fallow-ignore-next-line unproduced-catch-tag"),
2241 ];
2242 Self {
2243 finding_id: None,
2244 catch_tag,
2245 actions,
2246 introduced: None,
2247 effective_severity: None,
2248 }
2249 }
2250}
2251
2252/// Wire-shape envelope for a [`PropDrillingChain`] finding. There is no safe
2253/// auto-fix: collapsing a drilling chain (colocate the consumer, lift to a
2254/// context, or compose the component) is a design decision. The only action is a
2255/// line-level suppress at the source hop's prop declaration. The rule defaults
2256/// to `off` (opt-in health signal), so this finding is dormant by default.
2257#[derive(Debug, Clone, Serialize, Deserialize)]
2258#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2259pub struct PropDrillingChainFinding {
2260 /// The underlying located chain.
2261 #[serde(flatten)]
2262 pub chain: PropDrillingChain,
2263 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2264 /// `~<k>` suffix when several findings of one type share an identity.
2265 /// Line and column are not inputs, so the id survives line shifts,
2266 /// reformats and reorders. A rename of the file or the symbol gives a
2267 /// new id. Absent in output from older versions.
2268 #[serde(default, skip_serializing_if = "Option::is_none")]
2269 pub finding_id: Option<String>,
2270 /// Suggested next steps. Always emitted (possibly empty for
2271 /// forward-compat).
2272 pub actions: Vec<IssueAction>,
2273 /// Set by the audit pass when this finding is introduced relative to
2274 /// the merge-base.
2275 #[serde(default, skip_serializing_if = "Option::is_none")]
2276 pub introduced: Option<AuditIntroduced>,
2277 /// Rule severity after resolving overrides for the source hop. An explicit
2278 /// `error` enforces the chain; `warn` stays advisory under strict flags.
2279 /// Saved reports use this value for CI levels. Absent in older output.
2280 /// Not part of finding identity, baseline keys or fingerprints.
2281 #[serde(
2282 default,
2283 skip_serializing_if = "Option::is_none",
2284 deserialize_with = "deserialize_effective_severity"
2285 )]
2286 pub effective_severity: Option<EffectiveSeverity>,
2287}
2288
2289impl PropDrillingChainFinding {
2290 /// Build the wrapper from a raw [`PropDrillingChain`]. Emits only a
2291 /// line-level suppress action anchored at the source hop: there is no safe
2292 /// auto-fix because collapsing the chain is a design decision (colocate,
2293 /// lift to context, or compose).
2294 #[must_use]
2295 pub fn with_actions(chain: PropDrillingChain) -> Self {
2296 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
2297 kind: SuppressLineKind::SuppressLine,
2298 auto_fixable: false,
2299 description: "Suppress with an inline comment above the source prop declaration"
2300 .to_string(),
2301 comment: "// fallow-ignore-next-line prop-drilling".to_string(),
2302 scope: None,
2303 })];
2304 Self {
2305 finding_id: None,
2306 chain,
2307 actions,
2308 introduced: None,
2309 effective_severity: None,
2310 }
2311 }
2312}
2313
2314/// Wire-shape envelope for a [`ThinWrapper`] finding. There is no safe
2315/// auto-fix: inlining a thin wrapper at its call sites (or deleting it) is a
2316/// design decision. The only action is a line-level suppress at the wrapper's
2317/// definition. The rule defaults to `off` (opt-in health signal), so this
2318/// finding is dormant by default.
2319#[derive(Debug, Clone, Serialize, Deserialize)]
2320#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2321pub struct ThinWrapperFinding {
2322 /// The underlying located thin wrapper.
2323 #[serde(flatten)]
2324 pub wrapper: ThinWrapper,
2325 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2326 /// `~<k>` suffix when several findings of one type share an identity.
2327 /// Line and column are not inputs, so the id survives line shifts,
2328 /// reformats and reorders. A rename of the file or the symbol gives a
2329 /// new id. Absent in output from older versions.
2330 #[serde(default, skip_serializing_if = "Option::is_none")]
2331 pub finding_id: Option<String>,
2332 /// Suggested next steps. Always emitted (possibly empty for
2333 /// forward-compat).
2334 pub actions: Vec<IssueAction>,
2335 /// Set by the audit pass when this finding is introduced relative to
2336 /// the merge-base.
2337 #[serde(default, skip_serializing_if = "Option::is_none")]
2338 pub introduced: Option<AuditIntroduced>,
2339 /// Rule severity of this finding. Explicit errors enforce analysis gates;
2340 /// warnings stay advisory, including under strict flags. Saved reports
2341 /// retain this value for CI levels without the original config. Absent
2342 /// in output from older versions. Not part of finding identity, baseline
2343 /// keys or fingerprints.
2344 #[serde(
2345 default,
2346 skip_serializing_if = "Option::is_none",
2347 deserialize_with = "deserialize_effective_severity"
2348 )]
2349 pub effective_severity: Option<EffectiveSeverity>,
2350}
2351
2352impl ThinWrapperFinding {
2353 /// Build the wrapper from a raw [`ThinWrapper`]. Emits only a line-level
2354 /// suppress action anchored at the wrapper definition: there is no safe
2355 /// auto-fix because inlining or deleting the wrapper is a design decision.
2356 #[must_use]
2357 pub fn with_actions(wrapper: ThinWrapper) -> Self {
2358 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
2359 kind: SuppressLineKind::SuppressLine,
2360 auto_fixable: false,
2361 description: "Suppress with an inline comment above the component definition"
2362 .to_string(),
2363 comment: "// fallow-ignore-next-line thin-wrapper".to_string(),
2364 scope: None,
2365 })];
2366 Self {
2367 finding_id: None,
2368 wrapper,
2369 actions,
2370 introduced: None,
2371 effective_severity: None,
2372 }
2373 }
2374}
2375
2376/// Wire-shape envelope for a [`DuplicatePropShape`] finding. There is no safe
2377/// auto-fix: extracting a shared `Props` type or a base component for a group of
2378/// same-shaped components is a design decision. The actions are manual guidance
2379/// (extract the shared shape) plus a line-level suppress at the component
2380/// definition and a file-level suppress escape hatch (mirroring the
2381/// route-collision multi-file model). The rule defaults to `off` (opt-in health
2382/// signal), so this finding is dormant by default.
2383#[derive(Debug, Clone, Serialize, Deserialize)]
2384#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2385pub struct DuplicatePropShapeFinding {
2386 /// The underlying duplicate-prop-shape entry.
2387 #[serde(flatten)]
2388 pub shape: DuplicatePropShape,
2389 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2390 /// `~<k>` suffix when several findings of one type share an identity.
2391 /// Line and column are not inputs, so the id survives line shifts,
2392 /// reformats and reorders. A rename of the file or the symbol gives a
2393 /// new id. Absent in output from older versions.
2394 #[serde(default, skip_serializing_if = "Option::is_none")]
2395 pub finding_id: Option<String>,
2396 /// Suggested next steps. Always emitted (possibly empty for
2397 /// forward-compat).
2398 pub actions: Vec<IssueAction>,
2399 /// Set by the audit pass when this finding is introduced relative to
2400 /// the merge-base.
2401 #[serde(default, skip_serializing_if = "Option::is_none")]
2402 pub introduced: Option<AuditIntroduced>,
2403 /// Rule severity of this finding. Explicit errors enforce analysis gates;
2404 /// warnings stay advisory, including under strict flags. Saved reports
2405 /// retain this value for CI levels without the original config. Absent
2406 /// in output from older versions. Not part of finding identity, baseline
2407 /// keys or fingerprints.
2408 #[serde(
2409 default,
2410 skip_serializing_if = "Option::is_none",
2411 deserialize_with = "deserialize_effective_severity"
2412 )]
2413 pub effective_severity: Option<EffectiveSeverity>,
2414}
2415
2416impl DuplicatePropShapeFinding {
2417 /// Build the wrapper from a raw [`DuplicatePropShape`]. Manual guidance is
2418 /// the primary action (extract a shared shape); a line-level suppress at the
2419 /// component definition and a file-level suppress escape hatch follow,
2420 /// mirroring the multi-file route-collision suppress model. There is no safe
2421 /// auto-fix because extracting a shared type or base component is a design
2422 /// decision.
2423 #[must_use]
2424 pub fn with_actions(shape: DuplicatePropShape) -> Self {
2425 let actions = vec![
2426 IssueAction::SuppressLine(SuppressLineAction {
2427 kind: SuppressLineKind::SuppressLine,
2428 auto_fixable: false,
2429 description: "Three or more components share this exact prop shape. Extract one \
2430 shared `Props` type (or a base component) that every member reuses, \
2431 or keep them separate if a per-variant divergence is planned. \
2432 Suppress one member with an inline comment above the component \
2433 definition."
2434 .to_string(),
2435 comment: "// fallow-ignore-next-line duplicate-prop-shape".to_string(),
2436 scope: None,
2437 }),
2438 IssueAction::SuppressFile(SuppressFileAction {
2439 kind: SuppressFileKind::SuppressFile,
2440 auto_fixable: false,
2441 description: "Escape hatch: a file-level suppress silences this member but it \
2442 still appears in its siblings' `sharing_components` (the group is \
2443 real regardless of suppression)."
2444 .to_string(),
2445 comment: "// fallow-ignore-file duplicate-prop-shape".to_string(),
2446 }),
2447 ];
2448 Self {
2449 finding_id: None,
2450 shape,
2451 actions,
2452 introduced: None,
2453 effective_severity: None,
2454 }
2455 }
2456}
2457
2458/// Wire-shape envelope for an [`UnusedComponentInput`] finding. There is no safe
2459/// auto-fix: removing a declared input is judgement-bearing (the input may be
2460/// part of a deliberately-stable public component API). The only action is a
2461/// line-level suppress at the input declaration.
2462#[derive(Debug, Clone, Serialize, Deserialize)]
2463#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2464pub struct UnusedComponentInputFinding {
2465 /// The underlying finding.
2466 #[serde(flatten)]
2467 pub input: UnusedComponentInput,
2468 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2469 /// `~<k>` suffix when several findings of one type share an identity.
2470 /// Line and column are not inputs, so the id survives line shifts,
2471 /// reformats and reorders. A rename of the file or the symbol gives a
2472 /// new id. Absent in output from older versions.
2473 #[serde(default, skip_serializing_if = "Option::is_none")]
2474 pub finding_id: Option<String>,
2475 /// Suggested next steps. Always emitted (possibly empty for
2476 /// forward-compat).
2477 pub actions: Vec<IssueAction>,
2478 /// Set by the audit pass when this finding is introduced relative to
2479 /// the merge-base.
2480 #[serde(default, skip_serializing_if = "Option::is_none")]
2481 pub introduced: Option<AuditIntroduced>,
2482 /// Gate severity of this finding after `rules` and `overrides[].rules`
2483 /// resolve for its path. CI formats read it for the annotation, SARIF
2484 /// and CodeClimate level. Absent in output from older versions. Not
2485 /// part of the finding identity, baseline keys or fingerprints.
2486 #[serde(
2487 default,
2488 skip_serializing_if = "Option::is_none",
2489 deserialize_with = "deserialize_effective_severity"
2490 )]
2491 pub effective_severity: Option<EffectiveSeverity>,
2492}
2493
2494impl UnusedComponentInputFinding {
2495 /// Build the wrapper from a raw [`UnusedComponentInput`]. Emits only a
2496 /// line-level suppress action: there is no safe auto-fix because removing an
2497 /// input is a human decision (it may be part of a stable component API).
2498 #[must_use]
2499 pub fn with_actions(input: UnusedComponentInput) -> Self {
2500 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
2501 kind: SuppressLineKind::SuppressLine,
2502 auto_fixable: false,
2503 description: "Suppress with an inline comment above the line".to_string(),
2504 comment: "// fallow-ignore-next-line unused-component-input".to_string(),
2505 scope: None,
2506 })];
2507 Self {
2508 finding_id: None,
2509 input,
2510 actions,
2511 introduced: None,
2512 effective_severity: None,
2513 }
2514 }
2515}
2516
2517/// Wire-shape envelope for an [`UnusedComponentOutput`] finding. There is no safe
2518/// auto-fix: removing a declared output is judgement-bearing (the event may be
2519/// part of a deliberately-stable public component API). The only action is a
2520/// line-level suppress at the output declaration.
2521#[derive(Debug, Clone, Serialize, Deserialize)]
2522#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2523pub struct UnusedComponentOutputFinding {
2524 /// The underlying finding.
2525 #[serde(flatten)]
2526 pub output: UnusedComponentOutput,
2527 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2528 /// `~<k>` suffix when several findings of one type share an identity.
2529 /// Line and column are not inputs, so the id survives line shifts,
2530 /// reformats and reorders. A rename of the file or the symbol gives a
2531 /// new id. Absent in output from older versions.
2532 #[serde(default, skip_serializing_if = "Option::is_none")]
2533 pub finding_id: Option<String>,
2534 /// Suggested next steps. Always emitted (possibly empty for
2535 /// forward-compat).
2536 pub actions: Vec<IssueAction>,
2537 /// Set by the audit pass when this finding is introduced relative to
2538 /// the merge-base.
2539 #[serde(default, skip_serializing_if = "Option::is_none")]
2540 pub introduced: Option<AuditIntroduced>,
2541 /// Gate severity of this finding after `rules` and `overrides[].rules`
2542 /// resolve for its path. CI formats read it for the annotation, SARIF
2543 /// and CodeClimate level. Absent in output from older versions. Not
2544 /// part of the finding identity, baseline keys or fingerprints.
2545 #[serde(
2546 default,
2547 skip_serializing_if = "Option::is_none",
2548 deserialize_with = "deserialize_effective_severity"
2549 )]
2550 pub effective_severity: Option<EffectiveSeverity>,
2551}
2552
2553impl UnusedComponentOutputFinding {
2554 /// Build the wrapper from a raw [`UnusedComponentOutput`]. Emits only a
2555 /// line-level suppress action: there is no safe auto-fix because removing an
2556 /// output is a human decision (it may be part of a stable component API).
2557 #[must_use]
2558 pub fn with_actions(output: UnusedComponentOutput) -> Self {
2559 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
2560 kind: SuppressLineKind::SuppressLine,
2561 auto_fixable: false,
2562 description: "Suppress with an inline comment above the line".to_string(),
2563 comment: "// fallow-ignore-next-line unused-component-output".to_string(),
2564 scope: None,
2565 })];
2566 Self {
2567 finding_id: None,
2568 output,
2569 actions,
2570 introduced: None,
2571 effective_severity: None,
2572 }
2573 }
2574}
2575
2576/// Wire-shape envelope for a [`RouteCollision`] finding. A route collision is a
2577/// guaranteed `next build` failure, so the primary action is manual guidance
2578/// (move or merge one of the colliding files), NOT a suppress: suppressing a
2579/// build error never makes the build pass. A file-level suppress is offered as
2580/// an escape hatch only.
2581#[derive(Debug, Clone, Serialize, Deserialize)]
2582#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2583pub struct RouteCollisionFinding {
2584 /// The underlying route-collision entry.
2585 #[serde(flatten)]
2586 pub collision: RouteCollision,
2587 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2588 /// `~<k>` suffix when several findings of one type share an identity.
2589 /// Line and column are not inputs, so the id survives line shifts,
2590 /// reformats and reorders. A rename of the file or the symbol gives a
2591 /// new id. Absent in output from older versions.
2592 #[serde(default, skip_serializing_if = "Option::is_none")]
2593 pub finding_id: Option<String>,
2594 /// Suggested next steps. Always emitted (possibly empty for
2595 /// forward-compat).
2596 pub actions: Vec<IssueAction>,
2597 /// Set by the audit pass when this finding is introduced relative to
2598 /// the merge-base.
2599 #[serde(default, skip_serializing_if = "Option::is_none")]
2600 pub introduced: Option<AuditIntroduced>,
2601 /// Gate severity of this finding after `rules` and `overrides[].rules`
2602 /// resolve for its path. CI formats read it for the annotation, SARIF
2603 /// and CodeClimate level. Absent in output from older versions. Not
2604 /// part of the finding identity, baseline keys or fingerprints.
2605 #[serde(
2606 default,
2607 skip_serializing_if = "Option::is_none",
2608 deserialize_with = "deserialize_effective_severity"
2609 )]
2610 pub effective_severity: Option<EffectiveSeverity>,
2611}
2612
2613impl RouteCollisionFinding {
2614 /// Build the wrapper from a raw [`RouteCollision`]. The primary action is
2615 /// manual guidance because suppressing a guaranteed build error is never
2616 /// the right fix; a file-level suppress is the escape hatch only.
2617 #[must_use]
2618 pub fn with_actions(collision: RouteCollision) -> Self {
2619 let actions = vec![
2620 IssueAction::Fix(FixAction {
2621 kind: FixActionType::ResolveRouteCollision,
2622 auto_fixable: false,
2623 description: "Two or more files resolve to the same URL. Move or merge one so \
2624 each URL has a single owner. Route groups `(name)` and parallel \
2625 slots `@name` are the only legal same-URL shapes."
2626 .to_string(),
2627 note: Some(
2628 "Next.js fails the build with \"You cannot have two parallel pages that \
2629 resolve to the same path\". See the sibling `conflicting_paths` array for \
2630 the other files that own this URL."
2631 .to_string(),
2632 ),
2633 available_in_catalogs: None,
2634 suggested_target: None,
2635 }),
2636 IssueAction::SuppressFile(SuppressFileAction {
2637 kind: SuppressFileKind::SuppressFile,
2638 auto_fixable: false,
2639 description: "Escape hatch only: a file-level suppress silences the finding but \
2640 does NOT make `next build` pass. Prefer moving or merging a file."
2641 .to_string(),
2642 comment: "// fallow-ignore-file route-collision".to_string(),
2643 }),
2644 ];
2645 Self {
2646 finding_id: None,
2647 collision,
2648 actions,
2649 introduced: None,
2650 effective_severity: None,
2651 }
2652 }
2653}
2654
2655/// Wire-shape envelope for a [`DynamicSegmentNameConflict`] finding. The
2656/// conflict is a Next.js dev / runtime error (`next build` does NOT catch it),
2657/// so the primary action is manual guidance (rename the dynamic segments to a
2658/// single consistent slug name), with a file-level suppress as escape hatch.
2659#[derive(Debug, Clone, Serialize, Deserialize)]
2660#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2661pub struct DynamicSegmentNameConflictFinding {
2662 /// The underlying dynamic-segment-name-conflict entry.
2663 #[serde(flatten)]
2664 pub conflict: DynamicSegmentNameConflict,
2665 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2666 /// `~<k>` suffix when several findings of one type share an identity.
2667 /// Line and column are not inputs, so the id survives line shifts,
2668 /// reformats and reorders. A rename of the file or the symbol gives a
2669 /// new id. Absent in output from older versions.
2670 #[serde(default, skip_serializing_if = "Option::is_none")]
2671 pub finding_id: Option<String>,
2672 /// Suggested next steps. Always emitted (possibly empty for
2673 /// forward-compat).
2674 pub actions: Vec<IssueAction>,
2675 /// Set by the audit pass when this finding is introduced relative to
2676 /// the merge-base.
2677 #[serde(default, skip_serializing_if = "Option::is_none")]
2678 pub introduced: Option<AuditIntroduced>,
2679 /// Gate severity of this finding after `rules` and `overrides[].rules`
2680 /// resolve for its path. CI formats read it for the annotation, SARIF
2681 /// and CodeClimate level. Absent in output from older versions. Not
2682 /// part of the finding identity, baseline keys or fingerprints.
2683 #[serde(
2684 default,
2685 skip_serializing_if = "Option::is_none",
2686 deserialize_with = "deserialize_effective_severity"
2687 )]
2688 pub effective_severity: Option<EffectiveSeverity>,
2689}
2690
2691impl DynamicSegmentNameConflictFinding {
2692 /// Build the wrapper from a raw [`DynamicSegmentNameConflict`]. Manual
2693 /// guidance primary action; file-level suppress escape hatch only.
2694 #[must_use]
2695 pub fn with_actions(conflict: DynamicSegmentNameConflict) -> Self {
2696 let actions = vec![
2697 IssueAction::Fix(FixAction {
2698 kind: FixActionType::ResolveDynamicSegmentNameConflict,
2699 auto_fixable: false,
2700 description: "Sibling dynamic segments at the same position use different param \
2701 names. Rename them to one consistent slug name (e.g. pick `[id]` \
2702 or `[slug]` for both)."
2703 .to_string(),
2704 note: Some(
2705 "Next.js throws \"You cannot use different slug names for the same dynamic \
2706 path\" at dev / runtime when the position is hit; `next build` does not \
2707 catch it. See the sibling `conflicting_segments` array."
2708 .to_string(),
2709 ),
2710 available_in_catalogs: None,
2711 suggested_target: None,
2712 }),
2713 IssueAction::SuppressFile(SuppressFileAction {
2714 kind: SuppressFileKind::SuppressFile,
2715 auto_fixable: false,
2716 description: "Escape hatch only: a file-level suppress silences the finding but \
2717 does NOT stop Next.js from throwing at dev / runtime. Prefer \
2718 renaming the segments."
2719 .to_string(),
2720 comment: "// fallow-ignore-file dynamic-segment-name-conflict".to_string(),
2721 }),
2722 ];
2723 Self {
2724 finding_id: None,
2725 conflict,
2726 actions,
2727 introduced: None,
2728 effective_severity: None,
2729 }
2730 }
2731}
2732
2733/// Wire-shape envelope for an [`UnusedMember`] finding consumed under the
2734/// `unused_enum_members` key.
2735#[derive(Debug, Clone, Serialize, Deserialize)]
2736#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2737pub struct UnusedEnumMemberFinding {
2738 /// The underlying dead-code entry.
2739 #[serde(flatten)]
2740 pub member: UnusedMember,
2741 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2742 /// `~<k>` suffix when several findings of one type share an identity.
2743 /// Line and column are not inputs, so the id survives line shifts,
2744 /// reformats and reorders. A rename of the file or the symbol gives a
2745 /// new id. Absent in output from older versions.
2746 #[serde(default, skip_serializing_if = "Option::is_none")]
2747 pub finding_id: Option<String>,
2748 /// Suggested next steps. Always emitted (possibly empty for
2749 /// forward-compat).
2750 pub actions: Vec<IssueAction>,
2751 /// Set by the audit pass when this finding is introduced relative to
2752 /// the merge-base.
2753 #[serde(default, skip_serializing_if = "Option::is_none")]
2754 pub introduced: Option<AuditIntroduced>,
2755 /// Gate severity of this finding after `rules` and `overrides[].rules`
2756 /// resolve for its path. CI formats read it for the annotation, SARIF
2757 /// and CodeClimate level. Absent in output from older versions. Not
2758 /// part of the finding identity, baseline keys or fingerprints.
2759 #[serde(
2760 default,
2761 skip_serializing_if = "Option::is_none",
2762 deserialize_with = "deserialize_effective_severity"
2763 )]
2764 pub effective_severity: Option<EffectiveSeverity>,
2765 /// Advisory caveats on the verdict behind this finding. A member's usage
2766 /// is collected by walking the member accesses of every module the run
2767 /// parsed, so a member whose only reference lives in a file the run never
2768 /// read reads as unused exactly like an export does. Sorted,
2769 /// deduplicated, and omitted from the wire when empty. Never gates the
2770 /// finding; it does withhold the `remove-enum-member` mutation.
2771 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2772 pub reachability_caveats: Vec<ReachabilityCaveat>,
2773}
2774
2775impl UnusedEnumMemberFinding {
2776 /// Build the wrapper from a raw [`UnusedMember`].
2777 #[must_use]
2778 pub fn with_actions(member: UnusedMember) -> Self {
2779 let actions = vec![
2780 IssueAction::Fix(FixAction {
2781 kind: FixActionType::RemoveEnumMember,
2782 auto_fixable: true,
2783 description: "Remove this enum member".to_string(),
2784 note: None,
2785 available_in_catalogs: None,
2786 suggested_target: None,
2787 }),
2788 IssueAction::SuppressLine(SuppressLineAction {
2789 kind: SuppressLineKind::SuppressLine,
2790 auto_fixable: false,
2791 description: "Suppress with an inline comment above the line".to_string(),
2792 comment: "// fallow-ignore-next-line unused-enum-member".to_string(),
2793 scope: None,
2794 }),
2795 ];
2796 Self {
2797 finding_id: None,
2798 member,
2799 actions,
2800 introduced: None,
2801 effective_severity: None,
2802 reachability_caveats: Vec::new(),
2803 }
2804 }
2805}
2806
2807/// Wire-shape envelope for an [`UnusedMember`] finding consumed under the
2808/// `unused_class_members` key. Same Rust struct as
2809/// [`UnusedEnumMemberFinding`]; the fix action and suppress comment carry
2810/// the class-member kebab-case identifier instead.
2811#[derive(Debug, Clone, Serialize, Deserialize)]
2812#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2813pub struct UnusedClassMemberFinding {
2814 /// The underlying dead-code entry.
2815 #[serde(flatten)]
2816 pub member: UnusedMember,
2817 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2818 /// `~<k>` suffix when several findings of one type share an identity.
2819 /// Line and column are not inputs, so the id survives line shifts,
2820 /// reformats and reorders. A rename of the file or the symbol gives a
2821 /// new id. Absent in output from older versions.
2822 #[serde(default, skip_serializing_if = "Option::is_none")]
2823 pub finding_id: Option<String>,
2824 /// Suggested next steps. Always emitted (possibly empty for
2825 /// forward-compat).
2826 pub actions: Vec<IssueAction>,
2827 /// Type-aware evidence for this exact candidate when requested.
2828 #[serde(default, skip_serializing_if = "Option::is_none")]
2829 pub semantic: Option<SemanticCandidateDecision>,
2830 /// Internal marker for a framework member that the syntactic analysis
2831 /// suppresses, but the semantic pass may promote after proving complete
2832 /// closed-world absence. Never serialized as part of the public finding.
2833 #[serde(skip)]
2834 #[cfg_attr(feature = "schema", schemars(skip))]
2835 pub semantic_only_candidate: bool,
2836 /// Set by the audit pass when this finding is introduced relative to
2837 /// the merge-base.
2838 #[serde(default, skip_serializing_if = "Option::is_none")]
2839 pub introduced: Option<AuditIntroduced>,
2840 /// Gate severity of this finding after `rules` and `overrides[].rules`
2841 /// resolve for its path. CI formats read it for the annotation, SARIF
2842 /// and CodeClimate level. Absent in output from older versions. Not
2843 /// part of the finding identity, baseline keys or fingerprints.
2844 #[serde(
2845 default,
2846 skip_serializing_if = "Option::is_none",
2847 deserialize_with = "deserialize_effective_severity"
2848 )]
2849 pub effective_severity: Option<EffectiveSeverity>,
2850 /// Advisory caveats on the verdict behind this finding. A class member's
2851 /// usage is collected by the same reachability-free member-access walk an
2852 /// enum member's is, so it takes the enum-member rule unchanged: any module
2853 /// this run analyzed incompletely can hold the access that credits it.
2854 /// Sorted, deduplicated, and omitted from the wire when empty. Never gates
2855 /// the finding; it does withhold the `remove-class-member` mutation that
2856 /// the type-aware pass would otherwise open.
2857 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2858 pub reachability_caveats: Vec<ReachabilityCaveat>,
2859}
2860
2861impl UnusedClassMemberFinding {
2862 /// Build the wrapper from a raw [`UnusedMember`]. Class-member fixes
2863 /// are not auto-applied (members can be used via dependency injection
2864 /// or decorators), so `auto_fixable` is `false` and a context note is
2865 /// attached.
2866 #[must_use]
2867 pub fn with_actions(member: UnusedMember) -> Self {
2868 let actions = vec![
2869 IssueAction::Fix(FixAction {
2870 kind: FixActionType::RemoveClassMember,
2871 auto_fixable: false,
2872 description: "Remove this class member".to_string(),
2873 note: Some(
2874 "Class member may be used via dependency injection or decorators".to_string(),
2875 ),
2876 available_in_catalogs: None,
2877 suggested_target: None,
2878 }),
2879 IssueAction::SuppressLine(SuppressLineAction {
2880 kind: SuppressLineKind::SuppressLine,
2881 auto_fixable: false,
2882 description: "Suppress with an inline comment above the line".to_string(),
2883 comment: "// fallow-ignore-next-line unused-class-member".to_string(),
2884 scope: None,
2885 }),
2886 ];
2887 Self {
2888 finding_id: None,
2889 member,
2890 actions,
2891 semantic: None,
2892 semantic_only_candidate: false,
2893 introduced: None,
2894 effective_severity: None,
2895 reachability_caveats: Vec::new(),
2896 }
2897 }
2898
2899 /// Mark this finding as latent until semantic analysis proves that the
2900 /// framework contract does not apply and no static references exist.
2901 #[must_use]
2902 pub const fn semantic_only_candidate(mut self) -> Self {
2903 self.semantic_only_candidate = true;
2904 self
2905 }
2906
2907 /// Attach the canonical semantic decision and expose the class-member fix
2908 /// only when the API policy granted closed-world eligibility AND this run
2909 /// holds the evidence for the mutation.
2910 ///
2911 /// This is the one code path that RAISES `auto_fixable` on a class member,
2912 /// and it runs in the API layer AFTER the analysis layer stamped the run's
2913 /// caveats, so it asks the gate for the same reason
2914 /// `set_export_semantic_action` does: a closed-world verdict computed
2915 /// over a program the run never fully read must not re-open a removal the
2916 /// incomplete run already withheld. The withheld note names the evidence
2917 /// gap rather than the semantic explanation, which stays readable on the
2918 /// finding's own `semantic` object.
2919 pub fn set_semantic_decision(&mut self, decision: SemanticCandidateDecision) {
2920 let evidence_complete = self.reachability_caveats.is_empty();
2921 if let Some(IssueAction::Fix(action)) = self.actions.first_mut() {
2922 action.auto_fixable = decision.closed_world_eligible && evidence_complete;
2923 action.note = Some(if evidence_complete {
2924 decision.explanation.clone()
2925 } else {
2926 INCOMPLETE_EVIDENCE_NOTE.to_string()
2927 });
2928 }
2929 self.semantic = Some(decision);
2930 }
2931}
2932
2933/// Wire-shape envelope for an [`UnusedMember`] finding consumed under the
2934/// `unused_store_members` key (a Pinia `state` / `getters` / `actions` key, or
2935/// a setup-store returned key, declared but never accessed by any consumer
2936/// project-wide). Same Rust struct as [`UnusedClassMemberFinding`]. Emits only
2937/// a line-level suppress action: there is no safe auto-fix because a store
2938/// member can be accessed reflectively (a Pinia plugin, `store.$onAction`, or
2939/// dynamic dispatch) in ways syntactic analysis cannot see, so removal is a
2940/// behavioral change the user must own.
2941#[derive(Debug, Clone, Serialize, Deserialize)]
2942#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2943pub struct UnusedStoreMemberFinding {
2944 /// The underlying dead-code entry.
2945 #[serde(flatten)]
2946 pub member: UnusedMember,
2947 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
2948 /// `~<k>` suffix when several findings of one type share an identity.
2949 /// Line and column are not inputs, so the id survives line shifts,
2950 /// reformats and reorders. A rename of the file or the symbol gives a
2951 /// new id. Absent in output from older versions.
2952 #[serde(default, skip_serializing_if = "Option::is_none")]
2953 pub finding_id: Option<String>,
2954 /// Suggested next steps. Always emitted (possibly empty for
2955 /// forward-compat).
2956 pub actions: Vec<IssueAction>,
2957 /// Set by the audit pass when this finding is introduced relative to
2958 /// the merge-base.
2959 #[serde(default, skip_serializing_if = "Option::is_none")]
2960 pub introduced: Option<AuditIntroduced>,
2961 /// Gate severity of this finding after `rules` and `overrides[].rules`
2962 /// resolve for its path. CI formats read it for the annotation, SARIF
2963 /// and CodeClimate level. Absent in output from older versions. Not
2964 /// part of the finding identity, baseline keys or fingerprints.
2965 #[serde(
2966 default,
2967 skip_serializing_if = "Option::is_none",
2968 deserialize_with = "deserialize_effective_severity"
2969 )]
2970 pub effective_severity: Option<EffectiveSeverity>,
2971 /// Advisory caveats on the verdict behind this finding. A store member's
2972 /// usage is collected by the same reachability-free member-access walk a
2973 /// class member's is, so it takes the member rule unchanged: any module
2974 /// this run analyzed incompletely can hold the access that credits it.
2975 /// Sorted, deduplicated, and omitted from the wire when empty. There is no
2976 /// mutation here to withhold, because a store member offers none on any
2977 /// surface; this is disclosure only, so a reader deciding by hand is told
2978 /// what the run did not see.
2979 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2980 pub reachability_caveats: Vec<ReachabilityCaveat>,
2981}
2982
2983impl UnusedStoreMemberFinding {
2984 /// Build the wrapper from a raw [`UnusedMember`]. Emits only a line-level
2985 /// suppress action (no auto-fix: store members can be accessed
2986 /// reflectively, so removal is never provably safe).
2987 #[must_use]
2988 pub fn with_actions(member: UnusedMember) -> Self {
2989 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
2990 kind: SuppressLineKind::SuppressLine,
2991 auto_fixable: false,
2992 description: "Suppress with an inline comment above the line".to_string(),
2993 comment: "// fallow-ignore-next-line unused-store-member".to_string(),
2994 scope: None,
2995 })];
2996 Self {
2997 finding_id: None,
2998 member,
2999 actions,
3000 introduced: None,
3001 effective_severity: None,
3002 reachability_caveats: Vec::new(),
3003 }
3004 }
3005}
3006
3007/// Wire-shape envelope for an [`UnusedMember`] finding consumed under the
3008/// `unused_namespace_members` key (an exported member of an exported
3009/// TypeScript namespace that no code reads). `member_name` is the dotted path
3010/// from the exported namespace, for example `Inner.x`. Emits only a
3011/// line-level suppress action: a member can be a multi-line function, class
3012/// or nested namespace, so there is no safe one-line auto-fix.
3013#[derive(Debug, Clone, Serialize, Deserialize)]
3014#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3015pub struct UnusedNamespaceMemberFinding {
3016 /// The underlying dead-code entry.
3017 #[serde(flatten)]
3018 pub member: UnusedMember,
3019 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3020 /// `~<k>` suffix when several findings of one type share an identity.
3021 /// Line and column are not inputs, so the id survives line shifts,
3022 /// reformats and reorders. A rename of the file or the symbol gives a
3023 /// new id. Absent in output from older versions.
3024 #[serde(default, skip_serializing_if = "Option::is_none")]
3025 pub finding_id: Option<String>,
3026 /// Suggested next steps. Always emitted (possibly empty for
3027 /// forward-compat).
3028 pub actions: Vec<IssueAction>,
3029 /// Set by the audit pass when this finding is introduced relative to
3030 /// the merge-base.
3031 #[serde(default, skip_serializing_if = "Option::is_none")]
3032 pub introduced: Option<AuditIntroduced>,
3033 /// Gate severity of this finding after `rules` and `overrides[].rules`
3034 /// resolve for its path. CI formats read it for the annotation, SARIF
3035 /// and CodeClimate level. Absent in output from older versions. Not
3036 /// part of the finding identity, baseline keys or fingerprints.
3037 #[serde(
3038 default,
3039 skip_serializing_if = "Option::is_none",
3040 deserialize_with = "deserialize_effective_severity"
3041 )]
3042 pub effective_severity: Option<EffectiveSeverity>,
3043 /// Advisory caveats on the verdict behind this finding. A namespace
3044 /// member takes the member rule unchanged: any module this run analyzed
3045 /// incompletely can hold the access that credits it. Sorted,
3046 /// deduplicated, and omitted from the wire when empty. This is disclosure
3047 /// only, because a namespace member offers no mutation.
3048 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3049 pub reachability_caveats: Vec<ReachabilityCaveat>,
3050}
3051
3052impl UnusedNamespaceMemberFinding {
3053 /// Build the wrapper from a raw [`UnusedMember`]. Emits only a line-level
3054 /// suppress action.
3055 #[must_use]
3056 pub fn with_actions(member: UnusedMember) -> Self {
3057 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
3058 kind: SuppressLineKind::SuppressLine,
3059 auto_fixable: false,
3060 description: "Suppress with an inline comment above the line".to_string(),
3061 comment: "// fallow-ignore-next-line unused-namespace-member".to_string(),
3062 scope: None,
3063 })];
3064 Self {
3065 finding_id: None,
3066 member,
3067 actions,
3068 introduced: None,
3069 effective_severity: None,
3070 reachability_caveats: Vec::new(),
3071 }
3072 }
3073}
3074
3075/// Wire-shape envelope for an [`UnusedMember`] finding consumed under the
3076/// `unused_protected_class_members` key (a `protected` class method or
3077/// property that neither its class nor a subclass reads). Emits only a
3078/// line-level suppress action: a subclass outside the project can read the
3079/// member, so removal is a decision for the user.
3080#[derive(Debug, Clone, Serialize, Deserialize)]
3081#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3082pub struct UnusedProtectedClassMemberFinding {
3083 /// The underlying dead-code entry.
3084 #[serde(flatten)]
3085 pub member: UnusedMember,
3086 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3087 /// `~<k>` suffix when several findings of one type share an identity.
3088 /// Line and column are not inputs, so the id survives line shifts,
3089 /// reformats and reorders. A rename of the file or the symbol gives a
3090 /// new id. Absent in output from older versions.
3091 #[serde(default, skip_serializing_if = "Option::is_none")]
3092 pub finding_id: Option<String>,
3093 /// Suggested next steps. Always emitted (possibly empty for
3094 /// forward-compat).
3095 pub actions: Vec<IssueAction>,
3096 /// Set by the audit pass when this finding is introduced relative to
3097 /// the merge-base.
3098 #[serde(default, skip_serializing_if = "Option::is_none")]
3099 pub introduced: Option<AuditIntroduced>,
3100 /// Gate severity of this finding after `rules` and `overrides[].rules`
3101 /// resolve for its path. CI formats read it for the annotation, SARIF
3102 /// and CodeClimate level. Absent in output from older versions. Not
3103 /// part of the finding identity, baseline keys or fingerprints.
3104 #[serde(
3105 default,
3106 skip_serializing_if = "Option::is_none",
3107 deserialize_with = "deserialize_effective_severity"
3108 )]
3109 pub effective_severity: Option<EffectiveSeverity>,
3110 /// Advisory caveats on the verdict behind this finding. A protected
3111 /// member takes the member rule unchanged: any module this run analyzed
3112 /// incompletely can hold the access that credits it. Sorted,
3113 /// deduplicated, and omitted from the wire when empty. This is disclosure
3114 /// only, because a protected member offers no mutation.
3115 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3116 pub reachability_caveats: Vec<ReachabilityCaveat>,
3117}
3118
3119impl UnusedProtectedClassMemberFinding {
3120 /// Build the wrapper from a raw [`UnusedMember`]. Emits only a line-level
3121 /// suppress action.
3122 #[must_use]
3123 pub fn with_actions(member: UnusedMember) -> Self {
3124 let actions = vec![IssueAction::SuppressLine(SuppressLineAction {
3125 kind: SuppressLineKind::SuppressLine,
3126 auto_fixable: false,
3127 description: "Suppress with an inline comment above the line".to_string(),
3128 comment: "// fallow-ignore-next-line unused-protected-class-member".to_string(),
3129 scope: None,
3130 })];
3131 Self {
3132 finding_id: None,
3133 member,
3134 actions,
3135 introduced: None,
3136 effective_severity: None,
3137 reachability_caveats: Vec::new(),
3138 }
3139 }
3140}
3141
3142/// Build an `ignoreDependencies` config action for a package manifest finding.
3143fn build_ignore_dependencies_suppress_action(package_name: &str) -> IssueAction {
3144 IssueAction::AddToConfig(AddToConfigAction {
3145 kind: AddToConfigKind::AddToConfig,
3146 auto_fixable: false,
3147 description: format!("Add \"{package_name}\" to ignoreDependencies in fallow config"),
3148 config_key: "ignoreDependencies".to_string(),
3149 value: AddToConfigValue::Scalar(package_name.to_string()),
3150 value_schema: Some(
3151 "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreDependencies/items"
3152 .to_string(),
3153 ),
3154 })
3155}
3156
3157/// Wire-shape envelope for an [`UnusedDependency`] finding consumed under
3158/// the `unused_dependencies` key (production deps). Flattens the bare
3159/// finding; the typed `actions` array carries either a `remove-dependency`
3160/// or `move-dependency` primary depending on
3161/// `inner.used_in_workspaces`.
3162#[derive(Debug, Clone, Serialize, Deserialize)]
3163#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3164pub struct UnusedDependencyFinding {
3165 /// The underlying dead-code entry.
3166 #[serde(flatten)]
3167 pub dep: UnusedDependency,
3168 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3169 /// `~<k>` suffix when several findings of one type share an identity.
3170 /// Line and column are not inputs, so the id survives line shifts,
3171 /// reformats and reorders. A rename of the file or the symbol gives a
3172 /// new id. Absent in output from older versions.
3173 #[serde(default, skip_serializing_if = "Option::is_none")]
3174 pub finding_id: Option<String>,
3175 /// Suggested next steps. Always emitted (possibly empty for
3176 /// forward-compat).
3177 pub actions: Vec<IssueAction>,
3178 /// Set by the audit pass when this finding is introduced relative to
3179 /// the merge-base.
3180 #[serde(default, skip_serializing_if = "Option::is_none")]
3181 pub introduced: Option<AuditIntroduced>,
3182 /// Gate severity of this finding after `rules` and `overrides[].rules`
3183 /// resolve for its path. CI formats read it for the annotation, SARIF
3184 /// and CodeClimate level. Absent in output from older versions. Not
3185 /// part of the finding identity, baseline keys or fingerprints.
3186 #[serde(
3187 default,
3188 skip_serializing_if = "Option::is_none",
3189 deserialize_with = "deserialize_effective_severity"
3190 )]
3191 pub effective_severity: Option<EffectiveSeverity>,
3192 /// Advisory caveats on the verdict behind this finding. A dependency is
3193 /// reported unused when NO module in the project imports its specifier,
3194 /// so a module that parsed with errors can hide the import that would
3195 /// have credited the package. Sorted, deduplicated, and omitted from the
3196 /// wire when empty. Never gates the finding, though `fallow fix`
3197 /// withholds the `remove-dependency` write while a caveat stands.
3198 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3199 pub reachability_caveats: Vec<ReachabilityCaveat>,
3200}
3201
3202impl UnusedDependencyFinding {
3203 /// Build the wrapper. Switches the primary fix from `remove-dependency`
3204 /// to `move-dependency` when the dep is imported by another workspace.
3205 #[must_use]
3206 pub fn with_actions(dep: UnusedDependency) -> Self {
3207 let actions = build_unused_dependency_actions(&dep, "dependencies");
3208 Self {
3209 finding_id: None,
3210 dep,
3211 actions,
3212 introduced: None,
3213 effective_severity: None,
3214 reachability_caveats: Vec::new(),
3215 }
3216 }
3217}
3218
3219/// Wire-shape envelope for an [`UnusedDependency`] finding consumed under
3220/// the `unused_dev_dependencies` key. Same bare struct as
3221/// [`UnusedDependencyFinding`]; the fix description points at
3222/// `devDependencies` and the suppress comment uses
3223/// `unused-dev-dependency`.
3224#[derive(Debug, Clone, Serialize, Deserialize)]
3225#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3226pub struct UnusedDevDependencyFinding {
3227 /// The underlying dead-code entry.
3228 #[serde(flatten)]
3229 pub dep: UnusedDependency,
3230 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3231 /// `~<k>` suffix when several findings of one type share an identity.
3232 /// Line and column are not inputs, so the id survives line shifts,
3233 /// reformats and reorders. A rename of the file or the symbol gives a
3234 /// new id. Absent in output from older versions.
3235 #[serde(default, skip_serializing_if = "Option::is_none")]
3236 pub finding_id: Option<String>,
3237 /// Suggested next steps. Always emitted (possibly empty for
3238 /// forward-compat).
3239 pub actions: Vec<IssueAction>,
3240 /// Set by the audit pass when this finding is introduced relative to
3241 /// the merge-base.
3242 #[serde(default, skip_serializing_if = "Option::is_none")]
3243 pub introduced: Option<AuditIntroduced>,
3244 /// Gate severity of this finding after `rules` and `overrides[].rules`
3245 /// resolve for its path. CI formats read it for the annotation, SARIF
3246 /// and CodeClimate level. Absent in output from older versions. Not
3247 /// part of the finding identity, baseline keys or fingerprints.
3248 #[serde(
3249 default,
3250 skip_serializing_if = "Option::is_none",
3251 deserialize_with = "deserialize_effective_severity"
3252 )]
3253 pub effective_severity: Option<EffectiveSeverity>,
3254 /// Advisory caveats on the verdict behind this finding. A dependency is
3255 /// reported unused when NO module in the project imports its specifier,
3256 /// so a module that parsed with errors can hide the import that would
3257 /// have credited the package. Sorted, deduplicated, and omitted from the
3258 /// wire when empty. Never gates the finding, though `fallow fix`
3259 /// withholds the `remove-dependency` write while a caveat stands.
3260 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3261 pub reachability_caveats: Vec<ReachabilityCaveat>,
3262}
3263
3264impl UnusedDevDependencyFinding {
3265 /// Build the wrapper.
3266 #[must_use]
3267 pub fn with_actions(dep: UnusedDependency) -> Self {
3268 let actions = build_unused_dependency_actions(&dep, "devDependencies");
3269 Self {
3270 finding_id: None,
3271 dep,
3272 actions,
3273 introduced: None,
3274 effective_severity: None,
3275 reachability_caveats: Vec::new(),
3276 }
3277 }
3278}
3279
3280/// Wire-shape envelope for an [`UnusedDependency`] finding consumed under
3281/// the `unused_optional_dependencies` key. Same bare struct as
3282/// [`UnusedDependencyFinding`]; the fix description points at
3283/// `optionalDependencies`. Reuses the `unused-dependency` suppress
3284/// `IssueKind` because there is no dedicated variant for optional deps.
3285#[derive(Debug, Clone, Serialize, Deserialize)]
3286#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3287pub struct UnusedOptionalDependencyFinding {
3288 /// The underlying dead-code entry.
3289 #[serde(flatten)]
3290 pub dep: UnusedDependency,
3291 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3292 /// `~<k>` suffix when several findings of one type share an identity.
3293 /// Line and column are not inputs, so the id survives line shifts,
3294 /// reformats and reorders. A rename of the file or the symbol gives a
3295 /// new id. Absent in output from older versions.
3296 #[serde(default, skip_serializing_if = "Option::is_none")]
3297 pub finding_id: Option<String>,
3298 /// Suggested next steps. Always emitted (possibly empty for
3299 /// forward-compat).
3300 pub actions: Vec<IssueAction>,
3301 /// Set by the audit pass when this finding is introduced relative to
3302 /// the merge-base.
3303 #[serde(default, skip_serializing_if = "Option::is_none")]
3304 pub introduced: Option<AuditIntroduced>,
3305 /// Gate severity of this finding after `rules` and `overrides[].rules`
3306 /// resolve for its path. CI formats read it for the annotation, SARIF
3307 /// and CodeClimate level. Absent in output from older versions. Not
3308 /// part of the finding identity, baseline keys or fingerprints.
3309 #[serde(
3310 default,
3311 skip_serializing_if = "Option::is_none",
3312 deserialize_with = "deserialize_effective_severity"
3313 )]
3314 pub effective_severity: Option<EffectiveSeverity>,
3315 /// Advisory caveats on the verdict behind this finding. A dependency is
3316 /// reported unused when NO module in the project imports its specifier,
3317 /// so a module that parsed with errors can hide the import that would
3318 /// have credited the package. Sorted, deduplicated, and omitted from the
3319 /// wire when empty. Never gates the finding, though `fallow fix`
3320 /// withholds the `remove-dependency` write while a caveat stands.
3321 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3322 pub reachability_caveats: Vec<ReachabilityCaveat>,
3323}
3324
3325impl UnusedOptionalDependencyFinding {
3326 /// Build the wrapper.
3327 #[must_use]
3328 pub fn with_actions(dep: UnusedDependency) -> Self {
3329 let actions = build_unused_dependency_actions(&dep, "optionalDependencies");
3330 Self {
3331 finding_id: None,
3332 dep,
3333 actions,
3334 introduced: None,
3335 effective_severity: None,
3336 reachability_caveats: Vec::new(),
3337 }
3338 }
3339}
3340
3341/// Wire-shape envelope for an [`UnlistedDependency`] finding. Carries an
3342/// `install-dependency` primary (non-auto-fixable) plus the standard
3343/// `ignoreDependencies` config suppress.
3344#[derive(Debug, Clone, Serialize, Deserialize)]
3345#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3346pub struct UnlistedDependencyFinding {
3347 /// The underlying dead-code entry.
3348 #[serde(flatten)]
3349 pub dep: UnlistedDependency,
3350 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3351 /// `~<k>` suffix when several findings of one type share an identity.
3352 /// Line and column are not inputs, so the id survives line shifts,
3353 /// reformats and reorders. A rename of the file or the symbol gives a
3354 /// new id. Absent in output from older versions.
3355 #[serde(default, skip_serializing_if = "Option::is_none")]
3356 pub finding_id: Option<String>,
3357 /// Suggested next steps. Always emitted (possibly empty for
3358 /// forward-compat).
3359 pub actions: Vec<IssueAction>,
3360 /// Set by the audit pass when this finding is introduced relative to
3361 /// the merge-base.
3362 #[serde(default, skip_serializing_if = "Option::is_none")]
3363 pub introduced: Option<AuditIntroduced>,
3364 /// Gate severity of this finding after `rules` and `overrides[].rules`
3365 /// resolve for its path. CI formats read it for the annotation, SARIF
3366 /// and CodeClimate level. Absent in output from older versions. Not
3367 /// part of the finding identity, baseline keys or fingerprints.
3368 #[serde(
3369 default,
3370 skip_serializing_if = "Option::is_none",
3371 deserialize_with = "deserialize_effective_severity"
3372 )]
3373 pub effective_severity: Option<EffectiveSeverity>,
3374}
3375
3376impl UnlistedDependencyFinding {
3377 /// Build the wrapper.
3378 #[must_use]
3379 pub fn with_actions(dep: UnlistedDependency) -> Self {
3380 let actions = vec![
3381 IssueAction::Fix(FixAction {
3382 kind: FixActionType::InstallDependency,
3383 auto_fixable: false,
3384 description: "Add this package to dependencies in package.json".to_string(),
3385 note: Some(
3386 "Verify this package should be a direct dependency before adding".to_string(),
3387 ),
3388 available_in_catalogs: None,
3389 suggested_target: None,
3390 }),
3391 build_ignore_dependencies_suppress_action(&dep.package_name),
3392 ];
3393 Self {
3394 finding_id: None,
3395 dep,
3396 actions,
3397 introduced: None,
3398 effective_severity: None,
3399 }
3400 }
3401}
3402
3403/// Wire-shape envelope for an [`UnlistedBinary`] finding. Carries an
3404/// `install-dependency` primary (non-auto-fixable) plus an `ignoreBinaries`
3405/// config suppress.
3406#[derive(Debug, Clone, Serialize, Deserialize)]
3407#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3408pub struct UnlistedBinaryFinding {
3409 /// The underlying dead-code entry.
3410 #[serde(flatten)]
3411 pub binary: UnlistedBinary,
3412 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3413 /// `~<k>` suffix when several findings of one type share an identity.
3414 /// Line and column are not inputs, so the id survives line shifts,
3415 /// reformats and reorders. Absent in output from older versions.
3416 #[serde(default, skip_serializing_if = "Option::is_none")]
3417 pub finding_id: Option<String>,
3418 /// Suggested next steps. Always emitted (possibly empty for
3419 /// forward-compat).
3420 pub actions: Vec<IssueAction>,
3421 /// Set by the audit pass when this finding is introduced relative to
3422 /// the merge-base.
3423 #[serde(default, skip_serializing_if = "Option::is_none")]
3424 pub introduced: Option<AuditIntroduced>,
3425 /// Gate severity of this finding after `rules` and `overrides[].rules`
3426 /// resolve for its path. CI formats read it for the annotation, SARIF
3427 /// and CodeClimate level. Absent in output from older versions. Not
3428 /// part of the finding identity, baseline keys or fingerprints.
3429 #[serde(
3430 default,
3431 skip_serializing_if = "Option::is_none",
3432 deserialize_with = "deserialize_effective_severity"
3433 )]
3434 pub effective_severity: Option<EffectiveSeverity>,
3435}
3436
3437impl UnlistedBinaryFinding {
3438 /// Build the wrapper.
3439 #[must_use]
3440 pub fn with_actions(binary: UnlistedBinary) -> Self {
3441 let name = &binary.binary_name;
3442 let actions = vec![
3443 IssueAction::Fix(FixAction {
3444 kind: FixActionType::InstallDependency,
3445 auto_fixable: false,
3446 description: "Add the package that provides this binary to devDependencies"
3447 .to_string(),
3448 note: Some(
3449 "If the operating system or the CI image provides this binary, add it to ignoreBinaries instead"
3450 .to_string(),
3451 ),
3452 available_in_catalogs: None,
3453 suggested_target: None,
3454 }),
3455 IssueAction::AddToConfig(AddToConfigAction {
3456 kind: AddToConfigKind::AddToConfig,
3457 auto_fixable: false,
3458 description: format!("Add \"{name}\" to ignoreBinaries in fallow config"),
3459 config_key: "ignoreBinaries".to_string(),
3460 value: AddToConfigValue::Scalar(name.clone()),
3461 value_schema: Some(
3462 "https://raw.githubusercontent.com/fallow-rs/fallow/main/schema.json#/properties/ignoreBinaries/items"
3463 .to_string(),
3464 ),
3465 }),
3466 ];
3467 Self {
3468 finding_id: None,
3469 binary,
3470 actions,
3471 introduced: None,
3472 effective_severity: None,
3473 }
3474 }
3475}
3476
3477/// Wire-shape envelope for a [`TypeOnlyDependency`] finding. Carries a
3478/// `move-to-dev` primary plus the standard `ignoreDependencies` config
3479/// suppress.
3480#[derive(Debug, Clone, Serialize, Deserialize)]
3481#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3482pub struct TypeOnlyDependencyFinding {
3483 /// The underlying dead-code entry.
3484 #[serde(flatten)]
3485 pub dep: TypeOnlyDependency,
3486 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3487 /// `~<k>` suffix when several findings of one type share an identity.
3488 /// Line and column are not inputs, so the id survives line shifts,
3489 /// reformats and reorders. A rename of the file or the symbol gives a
3490 /// new id. Absent in output from older versions.
3491 #[serde(default, skip_serializing_if = "Option::is_none")]
3492 pub finding_id: Option<String>,
3493 /// Suggested next steps. Always emitted (possibly empty for
3494 /// forward-compat).
3495 pub actions: Vec<IssueAction>,
3496 /// Set by the audit pass when this finding is introduced relative to
3497 /// the merge-base.
3498 #[serde(default, skip_serializing_if = "Option::is_none")]
3499 pub introduced: Option<AuditIntroduced>,
3500 /// Gate severity of this finding after `rules` and `overrides[].rules`
3501 /// resolve for its path. CI formats read it for the annotation, SARIF
3502 /// and CodeClimate level. Absent in output from older versions. Not
3503 /// part of the finding identity, baseline keys or fingerprints.
3504 #[serde(
3505 default,
3506 skip_serializing_if = "Option::is_none",
3507 deserialize_with = "deserialize_effective_severity"
3508 )]
3509 pub effective_severity: Option<EffectiveSeverity>,
3510}
3511
3512impl TypeOnlyDependencyFinding {
3513 /// Build the wrapper.
3514 #[must_use]
3515 pub fn with_actions(dep: TypeOnlyDependency) -> Self {
3516 let actions = vec![
3517 IssueAction::Fix(FixAction {
3518 kind: FixActionType::MoveToDev,
3519 auto_fixable: false,
3520 description: "Move to devDependencies (only type imports are used)".to_string(),
3521 note: Some(
3522 "Type imports are erased at runtime so this dependency is not needed in production"
3523 .to_string(),
3524 ),
3525 available_in_catalogs: None,
3526 suggested_target: None,
3527 }),
3528 build_ignore_dependencies_suppress_action(&dep.package_name),
3529 ];
3530 Self {
3531 finding_id: None,
3532 dep,
3533 actions,
3534 introduced: None,
3535 effective_severity: None,
3536 }
3537 }
3538}
3539
3540/// Wire-shape envelope for a [`TestOnlyDependency`] finding. Carries a
3541/// `move-to-dev` primary (different prose than [`TypeOnlyDependencyFinding`])
3542/// plus the standard `ignoreDependencies` config suppress.
3543#[derive(Debug, Clone, Serialize, Deserialize)]
3544#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3545pub struct TestOnlyDependencyFinding {
3546 /// The underlying dead-code entry.
3547 #[serde(flatten)]
3548 pub dep: TestOnlyDependency,
3549 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3550 /// `~<k>` suffix when several findings of one type share an identity.
3551 /// Line and column are not inputs, so the id survives line shifts,
3552 /// reformats and reorders. A rename of the file or the symbol gives a
3553 /// new id. Absent in output from older versions.
3554 #[serde(default, skip_serializing_if = "Option::is_none")]
3555 pub finding_id: Option<String>,
3556 /// Suggested next steps. Always emitted (possibly empty for
3557 /// forward-compat).
3558 pub actions: Vec<IssueAction>,
3559 /// Set by the audit pass when this finding is introduced relative to
3560 /// the merge-base.
3561 #[serde(default, skip_serializing_if = "Option::is_none")]
3562 pub introduced: Option<AuditIntroduced>,
3563 /// Gate severity of this finding after `rules` and `overrides[].rules`
3564 /// resolve for its path. CI formats read it for the annotation, SARIF
3565 /// and CodeClimate level. Absent in output from older versions. Not
3566 /// part of the finding identity, baseline keys or fingerprints.
3567 #[serde(
3568 default,
3569 skip_serializing_if = "Option::is_none",
3570 deserialize_with = "deserialize_effective_severity"
3571 )]
3572 pub effective_severity: Option<EffectiveSeverity>,
3573}
3574
3575impl TestOnlyDependencyFinding {
3576 /// Build the wrapper.
3577 #[must_use]
3578 pub fn with_actions(dep: TestOnlyDependency) -> Self {
3579 let actions = vec![
3580 IssueAction::Fix(FixAction {
3581 kind: FixActionType::MoveToDev,
3582 auto_fixable: false,
3583 description: "Move to devDependencies (only test files import this)".to_string(),
3584 note: Some(
3585 "Only test files import this package so it does not need to be a production dependency"
3586 .to_string(),
3587 ),
3588 available_in_catalogs: None,
3589 suggested_target: None,
3590 }),
3591 build_ignore_dependencies_suppress_action(&dep.package_name),
3592 ];
3593 Self {
3594 finding_id: None,
3595 dep,
3596 actions,
3597 introduced: None,
3598 effective_severity: None,
3599 }
3600 }
3601}
3602
3603/// Wire-shape envelope for a [`DevDependencyInProduction`] finding. Carries a
3604/// `move-to-prod` primary (the promote-side mirror of
3605/// [`TestOnlyDependencyFinding`]'s `move-to-dev`) plus the standard
3606/// `ignoreDependencies` config suppress.
3607#[derive(Debug, Clone, Serialize, Deserialize)]
3608#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3609pub struct DevDependencyInProductionFinding {
3610 /// The underlying dead-code entry.
3611 #[serde(flatten)]
3612 pub dep: DevDependencyInProduction,
3613 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3614 /// `~<k>` suffix when several findings of one type share an identity.
3615 /// Line and column are not inputs, so the id survives line shifts,
3616 /// reformats and reorders. A rename of the file or the symbol gives a
3617 /// new id. Absent in output from older versions.
3618 #[serde(default, skip_serializing_if = "Option::is_none")]
3619 pub finding_id: Option<String>,
3620 /// Suggested next steps. Always emitted (possibly empty for
3621 /// forward-compat).
3622 pub actions: Vec<IssueAction>,
3623 /// Set by the audit pass when this finding is introduced relative to
3624 /// the merge-base.
3625 #[serde(default, skip_serializing_if = "Option::is_none")]
3626 pub introduced: Option<AuditIntroduced>,
3627 /// Gate severity of this finding after `rules` and `overrides[].rules`
3628 /// resolve for its path. CI formats read it for the annotation, SARIF
3629 /// and CodeClimate level. Absent in output from older versions. Not
3630 /// part of the finding identity, baseline keys or fingerprints.
3631 #[serde(
3632 default,
3633 skip_serializing_if = "Option::is_none",
3634 deserialize_with = "deserialize_effective_severity"
3635 )]
3636 pub effective_severity: Option<EffectiveSeverity>,
3637}
3638
3639impl DevDependencyInProductionFinding {
3640 /// Build the wrapper.
3641 #[must_use]
3642 pub fn with_actions(dep: DevDependencyInProduction) -> Self {
3643 let actions = vec![
3644 IssueAction::Fix(FixAction {
3645 kind: FixActionType::MoveToProd,
3646 auto_fixable: false,
3647 description:
3648 "Move to dependencies if the deployment installs them (production code imports this)"
3649 .to_string(),
3650 note: Some(
3651 "A production-only install (`pnpm install --prod`) omits devDependencies, so an import resolved at runtime breaks. A build that inlines the package into its output resolves nothing at runtime, and moving it there can instead make the deployment require an install it did not need"
3652 .to_string(),
3653 ),
3654 available_in_catalogs: None,
3655 suggested_target: None,
3656 }),
3657 build_ignore_dependencies_suppress_action(&dep.package_name),
3658 ];
3659 Self {
3660 finding_id: None,
3661 dep,
3662 actions,
3663 introduced: None,
3664 effective_severity: None,
3665 }
3666 }
3667}
3668
3669// ── Catalog / dep-override family ───────────────────────────────
3670//
3671// These six wrappers replace the legacy `inject_actions` post-pass in
3672// `crates/cli/src/report/json.rs` for the catalog and dependency-override
3673// findings. Each `with_actions(...)` builds the typed `actions` array
3674// directly from the inner struct (and any per-call context such as
3675// `config_fixable`), so the wire shape is identical to the pre-2.76
3676// post-pass output but the Rust compiler now owns the action contract.
3677
3678/// Wire-shape envelope for a [`DuplicateExport`] finding. Carries up to
3679/// three actions in position-locked order: an `add-to-config` `ignoreExports`
3680/// snippet (only when `locations[]` carries at least one path) followed by
3681/// the `remove-duplicate` fix and the multi-location suppress.
3682///
3683/// The `add-to-config` action sits at position 0 because the documented
3684/// primary slot points at the safe, non-destructive path: the shadcn /
3685/// Radix / bits-ui namespace-barrel case where every `index.*` reexports
3686/// the directory's neighbours. The `remove-duplicate` fix stays as the
3687/// secondary so consumers that pattern-match on `actions[0].type` for
3688/// "primary fix" never propose deletion of an intentional barrel surface.
3689#[derive(Debug, Clone, Serialize, Deserialize)]
3690#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3691pub struct DuplicateExportFinding {
3692 /// The underlying finding.
3693 #[serde(flatten)]
3694 pub export: DuplicateExport,
3695 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3696 /// `~<k>` suffix when several findings of one type share an identity.
3697 /// Line and column are not inputs, so the id survives line shifts,
3698 /// reformats and reorders. A rename of the file or the symbol gives a
3699 /// new id. Absent in output from older versions.
3700 #[serde(default, skip_serializing_if = "Option::is_none")]
3701 pub finding_id: Option<String>,
3702 /// Suggested next steps. Always emitted (possibly empty for
3703 /// forward-compat).
3704 pub actions: Vec<IssueAction>,
3705 /// Set by the audit pass when this finding is introduced relative to
3706 /// the merge-base.
3707 #[serde(default, skip_serializing_if = "Option::is_none")]
3708 pub introduced: Option<AuditIntroduced>,
3709 /// Gate severity of this finding after `rules` and `overrides[].rules`
3710 /// resolve for its path. CI formats read it for the annotation, SARIF
3711 /// and CodeClimate level. Absent in output from older versions. Not
3712 /// part of the finding identity, baseline keys or fingerprints.
3713 #[serde(
3714 default,
3715 skip_serializing_if = "Option::is_none",
3716 deserialize_with = "deserialize_effective_severity"
3717 )]
3718 pub effective_severity: Option<EffectiveSeverity>,
3719}
3720
3721impl DuplicateExportFinding {
3722 /// Build the wrapper with the `add-to-config` action's `auto_fixable`
3723 /// defaulting to `false`. The CLI's `build_json_with_config_fixable`
3724 /// path layers the actual `config_fixable` signal via
3725 /// [`Self::set_config_fixable`] right before serialization (the
3726 /// fix-applier readiness check lives in `fallow-cli::fix` and is not
3727 /// reachable from the analyzer layer where wrappers are first built).
3728 /// Embedders that build `AnalysisResults` directly and never route
3729 /// through the CLI's JSON path keep the conservative default.
3730 #[must_use]
3731 pub fn with_actions(export: DuplicateExport) -> Self {
3732 let mut actions: Vec<IssueAction> = Vec::with_capacity(3);
3733
3734 if let Some(rules) = build_duplicate_exports_ignore_rules(&export) {
3735 actions.push(IssueAction::AddToConfig(AddToConfigAction {
3736 kind: AddToConfigKind::AddToConfig,
3737 auto_fixable: false,
3738 description: "Add an ignoreExports rule so these files are excluded from duplicate-export grouping (use when this duplication is an intentional namespace-barrel API).".to_string(),
3739 config_key: "ignoreExports".to_string(),
3740 value: AddToConfigValue::ExportsRules(rules),
3741 value_schema: Some(IGNORE_EXPORTS_VALUE_SCHEMA.to_string()),
3742 }));
3743 }
3744
3745 actions.push(IssueAction::Fix(FixAction {
3746 kind: FixActionType::RemoveDuplicate,
3747 auto_fixable: false,
3748 description: "Keep one canonical export location and remove the others".to_string(),
3749 note: Some(NAMESPACE_BARREL_HINT.to_string()),
3750 available_in_catalogs: None,
3751 suggested_target: None,
3752 }));
3753
3754 actions.push(IssueAction::SuppressLine(SuppressLineAction {
3755 kind: SuppressLineKind::SuppressLine,
3756 auto_fixable: false,
3757 description: "Suppress with an inline comment above the line".to_string(),
3758 comment: "// fallow-ignore-next-line duplicate-export".to_string(),
3759 scope: Some(SuppressLineScope::PerLocation),
3760 }));
3761
3762 Self {
3763 finding_id: None,
3764 export,
3765 actions,
3766 introduced: None,
3767 effective_severity: None,
3768 }
3769 }
3770
3771 /// Update the position-0 `add-to-config` action's `auto_fixable` flag.
3772 /// Idempotent and a no-op when position 0 is not an `add-to-config`
3773 /// action (happens when the finding has no locations). Called by the
3774 /// CLI's JSON serializer with the result of
3775 /// `crate::fix::is_config_fixable` before emitting bytes.
3776 pub fn set_config_fixable(&mut self, fixable: bool) {
3777 if let Some(IssueAction::AddToConfig(action)) = self.actions.first_mut() {
3778 action.auto_fixable = fixable;
3779 }
3780 }
3781}
3782
3783/// Wire-shape envelope for an [`UnusedCatalogEntry`] finding. Per-instance
3784/// `auto_fixable` flips to `false` when `hardcoded_consumers` is non-empty or
3785/// the source is not `pnpm-workspace.yaml`.
3786#[derive(Debug, Clone, Serialize, Deserialize)]
3787#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3788pub struct UnusedCatalogEntryFinding {
3789 /// The underlying finding.
3790 #[serde(flatten)]
3791 pub entry: UnusedCatalogEntry,
3792 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3793 /// `~<k>` suffix when several findings of one type share an identity.
3794 /// Line and column are not inputs, so the id survives line shifts,
3795 /// reformats and reorders. A rename of the file or the symbol gives a
3796 /// new id. Absent in output from older versions.
3797 #[serde(default, skip_serializing_if = "Option::is_none")]
3798 pub finding_id: Option<String>,
3799 /// Suggested next steps. Always emitted.
3800 pub actions: Vec<IssueAction>,
3801 /// Set by the audit pass when this finding is introduced relative to
3802 /// the merge-base.
3803 #[serde(default, skip_serializing_if = "Option::is_none")]
3804 pub introduced: Option<AuditIntroduced>,
3805 /// Gate severity of this finding after `rules` and `overrides[].rules`
3806 /// resolve for its path. CI formats read it for the annotation, SARIF
3807 /// and CodeClimate level. Absent in output from older versions. Not
3808 /// part of the finding identity, baseline keys or fingerprints.
3809 #[serde(
3810 default,
3811 skip_serializing_if = "Option::is_none",
3812 deserialize_with = "deserialize_effective_severity"
3813 )]
3814 pub effective_severity: Option<EffectiveSeverity>,
3815}
3816
3817impl UnusedCatalogEntryFinding {
3818 /// Build the wrapper. Per-instance `auto_fixable` is `true` only when
3819 /// `hardcoded_consumers` is empty and the source is `pnpm-workspace.yaml`;
3820 /// otherwise `fallow fix` skips the entry to avoid breaking installs or
3821 /// applying YAML edits to Bun `package.json` catalogs.
3822 #[must_use]
3823 pub fn with_actions(entry: UnusedCatalogEntry) -> Self {
3824 let is_pnpm_source = is_pnpm_catalog_source(&entry.path);
3825 let auto_fixable = entry.hardcoded_consumers.is_empty() && is_pnpm_source;
3826 let note = if is_pnpm_source {
3827 Some(
3828 "If any consumer declares the same package with a hardcoded version, switch the consumer to `catalog:` before removing"
3829 .to_string(),
3830 )
3831 } else {
3832 Some(
3833 "fallow fix only edits pnpm-workspace.yaml catalog entries. Edit Bun package.json catalogs manually."
3834 .to_string(),
3835 )
3836 };
3837 let mut actions = vec![IssueAction::Fix(FixAction {
3838 kind: FixActionType::RemoveCatalogEntry,
3839 auto_fixable,
3840 description: if is_pnpm_source {
3841 "Remove the entry from pnpm-workspace.yaml".to_string()
3842 } else {
3843 "Remove the entry from the catalog source file manually".to_string()
3844 },
3845 note,
3846 available_in_catalogs: None,
3847 suggested_target: None,
3848 })];
3849 if is_pnpm_source {
3850 actions.push(IssueAction::SuppressLine(SuppressLineAction {
3851 kind: SuppressLineKind::SuppressLine,
3852 auto_fixable: false,
3853 description: "Suppress with a YAML comment above the line".to_string(),
3854 comment: "# fallow-ignore-next-line unused-catalog-entry".to_string(),
3855 scope: None,
3856 }));
3857 }
3858 Self {
3859 finding_id: None,
3860 entry,
3861 actions,
3862 introduced: None,
3863 effective_severity: None,
3864 }
3865 }
3866}
3867
3868/// Wire-shape envelope for an [`EmptyCatalogGroup`] finding. Carries a
3869/// `remove-empty-catalog-group` primary. YAML-sourced findings also include a
3870/// YAML-comment suppress action.
3871#[derive(Debug, Clone, Serialize, Deserialize)]
3872#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3873pub struct EmptyCatalogGroupFinding {
3874 /// The underlying finding.
3875 #[serde(flatten)]
3876 pub group: EmptyCatalogGroup,
3877 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3878 /// `~<k>` suffix when several findings of one type share an identity.
3879 /// Line and column are not inputs, so the id survives line shifts,
3880 /// reformats and reorders. A rename of the file or the symbol gives a
3881 /// new id. Absent in output from older versions.
3882 #[serde(default, skip_serializing_if = "Option::is_none")]
3883 pub finding_id: Option<String>,
3884 /// Suggested next steps. Always emitted.
3885 pub actions: Vec<IssueAction>,
3886 /// Set by the audit pass when this finding is introduced relative to
3887 /// the merge-base.
3888 #[serde(default, skip_serializing_if = "Option::is_none")]
3889 pub introduced: Option<AuditIntroduced>,
3890 /// Gate severity of this finding after `rules` and `overrides[].rules`
3891 /// resolve for its path. CI formats read it for the annotation, SARIF
3892 /// and CodeClimate level. Absent in output from older versions. Not
3893 /// part of the finding identity, baseline keys or fingerprints.
3894 #[serde(
3895 default,
3896 skip_serializing_if = "Option::is_none",
3897 deserialize_with = "deserialize_effective_severity"
3898 )]
3899 pub effective_severity: Option<EffectiveSeverity>,
3900}
3901
3902impl EmptyCatalogGroupFinding {
3903 /// Build the wrapper.
3904 #[must_use]
3905 pub fn with_actions(group: EmptyCatalogGroup) -> Self {
3906 let auto_fixable = is_pnpm_catalog_source(&group.path);
3907 let mut actions = vec![IssueAction::Fix(FixAction {
3908 kind: FixActionType::RemoveEmptyCatalogGroup,
3909 auto_fixable,
3910 description: if auto_fixable {
3911 "Remove the empty named catalog group from pnpm-workspace.yaml".to_string()
3912 } else {
3913 "Remove the empty named catalog group from the catalog source file manually"
3914 .to_string()
3915 },
3916 note: Some(if auto_fixable {
3917 "Only named groups under `catalogs:` are flagged; the top-level `catalog:` hook is intentionally ignored"
3918 .to_string()
3919 } else {
3920 "fallow fix only edits pnpm-workspace.yaml catalog groups. Edit Bun package.json catalogs manually."
3921 .to_string()
3922 }),
3923 available_in_catalogs: None,
3924 suggested_target: None,
3925 })];
3926 if auto_fixable {
3927 actions.push(IssueAction::SuppressLine(SuppressLineAction {
3928 kind: SuppressLineKind::SuppressLine,
3929 auto_fixable: false,
3930 description: "Suppress with a YAML comment above the line".to_string(),
3931 comment: "# fallow-ignore-next-line empty-catalog-group".to_string(),
3932 scope: None,
3933 }));
3934 }
3935 Self {
3936 finding_id: None,
3937 group,
3938 actions,
3939 introduced: None,
3940 effective_severity: None,
3941 }
3942 }
3943}
3944
3945/// Wire-shape envelope for an [`UnresolvedCatalogReference`] finding. The
3946/// primary action at position 0 discriminates on `available_in_catalogs`:
3947/// `add-catalog-entry` when the array is empty (no other catalog declares
3948/// the package), or `update-catalog-reference` when at least one
3949/// alternative exists. When exactly one alternative exists, the action
3950/// also carries `suggested_target` so deterministic agents can land the
3951/// edit without picking from a list.
3952#[derive(Debug, Clone, Serialize, Deserialize)]
3953#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3954pub struct UnresolvedCatalogReferenceFinding {
3955 /// The underlying finding.
3956 #[serde(flatten)]
3957 pub reference: UnresolvedCatalogReference,
3958 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
3959 /// `~<k>` suffix when several findings of one type share an identity.
3960 /// Line and column are not inputs, so the id survives line shifts,
3961 /// reformats and reorders. A rename of the file or the symbol gives a
3962 /// new id. Absent in output from older versions.
3963 #[serde(default, skip_serializing_if = "Option::is_none")]
3964 pub finding_id: Option<String>,
3965 /// Suggested next steps. Always emitted; position 0 is the discriminated
3966 /// primary (see struct docs).
3967 pub actions: Vec<IssueAction>,
3968 /// Set by the audit pass when this finding is introduced relative to
3969 /// the merge-base.
3970 #[serde(default, skip_serializing_if = "Option::is_none")]
3971 pub introduced: Option<AuditIntroduced>,
3972 /// Gate severity of this finding after `rules` and `overrides[].rules`
3973 /// resolve for its path. CI formats read it for the annotation, SARIF
3974 /// and CodeClimate level. Absent in output from older versions. Not
3975 /// part of the finding identity, baseline keys or fingerprints.
3976 #[serde(
3977 default,
3978 skip_serializing_if = "Option::is_none",
3979 deserialize_with = "deserialize_effective_severity"
3980 )]
3981 pub effective_severity: Option<EffectiveSeverity>,
3982}
3983
3984impl UnresolvedCatalogReferenceFinding {
3985 /// Build the wrapper. The discriminator at position 0 is the
3986 /// `add-catalog-entry` vs `update-catalog-reference` pick documented on
3987 /// the struct.
3988 #[must_use]
3989 pub fn with_actions(reference: UnresolvedCatalogReference) -> Self {
3990 // Normalize separators to forward slashes so the
3991 // `ignoreCatalogReferences.consumer` action value is portable when
3992 // pasted into a Windows-authored config. See
3993 // `build_duplicate_exports_ignore_rules` for the same pattern.
3994 let consumer_path = reference.path.to_string_lossy().replace('\\', "/");
3995 let primary = catalog_reference_primary_action(&reference);
3996 let fallback = remove_catalog_reference_action();
3997 let suppress = suppress_catalog_reference_action(&reference, consumer_path);
3998
3999 Self {
4000 finding_id: None,
4001 reference,
4002 actions: vec![primary, fallback, suppress],
4003 introduced: None,
4004 effective_severity: None,
4005 }
4006 }
4007}
4008
4009fn catalog_reference_primary_action(reference: &UnresolvedCatalogReference) -> IssueAction {
4010 if reference.available_in_catalogs.is_empty() {
4011 return IssueAction::Fix(FixAction {
4012 kind: FixActionType::AddCatalogEntry,
4013 auto_fixable: false,
4014 description: format!(
4015 "Add `{}` to the `{}` catalog in pnpm-workspace.yaml",
4016 reference.entry_name, reference.catalog_name
4017 ),
4018 note: Some(
4019 "Pin a version that satisfies the consumer's import; no other catalog declares this package today"
4020 .to_string(),
4021 ),
4022 available_in_catalogs: None,
4023 suggested_target: None,
4024 });
4025 }
4026
4027 let available = reference.available_in_catalogs.clone();
4028 let suggested_target = (available.len() == 1).then(|| available[0].clone());
4029 IssueAction::Fix(FixAction {
4030 kind: FixActionType::UpdateCatalogReference,
4031 auto_fixable: false,
4032 description: format!(
4033 "Switch the reference from `catalog:{}` to a catalog that declares `{}`",
4034 reference.catalog_name, reference.entry_name
4035 ),
4036 note: None,
4037 available_in_catalogs: Some(available),
4038 suggested_target,
4039 })
4040}
4041
4042fn remove_catalog_reference_action() -> IssueAction {
4043 IssueAction::Fix(FixAction {
4044 kind: FixActionType::RemoveCatalogReference,
4045 auto_fixable: false,
4046 description: "Remove the catalog reference and pin a hardcoded version in its place"
4047 .to_string(),
4048 note: Some(
4049 "Use only when neither another catalog declares the package nor the named catalog should grow to include it"
4050 .to_string(),
4051 ),
4052 available_in_catalogs: None,
4053 suggested_target: None,
4054 })
4055}
4056
4057fn suppress_catalog_reference_action(
4058 reference: &UnresolvedCatalogReference,
4059 consumer_path: String,
4060) -> IssueAction {
4061 let mut suppress_value = serde_json::Map::new();
4062 suppress_value.insert(
4063 "package".to_string(),
4064 serde_json::Value::String(reference.entry_name.clone()),
4065 );
4066 suppress_value.insert(
4067 "catalog".to_string(),
4068 serde_json::Value::String(reference.catalog_name.clone()),
4069 );
4070 suppress_value.insert(
4071 "consumer".to_string(),
4072 serde_json::Value::String(consumer_path),
4073 );
4074 IssueAction::AddToConfig(AddToConfigAction {
4075 kind: AddToConfigKind::AddToConfig,
4076 auto_fixable: false,
4077 description: "Suppress this reference via ignoreCatalogReferences in fallow config (use when the catalog edit is intentionally landing in a separate PR or the package is a placeholder).".to_string(),
4078 config_key: "ignoreCatalogReferences".to_string(),
4079 value: AddToConfigValue::RuleObject(suppress_value),
4080 value_schema: Some(IGNORE_CATALOG_REFERENCES_VALUE_SCHEMA.to_string()),
4081 })
4082}
4083
4084/// Wire-shape envelope for an [`UnusedDependencyOverride`] finding. Carries
4085/// a `remove-dependency-override` primary plus an `add-to-config`
4086/// `ignoreDependencyOverrides` suppress scoped to the target package and
4087/// declaration source.
4088#[derive(Debug, Clone, Serialize, Deserialize)]
4089#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
4090pub struct UnusedDependencyOverrideFinding {
4091 /// The underlying finding.
4092 #[serde(flatten)]
4093 pub entry: UnusedDependencyOverride,
4094 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
4095 /// `~<k>` suffix when several findings of one type share an identity.
4096 /// Line and column are not inputs, so the id survives line shifts,
4097 /// reformats and reorders. A rename of the file or the symbol gives a
4098 /// new id. Absent in output from older versions.
4099 #[serde(default, skip_serializing_if = "Option::is_none")]
4100 pub finding_id: Option<String>,
4101 /// Suggested next steps. Always emitted.
4102 pub actions: Vec<IssueAction>,
4103 /// Set by the audit pass when this finding is introduced relative to
4104 /// the merge-base.
4105 #[serde(default, skip_serializing_if = "Option::is_none")]
4106 pub introduced: Option<AuditIntroduced>,
4107 /// Gate severity of this finding after `rules` and `overrides[].rules`
4108 /// resolve for its path. CI formats read it for the annotation, SARIF
4109 /// and CodeClimate level. Absent in output from older versions. Not
4110 /// part of the finding identity, baseline keys or fingerprints.
4111 #[serde(
4112 default,
4113 skip_serializing_if = "Option::is_none",
4114 deserialize_with = "deserialize_effective_severity"
4115 )]
4116 pub effective_severity: Option<EffectiveSeverity>,
4117}
4118
4119impl UnusedDependencyOverrideFinding {
4120 /// Build the wrapper.
4121 #[must_use]
4122 pub fn with_actions(entry: UnusedDependencyOverride) -> Self {
4123 let mut actions: Vec<IssueAction> = Vec::with_capacity(2);
4124 actions.push(IssueAction::Fix(FixAction {
4125 kind: FixActionType::RemoveDependencyOverride,
4126 auto_fixable: false,
4127 description: "Remove the package-manager override entry from its declaration source"
4128 .to_string(),
4129 note: Some(
4130 "Conservative static check; verify against the active package manager's frozen-lockfile install before removing in case the override targets a transitive dependency (CVE-fix pattern)"
4131 .to_string(),
4132 ),
4133 available_in_catalogs: None,
4134 suggested_target: None,
4135 }));
4136
4137 if let Some(suppress) = build_ignore_dependency_overrides_suppress(
4138 Some(&entry.target_package),
4139 &entry.raw_key,
4140 entry.source,
4141 ) {
4142 actions.push(suppress);
4143 }
4144
4145 Self {
4146 finding_id: None,
4147 entry,
4148 actions,
4149 introduced: None,
4150 effective_severity: None,
4151 }
4152 }
4153}
4154
4155/// Wire-shape envelope for a [`MisconfiguredDependencyOverride`] finding.
4156/// Carries a `fix-dependency-override` primary plus the conditional
4157/// `add-to-config` `ignoreDependencyOverrides` suppress (skipped when both
4158/// `target_package` and `raw_key` are empty, since the rule matcher keys on
4159/// a non-empty package name).
4160#[derive(Debug, Clone, Serialize, Deserialize)]
4161#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
4162pub struct MisconfiguredDependencyOverrideFinding {
4163 /// The underlying finding.
4164 #[serde(flatten)]
4165 pub entry: MisconfiguredDependencyOverride,
4166 /// Stable id of this finding: `dc1:<rule>:<16 hex digits>`, with a
4167 /// `~<k>` suffix when several findings of one type share an identity.
4168 /// Line and column are not inputs, so the id survives line shifts,
4169 /// reformats and reorders. A rename of the file or the symbol gives a
4170 /// new id. Absent in output from older versions.
4171 #[serde(default, skip_serializing_if = "Option::is_none")]
4172 pub finding_id: Option<String>,
4173 /// Suggested next steps. Always emitted.
4174 pub actions: Vec<IssueAction>,
4175 /// Set by the audit pass when this finding is introduced relative to
4176 /// the merge-base.
4177 #[serde(default, skip_serializing_if = "Option::is_none")]
4178 pub introduced: Option<AuditIntroduced>,
4179 /// Gate severity of this finding after `rules` and `overrides[].rules`
4180 /// resolve for its path. CI formats read it for the annotation, SARIF
4181 /// and CodeClimate level. Absent in output from older versions. Not
4182 /// part of the finding identity, baseline keys or fingerprints.
4183 #[serde(
4184 default,
4185 skip_serializing_if = "Option::is_none",
4186 deserialize_with = "deserialize_effective_severity"
4187 )]
4188 pub effective_severity: Option<EffectiveSeverity>,
4189}
4190
4191impl MisconfiguredDependencyOverrideFinding {
4192 /// Build the wrapper. The suppress action is omitted when neither
4193 /// `target_package` (set on `EmptyValue` cases) nor `raw_key` provides a
4194 /// non-empty package name; an `ignoreDependencyOverrides` entry with
4195 /// `package: ""` would be silently ignored by the config parser.
4196 #[must_use]
4197 pub fn with_actions(entry: MisconfiguredDependencyOverride) -> Self {
4198 let mut actions: Vec<IssueAction> = Vec::with_capacity(2);
4199 actions.push(IssueAction::Fix(FixAction {
4200 kind: FixActionType::FixDependencyOverride,
4201 auto_fixable: false,
4202 description:
4203 "Fix the package-manager override key or value: invalid entries are rejected or ignored"
4204 .to_string(),
4205 note: Some(
4206 "Common shapes: bare `pkg`, scoped `@scope/pkg`, version-selector `pkg@<2`, parent-chain `parent>child`. Valid values include semver ranges, `-` (removal), `$ref` (self-ref), and `npm:alias@^1`."
4207 .to_string(),
4208 ),
4209 available_in_catalogs: None,
4210 suggested_target: None,
4211 }));
4212
4213 if let Some(suppress) = build_ignore_dependency_overrides_suppress(
4214 entry.target_package.as_deref(),
4215 &entry.raw_key,
4216 entry.source,
4217 ) {
4218 actions.push(suppress);
4219 }
4220
4221 Self {
4222 finding_id: None,
4223 entry,
4224 actions,
4225 introduced: None,
4226 effective_severity: None,
4227 }
4228 }
4229}
4230
4231/// Shared `add-to-config` `ignoreDependencyOverrides` builder for the two
4232/// override findings. Returns `None` when no non-empty package name is
4233/// available; the config parser silently drops entries with an empty
4234/// `package` field, so emitting one would be a no-op that misleads agents.
4235fn build_ignore_dependency_overrides_suppress(
4236 target_package: Option<&str>,
4237 raw_key: &str,
4238 source: DependencyOverrideSource,
4239) -> Option<IssueAction> {
4240 let package = target_package
4241 .filter(|s| !s.is_empty())
4242 .or_else(|| Some(raw_key).filter(|s| !s.is_empty()))?
4243 .to_string();
4244 let mut value = serde_json::Map::new();
4245 value.insert("package".to_string(), serde_json::Value::String(package));
4246 value.insert(
4247 "source".to_string(),
4248 serde_json::Value::String(source.as_label().to_string()),
4249 );
4250 Some(IssueAction::AddToConfig(AddToConfigAction {
4251 kind: AddToConfigKind::AddToConfig,
4252 auto_fixable: false,
4253 description: "Suppress this override finding via ignoreDependencyOverrides in fallow config (use for CVE-fix overrides that target a purely-transitive package).".to_string(),
4254 config_key: "ignoreDependencyOverrides".to_string(),
4255 value: AddToConfigValue::RuleObject(value),
4256 value_schema: Some(IGNORE_DEPENDENCY_OVERRIDES_VALUE_SCHEMA.to_string()),
4257 }))
4258}
4259
4260// ── The mutation gate, registered once ──────────────────────────
4261//
4262// Every finding whose reachability verdict a lost import edge can distort.
4263// The analysis layer stamps caveats through `set_reachability_caveats`, which
4264// enforces the gate on the finding's actions in the same call; every mutation
4265// surface reads the answer back through `may_auto_apply_mutation`.
4266impl_caveated_finding!(
4267 UnusedFileFinding,
4268 UnusedExportFinding,
4269 UnusedTypeFinding,
4270 UnusedEnumMemberFinding,
4271 UnusedClassMemberFinding,
4272 UnusedNamespaceMemberFinding,
4273 UnusedProtectedClassMemberFinding,
4274 UnusedStoreMemberFinding,
4275 UnusedDependencyFinding,
4276 UnusedDevDependencyFinding,
4277 UnusedOptionalDependencyFinding,
4278);
4279
4280/// Gate severity of one finding after rule resolution.
4281///
4282/// It is the severity that `rules` and the matching `overrides[].rules` give
4283/// the finding for its path. `--fail-on-issues` raises `warn` to `error`. A
4284/// finding whose rule is `off` is not reported, so there is no `off` value.
4285/// The type is separate from the health `severity` band, which ranks a
4286/// finding and does not gate it.
4287///
4288/// The `fallow dead-code` findings gate fails when a finding is `error`.
4289/// Other gates (regression, stale baseline) decide on their own inputs. Two
4290/// commands differ: the `fallow audit` `new-only` gate fails only on introduced
4291/// findings, so an inherited `error` finding does not fail the audit, and the
4292/// combined command (`fallow` without a subcommand) exits 0 for machine
4293/// formats unless `--fail-on-issues` or `--ci` is set.
4294///
4295/// Complexity findings carry the same type. The `complexity-cyclomatic`,
4296/// `complexity-cognitive` and `complexity-crap` rules set it, and the
4297/// `fallow health` findings gate and the audit verdict read it.
4298#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4299#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
4300#[serde(rename_all = "lowercase")]
4301pub enum EffectiveSeverity {
4302 /// The finding fails the run.
4303 Error,
4304 /// The finding is reported and does not fail the run.
4305 Warn,
4306}
4307
4308/// Read an optional [`EffectiveSeverity`] and treat an unknown value as absent.
4309///
4310/// A saved report from a newer version can carry a value this version does not
4311/// know. The renderers then use the rule-based level, as for a report without
4312/// the field, and the envelope still loads.
4313///
4314/// # Errors
4315///
4316/// Returns an error only when the input is not valid JSON-like data.
4317pub fn deserialize_effective_severity<'de, D>(
4318 deserializer: D,
4319) -> Result<Option<EffectiveSeverity>, D::Error>
4320where
4321 D: serde::Deserializer<'de>,
4322{
4323 #[derive(Deserialize)]
4324 #[serde(untagged)]
4325 enum Tolerant {
4326 Known(EffectiveSeverity),
4327 Unknown(serde::de::IgnoredAny),
4328 }
4329 Ok(match Option::<Tolerant>::deserialize(deserializer)? {
4330 Some(Tolerant::Known(severity)) => Some(severity),
4331 Some(Tolerant::Unknown(_)) | None => None,
4332 })
4333}
4334
4335/// A finding wrapper that carries an [`EffectiveSeverity`].
4336///
4337/// The analysis layer writes the value one time after rule resolution. CI
4338/// renderers read it and fall back to the rule-level severity when it is
4339/// absent, for example in a saved report from an older version.
4340pub trait GatedFinding {
4341 /// The gate severity, or `None` when no value was written.
4342 fn effective_severity(&self) -> Option<EffectiveSeverity>;
4343
4344 /// Write the gate severity.
4345 fn set_effective_severity(&mut self, severity: Option<EffectiveSeverity>);
4346}
4347
4348/// Implement [`GatedFinding`] for wrappers with an `effective_severity` field.
4349macro_rules! impl_gated_finding {
4350 ($($finding:ty),+ $(,)?) => {
4351 $(
4352 impl GatedFinding for $finding {
4353 fn effective_severity(&self) -> Option<EffectiveSeverity> {
4354 self.effective_severity
4355 }
4356
4357 fn set_effective_severity(&mut self, severity: Option<EffectiveSeverity>) {
4358 self.effective_severity = severity;
4359 }
4360 }
4361 )+
4362 };
4363}
4364
4365impl_gated_finding!(
4366 UnusedFileFinding,
4367 PrivateTypeLeakFinding,
4368 DeprecatedExportInUseFinding,
4369 UnresolvedImportFinding,
4370 CircularDependencyFinding,
4371 ReExportCycleFinding,
4372 PackageCycleFinding,
4373 BoundaryViolationFinding,
4374 BoundaryCoverageViolationFinding,
4375 BoundaryCallViolationFinding,
4376 UnusedExportFinding,
4377 UnusedTypeFinding,
4378 InvalidClientExportFinding,
4379 MixedClientServerBarrelFinding,
4380 MisplacedDirectiveFinding,
4381 UnprovidedInjectFinding,
4382 UnusedServerActionFinding,
4383 UnusedLoadDataKeyFinding,
4384 UnrenderedComponentFinding,
4385 UnusedComponentPropFinding,
4386 AbsentComponentPropFinding,
4387 UnusedComponentEmitFinding,
4388 UnusedSvelteEventFinding,
4389 UnusedEffectLayerFinding,
4390 UnusedTaggedErrorFinding,
4391 UnproducedCatchTagFinding,
4392 UnusedComponentInputFinding,
4393 UnusedComponentOutputFinding,
4394 RouteCollisionFinding,
4395 DynamicSegmentNameConflictFinding,
4396 UnusedEnumMemberFinding,
4397 UnusedClassMemberFinding,
4398 UnusedNamespaceMemberFinding,
4399 UnusedProtectedClassMemberFinding,
4400 UnusedStoreMemberFinding,
4401 UnusedDependencyFinding,
4402 UnusedDevDependencyFinding,
4403 UnusedOptionalDependencyFinding,
4404 UnlistedDependencyFinding,
4405 UnlistedBinaryFinding,
4406 TypeOnlyDependencyFinding,
4407 TestOnlyDependencyFinding,
4408 DevDependencyInProductionFinding,
4409 DuplicateExportFinding,
4410 DuplicateExportAliasFinding,
4411 UnusedCatalogEntryFinding,
4412 EmptyCatalogGroupFinding,
4413 UnresolvedCatalogReferenceFinding,
4414 UnusedDependencyOverrideFinding,
4415 MisconfiguredDependencyOverrideFinding,
4416 PropDrillingChainFinding,
4417 ThinWrapperFinding,
4418 DuplicatePropShapeFinding,
4419 crate::results::StaleSuppression,
4420);
4421
4422#[path = "output_dead_code_re_export_cycle.rs"]
4423mod output_dead_code_re_export_cycle;
4424pub use output_dead_code_re_export_cycle::ReExportCycleFinding;
4425
4426#[path = "output_dead_code_namespace_escape.rs"]
4427mod output_dead_code_namespace_escape;
4428pub use output_dead_code_namespace_escape::NamespaceEscapeFinding;
4429
4430#[path = "output_dead_code_actions.rs"]
4431mod output_dead_code_actions;
4432use output_dead_code_actions::{
4433 build_duplicate_exports_ignore_rules, build_unused_dependency_actions,
4434};
4435
4436#[cfg(test)]
4437#[path = "output_dead_code_caveat_tokens.rs"]
4438mod caveat_tokens;
4439
4440/// A caveated finding must expose no automatic fix. An uncaveated finding keeps its actions.
4441/// The annotation pass requires an implementation of `CaveatedFinding`.
4442/// The tests also cover finding types that can expose automatic fixes.
4443#[cfg(test)]
4444#[path = "output_dead_code_mutation_gate.rs"]
4445mod mutation_gate;
4446
4447// These tests pin the primary action at actions[0] for consumers that read it.
4448#[cfg(test)]
4449#[path = "output_dead_code_position_0_invariants.rs"]
4450mod position_0_invariants;