use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use crate::extract::{
MemberKind, SecurityControlKind, SecurityUrlShape, SkippedSecurityCalleeExpressionKind,
SkippedSecurityCalleeReason,
};
use crate::output::{
FixAction, FixActionType, IssueAction, SuppressLineAction, SuppressLineKind, SuppressLineScope,
};
use crate::output_dead_code::{
AbsentComponentPropFinding, BoundaryCallViolationFinding, BoundaryCoverageViolationFinding,
BoundaryViolationFinding, CircularDependencyFinding, DeprecatedExportInUseFinding,
DevDependencyInProductionFinding, DuplicateExportAliasFinding, DuplicateExportFinding,
DuplicatePropShapeFinding, DynamicSegmentNameConflictFinding, EmptyCatalogGroupFinding,
InvalidClientExportFinding, MisconfiguredDependencyOverrideFinding, MisplacedDirectiveFinding,
MixedClientServerBarrelFinding, PackageCycleFinding, PolicyViolationFinding,
PrivateTypeLeakFinding, PropDrillingChainFinding, ReExportCycleFinding, RouteCollisionFinding,
TestOnlyDependencyFinding, ThinWrapperFinding, TypeOnlyDependencyFinding,
UnlistedBinaryFinding, UnlistedDependencyFinding, UnprovidedInjectFinding,
UnrenderedComponentFinding, UnresolvedCatalogReferenceFinding, UnresolvedImportFinding,
UnusedCatalogEntryFinding, UnusedClassMemberFinding, UnusedComponentEmitFinding,
UnusedComponentInputFinding, UnusedComponentOutputFinding, UnusedComponentPropFinding,
UnusedDependencyFinding, UnusedDependencyOverrideFinding, UnusedDevDependencyFinding,
UnusedEnumMemberFinding, UnusedExportFinding, UnusedFileFinding, UnusedLoadDataKeyFinding,
UnusedNamespaceMemberFinding, UnusedOptionalDependencyFinding, UnusedServerActionFinding,
UnusedStoreMemberFinding, UnusedSvelteEventFinding, UnusedTypeFinding,
};
pub use crate::output_dead_code::{
UnproducedCatchTagFinding, UnusedEffectLayerFinding, UnusedTaggedErrorFinding,
};
#[path = "results_component_health.rs"]
mod component_health;
pub use component_health::ERROR_ONLY_RESULT_KEYS;
use crate::serde_path;
use crate::suppress::closest_known_kind_name;
#[path = "results_ignore_findings.rs"]
mod ignore_findings;
use ignore_findings::classify_ignore_findings_fields;
#[path = "results_merge_parts.rs"]
mod merge_parts;
use merge_parts::split_merge_parts;
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct EntryPointSummary {
pub total: usize,
pub by_source: Vec<(String, usize)>,
}
#[derive(Debug, Clone, Default)]
pub struct RenderFanInMetric {
pub per_component: Vec<RenderFanInComponent>,
pub p95_distinct_parents: Option<u32>,
pub high_pct: Option<f64>,
pub max_distinct_parents: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct RenderFanInComponent {
pub file: PathBuf,
pub component: String,
pub render_sites: u32,
pub distinct_parents: u32,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ReactHookSummary {
pub state: u16,
pub effect: u16,
pub memo: u16,
pub callback: u16,
pub custom: u16,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReactPropDrill {
pub depth: u32,
pub hops: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReactPropIntel {
pub name: String,
pub anchor_line: u32,
pub anchor_col: u32,
pub used_in_body: bool,
pub passed_from_sites: u32,
pub drill: Option<ReactPropDrill>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReactComponentIntel {
pub path: PathBuf,
pub component_name: String,
pub anchor_line: u32,
pub anchor_col: u32,
pub render_sites: u32,
pub distinct_parents: u32,
pub prop_count: u16,
pub hooks: ReactHookSummary,
pub props: Vec<ReactPropIntel>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct AnalysisResults {
pub unused_files: Vec<UnusedFileFinding>,
pub unused_exports: Vec<UnusedExportFinding>,
pub unused_types: Vec<UnusedTypeFinding>,
pub private_type_leaks: Vec<PrivateTypeLeakFinding>,
#[serde(default)]
pub deprecated_exports_in_use: Vec<DeprecatedExportInUseFinding>,
pub unused_dependencies: Vec<UnusedDependencyFinding>,
pub unused_dev_dependencies: Vec<UnusedDevDependencyFinding>,
pub unused_optional_dependencies: Vec<UnusedOptionalDependencyFinding>,
pub unused_enum_members: Vec<UnusedEnumMemberFinding>,
pub unused_class_members: Vec<UnusedClassMemberFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_namespace_members: Vec<UnusedNamespaceMemberFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_store_members: Vec<UnusedStoreMemberFinding>,
pub unresolved_imports: Vec<UnresolvedImportFinding>,
pub unlisted_dependencies: Vec<UnlistedDependencyFinding>,
#[serde(default)]
pub unlisted_binaries: Vec<UnlistedBinaryFinding>,
pub duplicate_exports: Vec<DuplicateExportFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub duplicate_export_aliases: Vec<DuplicateExportAliasFinding>,
pub type_only_dependencies: Vec<TypeOnlyDependencyFinding>,
#[serde(default)]
pub test_only_dependencies: Vec<TestOnlyDependencyFinding>,
#[serde(default)]
pub dev_dependencies_in_production: Vec<DevDependencyInProductionFinding>,
pub circular_dependencies: Vec<CircularDependencyFinding>,
#[serde(default)]
pub re_export_cycles: Vec<ReExportCycleFinding>,
#[serde(default)]
pub package_cycles: Vec<PackageCycleFinding>,
#[serde(default)]
pub boundary_violations: Vec<BoundaryViolationFinding>,
#[serde(default)]
pub boundary_coverage_violations: Vec<BoundaryCoverageViolationFinding>,
#[serde(default)]
pub boundary_call_violations: Vec<BoundaryCallViolationFinding>,
#[serde(default)]
pub policy_violations: Vec<PolicyViolationFinding>,
#[serde(default)]
pub stale_suppressions: Vec<StaleSuppression>,
#[serde(default)]
pub unused_catalog_entries: Vec<UnusedCatalogEntryFinding>,
#[serde(default)]
pub empty_catalog_groups: Vec<EmptyCatalogGroupFinding>,
#[serde(default)]
pub unresolved_catalog_references: Vec<UnresolvedCatalogReferenceFinding>,
#[serde(default)]
pub unused_dependency_overrides: Vec<UnusedDependencyOverrideFinding>,
#[serde(default)]
pub misconfigured_dependency_overrides: Vec<MisconfiguredDependencyOverrideFinding>,
#[serde(default)]
pub invalid_client_exports: Vec<InvalidClientExportFinding>,
#[serde(default)]
pub mixed_client_server_barrels: Vec<MixedClientServerBarrelFinding>,
#[serde(default)]
pub misplaced_directives: Vec<MisplacedDirectiveFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unprovided_injects: Vec<UnprovidedInjectFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unrendered_components: Vec<UnrenderedComponentFinding>,
#[serde(default)]
pub route_collisions: Vec<RouteCollisionFinding>,
#[serde(default)]
pub dynamic_segment_name_conflicts: Vec<DynamicSegmentNameConflictFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_component_props: Vec<UnusedComponentPropFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub absent_component_props: Vec<AbsentComponentPropFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_component_emits: Vec<UnusedComponentEmitFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_component_inputs: Vec<UnusedComponentInputFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_component_outputs: Vec<UnusedComponentOutputFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_svelte_events: Vec<UnusedSvelteEventFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_effect_layers: Vec<UnusedEffectLayerFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_tagged_errors: Vec<UnusedTaggedErrorFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unproduced_catch_tags: Vec<UnproducedCatchTagFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_server_actions: Vec<UnusedServerActionFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub unused_load_data_keys: Vec<UnusedLoadDataKeyFinding>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub unused_load_data_keys_global_abstain: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub prop_drilling_chains: Vec<PropDrillingChainFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub thin_wrappers: Vec<ThinWrapperFinding>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub duplicate_prop_shapes: Vec<DuplicatePropShapeFinding>,
#[serde(default, skip_serializing_if = "is_zero")]
pub cascade_hidden: usize,
#[serde(skip)]
#[cfg_attr(feature = "schema", schemars(skip))]
pub cascade: CascadeState,
#[serde(skip)]
pub suppression_count: usize,
#[serde(skip)]
pub unused_component_props_exempted: usize,
#[serde(skip)]
pub active_suppressions: Vec<ActiveSuppression>,
#[serde(skip)]
pub feature_flags: Vec<FeatureFlag>,
#[serde(skip)]
pub security_findings: Vec<SecurityFinding>,
#[serde(skip)]
pub security_unresolved_edge_files: usize,
#[serde(skip)]
pub security_unresolved_callee_sites: usize,
#[serde(skip)]
pub security_unresolved_callee_diagnostics: Vec<SecurityUnresolvedCalleeDiagnostic>,
#[serde(skip)]
pub export_usages: Vec<ExportUsage>,
#[serde(skip)]
pub entry_point_summary: Option<EntryPointSummary>,
#[serde(skip)]
pub render_fan_in: Option<RenderFanInMetric>,
#[serde(skip)]
pub react_component_intel: Vec<ReactComponentIntel>,
#[serde(skip)]
#[cfg_attr(feature = "schema", schemars(skip))]
pub semantic_reachable_files: rustc_hash::FxHashSet<PathBuf>,
#[serde(skip)]
#[cfg_attr(feature = "schema", schemars(skip))]
pub semantic_framework_contracts: Vec<crate::semantic::SemanticFrameworkContract>,
}
#[expect(
clippy::trivially_copy_pass_by_ref,
reason = "serde `skip_serializing_if` passes the field by reference"
)]
const fn is_zero(count: &usize) -> bool {
*count == 0
}
#[derive(Debug, Default, Clone)]
pub struct CascadeState {
pub suppressed_unused_files: Vec<PathBuf>,
pub hidden: CascadeHiddenFindings,
}
#[derive(Debug, Default, Clone)]
pub struct CascadeHiddenFindings {
pub unused_exports: Vec<UnusedExportFinding>,
pub unused_types: Vec<UnusedTypeFinding>,
pub unused_enum_members: Vec<UnusedEnumMemberFinding>,
pub unused_class_members: Vec<UnusedClassMemberFinding>,
}
impl CascadeHiddenFindings {
#[must_use]
pub fn len(&self) -> usize {
self.unused_exports.len()
+ self.unused_types.len()
+ self.unused_enum_members.len()
+ self.unused_class_members.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
#[must_use]
pub fn to_results(&self) -> AnalysisResults {
AnalysisResults {
unused_exports: self.unused_exports.clone(),
unused_types: self.unused_types.clone(),
unused_enum_members: self.unused_enum_members.clone(),
unused_class_members: self.unused_class_members.clone(),
..AnalysisResults::default()
}
}
fn extend(&mut self, other: Self) {
self.unused_exports.extend(other.unused_exports);
self.unused_types.extend(other.unused_types);
self.unused_enum_members.extend(other.unused_enum_members);
self.unused_class_members.extend(other.unused_class_members);
}
}
fn move_covered<T>(
findings: &mut Vec<T>,
hidden: &mut Vec<T>,
path_of: impl Fn(&T) -> &Path,
covered: &dyn Fn(&Path) -> bool,
) {
let (moved, kept): (Vec<T>, Vec<T>) = std::mem::take(findings)
.into_iter()
.partition(|finding| covered(path_of(finding)));
*findings = kept;
hidden.extend(moved);
}
struct AnalysisResultsCoreMergeParts {
unused_files: Vec<UnusedFileFinding>,
unused_exports: Vec<UnusedExportFinding>,
unused_types: Vec<UnusedTypeFinding>,
private_type_leaks: Vec<PrivateTypeLeakFinding>,
deprecated_exports_in_use: Vec<DeprecatedExportInUseFinding>,
unused_enum_members: Vec<UnusedEnumMemberFinding>,
unused_class_members: Vec<UnusedClassMemberFinding>,
unused_namespace_members: Vec<UnusedNamespaceMemberFinding>,
unused_store_members: Vec<UnusedStoreMemberFinding>,
unresolved_imports: Vec<UnresolvedImportFinding>,
boundary_violations: Vec<BoundaryViolationFinding>,
boundary_coverage_violations: Vec<BoundaryCoverageViolationFinding>,
boundary_call_violations: Vec<BoundaryCallViolationFinding>,
policy_violations: Vec<PolicyViolationFinding>,
stale_suppressions: Vec<StaleSuppression>,
}
struct AnalysisResultsGraphMergeParts {
unused_dependencies: Vec<UnusedDependencyFinding>,
unused_dev_dependencies: Vec<UnusedDevDependencyFinding>,
unused_optional_dependencies: Vec<UnusedOptionalDependencyFinding>,
unlisted_dependencies: Vec<UnlistedDependencyFinding>,
unlisted_binaries: Vec<UnlistedBinaryFinding>,
duplicate_exports: Vec<DuplicateExportFinding>,
duplicate_export_aliases: Vec<DuplicateExportAliasFinding>,
type_only_dependencies: Vec<TypeOnlyDependencyFinding>,
test_only_dependencies: Vec<TestOnlyDependencyFinding>,
dev_dependencies_in_production: Vec<DevDependencyInProductionFinding>,
circular_dependencies: Vec<CircularDependencyFinding>,
re_export_cycles: Vec<ReExportCycleFinding>,
package_cycles: Vec<PackageCycleFinding>,
}
struct AnalysisResultsWorkspaceMergeParts {
unused_catalog_entries: Vec<UnusedCatalogEntryFinding>,
empty_catalog_groups: Vec<EmptyCatalogGroupFinding>,
unresolved_catalog_references: Vec<UnresolvedCatalogReferenceFinding>,
unused_dependency_overrides: Vec<UnusedDependencyOverrideFinding>,
misconfigured_dependency_overrides: Vec<MisconfiguredDependencyOverrideFinding>,
}
struct AnalysisResultsFrameworkMergeParts {
invalid_client_exports: Vec<InvalidClientExportFinding>,
mixed_client_server_barrels: Vec<MixedClientServerBarrelFinding>,
misplaced_directives: Vec<MisplacedDirectiveFinding>,
unprovided_injects: Vec<UnprovidedInjectFinding>,
unrendered_components: Vec<UnrenderedComponentFinding>,
route_collisions: Vec<RouteCollisionFinding>,
dynamic_segment_name_conflicts: Vec<DynamicSegmentNameConflictFinding>,
unused_component_props: Vec<UnusedComponentPropFinding>,
absent_component_props: Vec<AbsentComponentPropFinding>,
unused_component_emits: Vec<UnusedComponentEmitFinding>,
unused_component_inputs: Vec<UnusedComponentInputFinding>,
unused_component_outputs: Vec<UnusedComponentOutputFinding>,
unused_svelte_events: Vec<UnusedSvelteEventFinding>,
unused_effect_layers: Vec<UnusedEffectLayerFinding>,
unused_tagged_errors: Vec<UnusedTaggedErrorFinding>,
unproduced_catch_tags: Vec<UnproducedCatchTagFinding>,
unused_server_actions: Vec<UnusedServerActionFinding>,
unused_load_data_keys: Vec<UnusedLoadDataKeyFinding>,
unused_load_data_keys_global_abstain: bool,
prop_drilling_chains: Vec<PropDrillingChainFinding>,
thin_wrappers: Vec<ThinWrapperFinding>,
duplicate_prop_shapes: Vec<DuplicatePropShapeFinding>,
}
struct AnalysisResultsMetadataMergeParts {
cascade_hidden: usize,
cascade: CascadeState,
suppression_count: usize,
unused_component_props_exempted: usize,
active_suppressions: Vec<ActiveSuppression>,
feature_flags: Vec<FeatureFlag>,
security_findings: Vec<SecurityFinding>,
security_unresolved_edge_files: usize,
security_unresolved_callee_sites: usize,
security_unresolved_callee_diagnostics: Vec<SecurityUnresolvedCalleeDiagnostic>,
export_usages: Vec<ExportUsage>,
entry_point_summary: Option<EntryPointSummary>,
render_fan_in: Option<RenderFanInMetric>,
react_component_intel: Vec<ReactComponentIntel>,
semantic_reachable_files: rustc_hash::FxHashSet<PathBuf>,
semantic_framework_contracts: Vec<crate::semantic::SemanticFrameworkContract>,
}
macro_rules! counted_analysis_result_fields {
($callback:ident $(, $arg:expr)? ) => {
$callback! {
$($arg,)?
unused_files => "unused_files",
unused_exports => "unused_exports",
unused_types => "unused_types",
private_type_leaks => "private_type_leaks",
deprecated_exports_in_use => "deprecated_exports_in_use",
unused_dependencies => "unused_dependencies",
unused_dev_dependencies => "unused_dev_dependencies",
unused_optional_dependencies => "unused_optional_dependencies",
unused_enum_members => "unused_enum_members",
unused_class_members => "unused_class_members",
unused_namespace_members => "unused_namespace_members",
unused_store_members => "unused_store_members",
unresolved_imports => "unresolved_imports",
unlisted_dependencies => "unlisted_dependencies",
unlisted_binaries => "unlisted_binaries",
duplicate_exports => "duplicate_exports",
duplicate_export_aliases => "duplicate_export_aliases",
type_only_dependencies => "type_only_dependencies",
test_only_dependencies => "test_only_dependencies",
dev_dependencies_in_production => "dev_dependencies_in_production",
circular_dependencies => "circular_dependencies",
re_export_cycles => "re_export_cycles",
package_cycles => "package_cycles",
boundary_violations => "boundary_violations",
boundary_coverage_violations => "boundary_coverage_violations",
boundary_call_violations => "boundary_call_violations",
policy_violations => "policy_violations",
stale_suppressions => "stale_suppressions",
unused_catalog_entries => "unused_catalog_entries",
empty_catalog_groups => "empty_catalog_groups",
unresolved_catalog_references => "unresolved_catalog_references",
unused_dependency_overrides => "unused_dependency_overrides",
misconfigured_dependency_overrides => "misconfigured_dependency_overrides",
invalid_client_exports => "invalid_client_exports",
mixed_client_server_barrels => "mixed_client_server_barrels",
misplaced_directives => "misplaced_directives",
unprovided_injects => "unprovided_injects",
unrendered_components => "unrendered_components",
route_collisions => "route_collisions",
dynamic_segment_name_conflicts => "dynamic_segment_name_conflicts",
unused_component_props => "unused_component_props",
absent_component_props => "absent_component_props",
unused_component_emits => "unused_component_emits",
unused_component_inputs => "unused_component_inputs",
unused_component_outputs => "unused_component_outputs",
unused_svelte_events => "unused_svelte_events",
unused_effect_layers => "unused_effect_layers",
unused_tagged_errors => "unused_tagged_errors",
unproduced_catch_tags => "unproduced_catch_tags",
unused_server_actions => "unused_server_actions",
unused_load_data_keys => "unused_load_data_keys",
}
};
}
trait FindingIgnorePolicy {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool;
}
macro_rules! impl_single_source_dead_code {
($($finding:ty => $($field:ident).+),+ $(,)?) => {
$(
impl FindingIgnorePolicy for $finding {
fn should_ignore(
&self,
predicate: &mut impl FnMut(&Path) -> bool,
) -> bool {
predicate(&self.$($field).+)
}
}
)+
};
}
impl_single_source_dead_code! {
UnusedFileFinding => file.path,
UnusedExportFinding => export.path,
UnusedTypeFinding => export.path,
PrivateTypeLeakFinding => leak.path,
DeprecatedExportInUseFinding => export.path,
UnusedEnumMemberFinding => member.path,
UnusedClassMemberFinding => member.path,
UnusedNamespaceMemberFinding => member.path,
UnusedStoreMemberFinding => member.path,
UnresolvedImportFinding => import.path,
UnprovidedInjectFinding => inject.path,
UnrenderedComponentFinding => component.path,
UnusedComponentPropFinding => prop.path,
AbsentComponentPropFinding => prop.path,
UnusedComponentEmitFinding => emit.path,
UnusedComponentInputFinding => input.path,
UnusedComponentOutputFinding => output.path,
UnusedSvelteEventFinding => event.path,
UnusedEffectLayerFinding => layer.path,
DuplicateExportAliasFinding => alias.path,
UnusedTaggedErrorFinding => error.path,
UnproducedCatchTagFinding => catch_tag.path,
UnusedServerActionFinding => action.path,
UnusedLoadDataKeyFinding => key.path,
ThinWrapperFinding => wrapper.file,
DuplicatePropShapeFinding => shape.file,
}
macro_rules! impl_never_ignored_finding {
($($finding:ty),+ $(,)?) => {
$(
impl FindingIgnorePolicy for $finding {
fn should_ignore(
&self,
_predicate: &mut impl FnMut(&Path) -> bool,
) -> bool {
false
}
}
)+
};
}
impl_never_ignored_finding! {
UnusedDependencyFinding,
UnusedDevDependencyFinding,
UnusedOptionalDependencyFinding,
TypeOnlyDependencyFinding,
TestOnlyDependencyFinding,
DevDependencyInProductionFinding,
UnusedCatalogEntryFinding,
EmptyCatalogGroupFinding,
UnresolvedCatalogReferenceFinding,
UnusedDependencyOverrideFinding,
MisconfiguredDependencyOverrideFinding,
BoundaryViolationFinding,
BoundaryCoverageViolationFinding,
BoundaryCallViolationFinding,
PolicyViolationFinding,
StaleSuppression,
InvalidClientExportFinding,
MixedClientServerBarrelFinding,
MisplacedDirectiveFinding,
RouteCollisionFinding,
DynamicSegmentNameConflictFinding,
}
fn all_nonempty_paths_match<'a>(
mut paths: impl Iterator<Item = &'a PathBuf>,
predicate: &mut impl FnMut(&Path) -> bool,
) -> bool {
let Some(first) = paths.next() else {
return false;
};
predicate(first) && paths.all(|path| predicate(path))
}
impl FindingIgnorePolicy for UnlistedDependencyFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(
self.dep.imported_from.iter().map(|site| &site.path),
predicate,
)
}
}
impl FindingIgnorePolicy for UnlistedBinaryFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(self.binary.used_in.iter().map(|site| &site.path), predicate)
}
}
impl FindingIgnorePolicy for DuplicateExportFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(
self.export.locations.iter().map(|location| &location.path),
predicate,
)
}
}
impl FindingIgnorePolicy for CircularDependencyFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(self.cycle.files.iter(), predicate)
}
}
impl FindingIgnorePolicy for ReExportCycleFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(self.cycle.files.iter(), predicate)
}
}
impl FindingIgnorePolicy for PackageCycleFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(self.cycle.edges.iter().map(|edge| &edge.path), predicate)
}
}
impl FindingIgnorePolicy for PropDrillingChainFinding {
fn should_ignore(&self, predicate: &mut impl FnMut(&Path) -> bool) -> bool {
all_nonempty_paths_match(self.chain.hops.iter().map(|hop| &hop.file), predicate)
}
}
macro_rules! uncounted_source_owned_result_fields {
($callback:ident $(, $arg:expr)? ) => {
$callback! {
$($arg,)?
prop_drilling_chains => "prop_drilling_chains",
thin_wrappers => "thin_wrappers",
duplicate_prop_shapes => "duplicate_prop_shapes",
}
};
}
macro_rules! remove_configured_ignored_findings {
($state:expr, $($field:ident => $key:literal,)+) => {{
let (results, predicate) = $state;
$(
results.$field.retain(|issue| {
!issue.should_ignore(&mut *predicate)
});
)+
}};
}
macro_rules! counted_result_key_slice {
($($field:ident => $key:literal,)+) => {
&[$($key),+, "prop_drilling_chains", "thin_wrappers", "duplicate_prop_shapes"]
};
}
macro_rules! counted_result_field_sum {
($results:expr, $($field:ident => $key:literal,)+) => {
0 $(+ ($results).$field.len())+
};
}
#[path = "results_key_findings.rs"]
mod result_key_findings;
pub const TOTAL_ISSUE_RESULT_KEYS: &[&str] =
counted_analysis_result_fields!(counted_result_key_slice);
impl AnalysisResults {
pub fn hide_cascade_findings(&mut self, covered: &dyn Fn(&Path) -> bool) {
let mut hidden = CascadeHiddenFindings::default();
move_covered(
&mut self.unused_exports,
&mut hidden.unused_exports,
|finding| finding.export.path.as_path(),
covered,
);
move_covered(
&mut self.unused_types,
&mut hidden.unused_types,
|finding| finding.export.path.as_path(),
covered,
);
move_covered(
&mut self.unused_enum_members,
&mut hidden.unused_enum_members,
|finding| finding.member.path.as_path(),
covered,
);
move_covered(
&mut self.unused_class_members,
&mut hidden.unused_class_members,
|finding| finding.member.path.as_path(),
covered,
);
self.cascade_hidden += hidden.len();
self.cascade.hidden.extend(hidden);
}
pub fn restore_cascade_findings(&mut self) {
let hidden = std::mem::take(&mut self.cascade.hidden);
self.unused_exports.extend(hidden.unused_exports);
self.unused_types.extend(hidden.unused_types);
self.unused_enum_members.extend(hidden.unused_enum_members);
self.unused_class_members
.extend(hidden.unused_class_members);
self.cascade_hidden = 0;
}
#[doc(hidden)]
pub fn remove_ignored_dead_code_findings(&mut self, mut is_ignored: impl FnMut(&Path) -> bool) {
classify_ignore_findings_fields(self);
counted_analysis_result_fields!(
remove_configured_ignored_findings,
(&mut *self, &mut is_ignored)
);
uncounted_source_owned_result_fields!(
remove_configured_ignored_findings,
(&mut *self, &mut is_ignored)
);
}
#[must_use]
pub const fn total_issues(&self) -> usize {
counted_analysis_result_fields!(counted_result_field_sum, self)
+ self.enforced_prop_drilling_count()
+ self.enforced_thin_wrapper_count()
+ self.enforced_duplicate_prop_shape_count()
}
#[must_use]
pub const fn has_issues(&self) -> bool {
self.total_issues() > 0
}
pub fn merge_into(&mut self, other: Self) {
let (core, graph, workspace, framework, metadata) = split_merge_parts(other);
self.merge_core_findings(core);
self.merge_dependency_and_graph_findings(graph);
self.merge_workspace_findings(workspace);
self.merge_framework_findings(framework);
self.merge_metadata_and_security(metadata);
}
fn merge_core_findings(&mut self, parts: AnalysisResultsCoreMergeParts) {
self.unused_files.extend(parts.unused_files);
self.unused_exports.extend(parts.unused_exports);
self.unused_types.extend(parts.unused_types);
self.private_type_leaks.extend(parts.private_type_leaks);
self.deprecated_exports_in_use
.extend(parts.deprecated_exports_in_use);
self.unused_enum_members.extend(parts.unused_enum_members);
self.unused_class_members.extend(parts.unused_class_members);
self.unused_namespace_members
.extend(parts.unused_namespace_members);
self.unused_store_members.extend(parts.unused_store_members);
self.unresolved_imports.extend(parts.unresolved_imports);
self.boundary_violations.extend(parts.boundary_violations);
self.boundary_coverage_violations
.extend(parts.boundary_coverage_violations);
self.boundary_call_violations
.extend(parts.boundary_call_violations);
self.policy_violations.extend(parts.policy_violations);
self.stale_suppressions.extend(parts.stale_suppressions);
}
fn merge_dependency_and_graph_findings(&mut self, parts: AnalysisResultsGraphMergeParts) {
self.unused_dependencies.extend(parts.unused_dependencies);
self.unused_dev_dependencies
.extend(parts.unused_dev_dependencies);
self.unused_optional_dependencies
.extend(parts.unused_optional_dependencies);
self.unlisted_dependencies
.extend(parts.unlisted_dependencies);
self.unlisted_binaries.extend(parts.unlisted_binaries);
self.duplicate_exports.extend(parts.duplicate_exports);
self.duplicate_export_aliases
.extend(parts.duplicate_export_aliases);
self.type_only_dependencies
.extend(parts.type_only_dependencies);
self.test_only_dependencies
.extend(parts.test_only_dependencies);
self.dev_dependencies_in_production
.extend(parts.dev_dependencies_in_production);
self.circular_dependencies
.extend(parts.circular_dependencies);
self.re_export_cycles.extend(parts.re_export_cycles);
self.package_cycles.extend(parts.package_cycles);
}
fn merge_workspace_findings(&mut self, parts: AnalysisResultsWorkspaceMergeParts) {
self.unused_catalog_entries
.extend(parts.unused_catalog_entries);
self.empty_catalog_groups.extend(parts.empty_catalog_groups);
self.unresolved_catalog_references
.extend(parts.unresolved_catalog_references);
self.unused_dependency_overrides
.extend(parts.unused_dependency_overrides);
self.misconfigured_dependency_overrides
.extend(parts.misconfigured_dependency_overrides);
}
fn merge_framework_findings(&mut self, parts: AnalysisResultsFrameworkMergeParts) {
self.invalid_client_exports
.extend(parts.invalid_client_exports);
self.mixed_client_server_barrels
.extend(parts.mixed_client_server_barrels);
self.misplaced_directives.extend(parts.misplaced_directives);
self.unprovided_injects.extend(parts.unprovided_injects);
self.unrendered_components
.extend(parts.unrendered_components);
self.route_collisions.extend(parts.route_collisions);
self.dynamic_segment_name_conflicts
.extend(parts.dynamic_segment_name_conflicts);
self.unused_component_props
.extend(parts.unused_component_props);
self.absent_component_props
.extend(parts.absent_component_props);
self.unused_component_emits
.extend(parts.unused_component_emits);
self.unused_component_inputs
.extend(parts.unused_component_inputs);
self.unused_component_outputs
.extend(parts.unused_component_outputs);
self.unused_svelte_events.extend(parts.unused_svelte_events);
self.unused_effect_layers.extend(parts.unused_effect_layers);
self.unused_tagged_errors.extend(parts.unused_tagged_errors);
self.unproduced_catch_tags
.extend(parts.unproduced_catch_tags);
self.unused_server_actions
.extend(parts.unused_server_actions);
self.unused_load_data_keys
.extend(parts.unused_load_data_keys);
self.unused_load_data_keys_global_abstain |= parts.unused_load_data_keys_global_abstain;
self.prop_drilling_chains.extend(parts.prop_drilling_chains);
self.thin_wrappers.extend(parts.thin_wrappers);
self.duplicate_prop_shapes
.extend(parts.duplicate_prop_shapes);
}
fn merge_metadata_and_security(&mut self, parts: AnalysisResultsMetadataMergeParts) {
self.semantic_reachable_files
.extend(parts.semantic_reachable_files);
self.feature_flags.extend(parts.feature_flags);
self.security_findings.extend(parts.security_findings);
self.security_unresolved_edge_files += parts.security_unresolved_edge_files;
self.security_unresolved_callee_sites += parts.security_unresolved_callee_sites;
self.security_unresolved_callee_diagnostics
.extend(parts.security_unresolved_callee_diagnostics);
self.export_usages.extend(parts.export_usages);
self.active_suppressions.extend(parts.active_suppressions);
self.suppression_count += parts.suppression_count;
self.cascade_hidden += parts.cascade_hidden;
self.cascade
.suppressed_unused_files
.extend(parts.cascade.suppressed_unused_files);
self.cascade.hidden.extend(parts.cascade.hidden);
self.unused_component_props_exempted += parts.unused_component_props_exempted;
if self.entry_point_summary.is_none() {
self.entry_point_summary = parts.entry_point_summary;
}
if self.render_fan_in.is_none() {
self.render_fan_in = parts.render_fan_in;
}
self.react_component_intel
.extend(parts.react_component_intel);
for contract in parts.semantic_framework_contracts {
if !self.semantic_framework_contracts.contains(&contract) {
self.semantic_framework_contracts.push(contract);
}
}
}
pub fn sort(&mut self) {
self.semantic_framework_contracts.sort();
self.sort_core_findings();
self.sort_dependency_findings();
self.sort_graph_findings();
self.sort_catalog_findings();
self.sort_metadata_findings();
self.sort_export_usages();
}
fn sort_core_findings(&mut self) {
self.sort_core_declaration_findings();
self.sort_core_member_findings();
self.sort_core_framework_findings();
self.sort_core_route_and_load_findings();
}
fn sort_core_declaration_findings(&mut self) {
self.unused_files
.sort_by(|a, b| a.file.path.cmp(&b.file.path));
self.unused_exports.sort_by(|a, b| {
a.export
.path
.cmp(&b.export.path)
.then(a.export.line.cmp(&b.export.line))
.then(a.export.export_name.cmp(&b.export.export_name))
});
self.unused_types.sort_by(|a, b| {
a.export
.path
.cmp(&b.export.path)
.then(a.export.line.cmp(&b.export.line))
.then(a.export.export_name.cmp(&b.export.export_name))
});
self.private_type_leaks.sort_by(|a, b| {
a.leak
.path
.cmp(&b.leak.path)
.then(a.leak.line.cmp(&b.leak.line))
.then(a.leak.export_name.cmp(&b.leak.export_name))
.then(a.leak.type_name.cmp(&b.leak.type_name))
});
self.deprecated_exports_in_use.sort_by(|a, b| {
a.export
.path
.cmp(&b.export.path)
.then(a.export.line.cmp(&b.export.line))
.then(a.export.export_name.cmp(&b.export.export_name))
});
self.unused_dependencies.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
self.unused_dev_dependencies.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
self.unused_optional_dependencies.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
}
fn sort_core_member_findings(&mut self) {
self.unused_enum_members.sort_by(|a, b| {
a.member
.path
.cmp(&b.member.path)
.then(a.member.line.cmp(&b.member.line))
.then(a.member.parent_name.cmp(&b.member.parent_name))
.then(a.member.member_name.cmp(&b.member.member_name))
});
self.unused_class_members.sort_by(|a, b| {
a.member
.path
.cmp(&b.member.path)
.then(a.member.line.cmp(&b.member.line))
.then(a.member.parent_name.cmp(&b.member.parent_name))
.then(a.member.member_name.cmp(&b.member.member_name))
});
self.unused_namespace_members.sort_by(|a, b| {
a.member
.path
.cmp(&b.member.path)
.then(a.member.line.cmp(&b.member.line))
.then(a.member.parent_name.cmp(&b.member.parent_name))
.then(a.member.member_name.cmp(&b.member.member_name))
});
self.unused_store_members.sort_by(|a, b| {
a.member
.path
.cmp(&b.member.path)
.then(a.member.line.cmp(&b.member.line))
.then(a.member.parent_name.cmp(&b.member.parent_name))
.then(a.member.member_name.cmp(&b.member.member_name))
});
self.unresolved_imports.sort_by(|a, b| {
a.import
.path
.cmp(&b.import.path)
.then(a.import.line.cmp(&b.import.line))
.then(a.import.col.cmp(&b.import.col))
.then(a.import.specifier.cmp(&b.import.specifier))
});
}
fn sort_core_framework_findings(&mut self) {
self.invalid_client_exports.sort_by(|a, b| {
a.export
.path
.cmp(&b.export.path)
.then(a.export.line.cmp(&b.export.line))
.then(a.export.export_name.cmp(&b.export.export_name))
});
self.mixed_client_server_barrels.sort_by(|a, b| {
a.barrel
.path
.cmp(&b.barrel.path)
.then(a.barrel.line.cmp(&b.barrel.line))
.then(a.barrel.client_origin.cmp(&b.barrel.client_origin))
.then(a.barrel.server_origin.cmp(&b.barrel.server_origin))
});
self.misplaced_directives.sort_by(|a, b| {
a.directive_site
.path
.cmp(&b.directive_site.path)
.then(a.directive_site.line.cmp(&b.directive_site.line))
.then(a.directive_site.col.cmp(&b.directive_site.col))
.then(a.directive_site.directive.cmp(&b.directive_site.directive))
});
self.unprovided_injects.sort_by(|a, b| {
a.inject
.path
.cmp(&b.inject.path)
.then(a.inject.line.cmp(&b.inject.line))
.then(a.inject.col.cmp(&b.inject.col))
.then(a.inject.key_name.cmp(&b.inject.key_name))
});
self.unrendered_components.sort_by(|a, b| {
a.component
.path
.cmp(&b.component.path)
.then(a.component.line.cmp(&b.component.line))
.then(a.component.col.cmp(&b.component.col))
.then(a.component.component_name.cmp(&b.component.component_name))
});
}
fn sort_core_route_and_load_findings(&mut self) {
self.sort_core_route_findings();
self.sort_core_component_prop_and_emit_findings();
self.sort_core_component_io_findings();
self.sort_core_server_load_findings();
}
fn sort_core_route_findings(&mut self) {
self.route_collisions.sort_by(|a, b| {
a.collision
.path
.cmp(&b.collision.path)
.then(a.collision.url.cmp(&b.collision.url))
});
self.dynamic_segment_name_conflicts.sort_by(|a, b| {
a.conflict
.path
.cmp(&b.conflict.path)
.then(a.conflict.position.cmp(&b.conflict.position))
});
}
fn sort_core_component_prop_and_emit_findings(&mut self) {
self.absent_component_props.sort_by(|a, b| {
a.prop
.path
.cmp(&b.prop.path)
.then(a.prop.line.cmp(&b.prop.line))
.then(a.prop.prop_name.cmp(&b.prop.prop_name))
});
self.unused_component_props.sort_by(|a, b| {
a.prop
.path
.cmp(&b.prop.path)
.then(a.prop.line.cmp(&b.prop.line))
.then(a.prop.prop_name.cmp(&b.prop.prop_name))
});
self.unused_component_emits.sort_by(|a, b| {
a.emit
.path
.cmp(&b.emit.path)
.then(a.emit.line.cmp(&b.emit.line))
.then(a.emit.emit_name.cmp(&b.emit.emit_name))
});
self.unused_svelte_events.sort_by(|a, b| {
a.event
.path
.cmp(&b.event.path)
.then(a.event.line.cmp(&b.event.line))
.then(a.event.event_name.cmp(&b.event.event_name))
});
self.sort_effect_findings();
}
fn sort_effect_findings(&mut self) {
self.unused_effect_layers.sort_by(|a, b| {
a.layer
.path
.cmp(&b.layer.path)
.then(a.layer.line.cmp(&b.layer.line))
.then(a.layer.name.cmp(&b.layer.name))
});
self.unused_tagged_errors.sort_by(|a, b| {
a.error
.path
.cmp(&b.error.path)
.then(a.error.line.cmp(&b.error.line))
.then(a.error.name.cmp(&b.error.name))
});
self.unproduced_catch_tags.sort_by(|a, b| {
a.catch_tag
.path
.cmp(&b.catch_tag.path)
.then(a.catch_tag.line.cmp(&b.catch_tag.line))
.then(a.catch_tag.col.cmp(&b.catch_tag.col))
.then(a.catch_tag.tag.cmp(&b.catch_tag.tag))
});
}
fn sort_core_component_io_findings(&mut self) {
self.unused_component_inputs.sort_by(|a, b| {
a.input
.path
.cmp(&b.input.path)
.then(a.input.line.cmp(&b.input.line))
.then(a.input.input_name.cmp(&b.input.input_name))
});
self.unused_component_outputs.sort_by(|a, b| {
a.output
.path
.cmp(&b.output.path)
.then(a.output.line.cmp(&b.output.line))
.then(a.output.output_name.cmp(&b.output.output_name))
});
}
fn sort_core_server_load_findings(&mut self) {
self.unused_server_actions.sort_by(|a, b| {
a.action
.path
.cmp(&b.action.path)
.then(a.action.line.cmp(&b.action.line))
.then(a.action.col.cmp(&b.action.col))
.then(a.action.action_name.cmp(&b.action.action_name))
});
self.unused_load_data_keys.sort_by(|a, b| {
a.key
.path
.cmp(&b.key.path)
.then(a.key.line.cmp(&b.key.line))
.then(a.key.col.cmp(&b.key.col))
.then(a.key.key_name.cmp(&b.key.key_name))
});
}
fn sort_prop_drilling_chains(&mut self) {
self.prop_drilling_chains.sort_by(|a, b| {
let a_src = a.chain.hops.first();
let b_src = b.chain.hops.first();
let a_file = a_src.map(|h| &h.file);
let b_file = b_src.map(|h| &h.file);
a_file
.cmp(&b_file)
.then_with(|| a_src.map(|h| h.line).cmp(&b_src.map(|h| h.line)))
.then(a.chain.prop.cmp(&b.chain.prop))
.then(a.chain.depth.cmp(&b.chain.depth))
});
}
fn sort_thin_wrappers(&mut self) {
self.thin_wrappers.sort_by(|a, b| {
a.wrapper
.file
.cmp(&b.wrapper.file)
.then(a.wrapper.line.cmp(&b.wrapper.line))
.then(a.wrapper.component.cmp(&b.wrapper.component))
});
}
fn sort_duplicate_prop_shapes(&mut self) {
self.duplicate_prop_shapes.sort_by(|a, b| {
a.shape
.shape
.cmp(&b.shape.shape)
.then(a.shape.file.cmp(&b.shape.file))
.then(a.shape.line.cmp(&b.shape.line))
.then(a.shape.component.cmp(&b.shape.component))
});
}
fn sort_dependency_findings(&mut self) {
self.unlisted_dependencies
.sort_by(|a, b| a.dep.package_name.cmp(&b.dep.package_name));
for dep in &mut self.unlisted_dependencies {
dep.dep
.imported_from
.sort_by(|a, b| a.path.cmp(&b.path).then(a.line.cmp(&b.line)));
}
self.unlisted_binaries
.sort_by(|a, b| a.binary.binary_name.cmp(&b.binary.binary_name));
for binary in &mut self.unlisted_binaries {
binary.binary.used_in.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.col.cmp(&b.col))
});
}
self.duplicate_exports
.sort_by(|a, b| a.export.export_name.cmp(&b.export.export_name));
for dup in &mut self.duplicate_exports {
dup.export
.locations
.sort_by(|a, b| a.path.cmp(&b.path).then(a.line.cmp(&b.line)));
}
self.duplicate_export_aliases.sort_by(|a, b| {
a.alias
.path
.cmp(&b.alias.path)
.then(a.alias.line.cmp(&b.alias.line))
.then(a.alias.col.cmp(&b.alias.col))
.then_with(|| a.alias.export_names.cmp(&b.alias.export_names))
});
self.type_only_dependencies.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
self.test_only_dependencies.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
self.dev_dependencies_in_production.sort_by(|a, b| {
a.dep
.path
.cmp(&b.dep.path)
.then(a.dep.line.cmp(&b.dep.line))
.then(a.dep.package_name.cmp(&b.dep.package_name))
});
}
fn sort_graph_findings(&mut self) {
self.circular_dependencies.sort_by(|a, b| {
a.cycle
.files
.cmp(&b.cycle.files)
.then(a.cycle.length.cmp(&b.cycle.length))
});
self.re_export_cycles
.sort_by(|a, b| a.cycle.files.cmp(&b.cycle.files));
self.package_cycles.sort_by(|a, b| {
a.cycle
.length
.cmp(&b.cycle.length)
.then_with(|| a.cycle.packages.cmp(&b.cycle.packages))
});
self.boundary_violations.sort_by(|a, b| {
a.violation
.from_path
.cmp(&b.violation.from_path)
.then(a.violation.line.cmp(&b.violation.line))
.then(a.violation.col.cmp(&b.violation.col))
.then(a.violation.to_path.cmp(&b.violation.to_path))
});
self.boundary_coverage_violations.sort_by(|a, b| {
a.violation
.path
.cmp(&b.violation.path)
.then(a.violation.line.cmp(&b.violation.line))
.then(a.violation.col.cmp(&b.violation.col))
});
self.boundary_call_violations.sort_by(|a, b| {
a.violation
.path
.cmp(&b.violation.path)
.then(a.violation.line.cmp(&b.violation.line))
.then(a.violation.col.cmp(&b.violation.col))
.then(a.violation.callee.cmp(&b.violation.callee))
});
self.policy_violations.sort_by(|a, b| {
a.violation
.path
.cmp(&b.violation.path)
.then(a.violation.line.cmp(&b.violation.line))
.then(a.violation.col.cmp(&b.violation.col))
.then(a.violation.rule_id.cmp(&b.violation.rule_id))
});
}
fn sort_catalog_findings(&mut self) {
self.sort_stale_suppressions();
self.sort_unused_catalog_entries();
self.sort_empty_catalog_groups();
self.sort_unresolved_catalog_references();
self.sort_unused_dependency_overrides();
}
fn sort_stale_suppressions(&mut self) {
self.stale_suppressions.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.col.cmp(&b.col))
});
}
fn sort_unused_catalog_entries(&mut self) {
self.unused_catalog_entries.sort_by(|a, b| {
a.entry
.path
.cmp(&b.entry.path)
.then_with(|| {
catalog_sort_key(&a.entry.catalog_name)
.cmp(&catalog_sort_key(&b.entry.catalog_name))
})
.then(a.entry.catalog_name.cmp(&b.entry.catalog_name))
.then(a.entry.entry_name.cmp(&b.entry.entry_name))
});
for finding in &mut self.unused_catalog_entries {
finding.entry.hardcoded_consumers.sort();
finding.entry.hardcoded_consumers.dedup();
}
}
fn sort_empty_catalog_groups(&mut self) {
self.empty_catalog_groups.sort_by(|a, b| {
a.group
.path
.cmp(&b.group.path)
.then_with(|| {
catalog_sort_key(&a.group.catalog_name)
.cmp(&catalog_sort_key(&b.group.catalog_name))
})
.then(a.group.catalog_name.cmp(&b.group.catalog_name))
.then(a.group.line.cmp(&b.group.line))
});
}
fn sort_unresolved_catalog_references(&mut self) {
self.unresolved_catalog_references.sort_by(|a, b| {
a.reference
.path
.cmp(&b.reference.path)
.then(a.reference.line.cmp(&b.reference.line))
.then_with(|| {
catalog_sort_key(&a.reference.catalog_name)
.cmp(&catalog_sort_key(&b.reference.catalog_name))
})
.then(a.reference.catalog_name.cmp(&b.reference.catalog_name))
.then(a.reference.entry_name.cmp(&b.reference.entry_name))
});
for finding in &mut self.unresolved_catalog_references {
finding.reference.available_in_catalogs.sort();
finding.reference.available_in_catalogs.dedup();
}
}
fn sort_unused_dependency_overrides(&mut self) {
self.unused_dependency_overrides.sort_by(|a, b| {
a.entry
.path
.cmp(&b.entry.path)
.then(a.entry.line.cmp(&b.entry.line))
.then(a.entry.raw_key.cmp(&b.entry.raw_key))
});
}
fn sort_metadata_findings(&mut self) {
self.sort_prop_drilling_chains();
self.sort_thin_wrappers();
self.sort_duplicate_prop_shapes();
self.misconfigured_dependency_overrides.sort_by(|a, b| {
a.entry
.path
.cmp(&b.entry.path)
.then(a.entry.line.cmp(&b.entry.line))
.then(a.entry.raw_key.cmp(&b.entry.raw_key))
});
self.feature_flags.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.flag_name.cmp(&b.flag_name))
});
self.security_unresolved_callee_diagnostics.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.col.cmp(&b.col))
.then(a.reason.cmp(&b.reason))
.then(a.expression_kind.cmp(&b.expression_kind))
});
}
fn sort_export_usages(&mut self) {
for usage in &mut self.export_usages {
usage.reference_locations.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.col.cmp(&b.col))
});
}
self.export_usages.sort_by(|a, b| {
a.path
.cmp(&b.path)
.then(a.line.cmp(&b.line))
.then(a.export_name.cmp(&b.export_name))
});
}
}
fn catalog_sort_key(name: &str) -> (u8, &str) {
if name == "default" {
(0, name)
} else {
(1, name)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedFile {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedExport {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub export_name: String,
pub is_type_only: bool,
pub line: u32,
pub col: u32,
pub span_start: u32,
pub is_re_export: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub deprecated: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deprecated_reason: Option<String>,
}
pub const DEPRECATED_CONSUMER_SAMPLE_CAP: usize = 10;
pub const DEPRECATED_REASON_MAX_CHARS: usize = 200;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum DeprecatedConsumerKind {
NamedImport,
DefaultImport,
NamespaceImport,
ReExport,
DynamicImport,
SideEffectImport,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DeprecatedExportConsumer {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub kind: DeprecatedConsumerKind,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DeprecatedExportInUse {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub export_name: String,
pub is_type_only: bool,
pub line: u32,
pub col: u32,
pub span_start: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deprecated_reason: Option<String>,
pub consumer_count: usize,
pub consumers: Vec<DeprecatedExportConsumer>,
pub public_api: bool,
}
impl DeprecatedExportInUse {
#[must_use]
pub fn description(&self) -> String {
let count = self.consumer_count;
let noun = if count == 1 { "consumer" } else { "consumers" };
let reason = self
.deprecated_reason
.as_deref()
.map_or_else(String::new, |reason| format!(": {reason}"));
format!(
"Deprecated export '{}' is still used by {count} {noun}{reason}",
self.export_name
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PrivateTypeLeak {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub export_name: String,
pub type_name: String,
pub line: u32,
pub col: u32,
pub span_start: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub semantic: Option<crate::semantic::SemanticPrivateTypeLeak>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct InvalidClientExport {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub export_name: String,
pub directive: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct MixedClientServerBarrel {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub client_origin: String,
pub server_origin: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct MisplacedDirective {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub directive: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnprovidedInject {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub key_name: String,
pub framework: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedServerAction {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub action_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedLoadDataKey {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub key_name: String,
pub line: u32,
pub col: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub route_dir: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnrenderedComponent {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub framework: String,
#[serde(
serialize_with = "serde_path::serialize_option",
skip_serializing_if = "Option::is_none"
)]
pub reachable_via: Option<PathBuf>,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedComponentProp {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub prop_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ComponentPropCallSite {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct AbsentComponentProp {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub framework: String,
pub prop_name: String,
pub line: u32,
pub col: u32,
pub has_default: bool,
pub inspected_call_sites: Vec<ComponentPropCallSite>,
pub explanation: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedComponentEmit {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub emit_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedSvelteEvent {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub event_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum EffectLayerKind {
TopLevel,
StaticMember,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedEffectLayer {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub name: String,
pub kind: EffectLayerKind,
pub line: u32,
pub col: u32,
pub dead_consumers: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct EffectCatchSite {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedTaggedError {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub name: String,
pub tag: String,
pub line: u32,
pub col: u32,
pub catch_sites: Vec<EffectCatchSite>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnproducedCatchTag {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub tag: String,
pub line: u32,
pub col: u32,
pub candidate_classes: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PropDrillHop {
#[serde(serialize_with = "serde_path::serialize")]
pub file: PathBuf,
pub line: u32,
pub component: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PropDrillingChain {
pub prop: String,
pub depth: u32,
pub hops: Vec<PropDrillHop>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ThinWrapper {
#[serde(serialize_with = "serde_path::serialize")]
pub file: PathBuf,
pub line: u32,
pub component: String,
pub child_component: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicatePropShapeMember {
#[serde(serialize_with = "serde_path::serialize")]
pub file: PathBuf,
pub line: u32,
pub component: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicatePropShape {
#[serde(serialize_with = "serde_path::serialize")]
pub file: PathBuf,
pub line: u32,
pub component: String,
pub shape: Vec<String>,
pub group_size: u32,
pub sharing_components: Vec<DuplicatePropShapeMember>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedComponentInput {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub input_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedComponentOutput {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub component_name: String,
pub output_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct RouteCollision {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub url: String,
#[serde(serialize_with = "serde_path::serialize_vec")]
pub conflicting_paths: Vec<PathBuf>,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DynamicSegmentNameConflict {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub position: String,
pub conflicting_segments: Vec<String>,
#[serde(serialize_with = "serde_path::serialize_vec")]
pub conflicting_paths: Vec<PathBuf>,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedDependency {
pub package_name: String,
pub location: DependencyLocation,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
#[serde(
default,
serialize_with = "serde_path::serialize_vec",
skip_serializing_if = "Vec::is_empty"
)]
#[cfg_attr(feature = "schema", schemars(default))]
pub used_in_workspaces: Vec<PathBuf>,
#[serde(
default,
serialize_with = "serde_path::serialize_vec",
skip_serializing_if = "Vec::is_empty"
)]
#[cfg_attr(feature = "schema", schemars(default))]
pub declared_and_imported_in: Vec<PathBuf>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum DependencyLocation {
Dependencies,
DevDependencies,
OptionalDependencies,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedMember {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub parent_name: String,
pub member_name: String,
pub kind: MemberKind,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnresolvedImport {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub specifier: String,
pub line: u32,
pub col: u32,
pub specifier_col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnlistedDependency {
pub package_name: String,
pub imported_from: Vec<ImportSite>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnlistedBinary {
pub binary_name: String,
pub used_in: Vec<BinaryUseSite>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct BinaryUseSite {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub script_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ImportSite {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicateExport {
pub export_name: String,
pub locations: Vec<DuplicateLocation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicateLocation {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicateExportAlias {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub local_name: String,
pub export_names: Vec<String>,
pub line: u32,
pub col: u32,
pub locations: Vec<DuplicateExportAliasLocation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DuplicateExportAliasLocation {
pub export_name: String,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TypeOnlyDependency {
pub package_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum SecurityFindingKind {
ClientServerLeak,
TaintedSink,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum TraceHopRole {
ClientBoundary,
UntrustedSource,
ModuleSource,
Intermediate,
SecretSource,
Sink,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TraceHop {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub role: TraceHopRole,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum TaintConfidence {
ArgLevel,
ModuleLevel,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityReachability {
pub reachable_from_entry: bool,
#[serde(default)]
pub reachable_from_untrusted_source: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub taint_confidence: Option<TaintConfidence>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub untrusted_source_hop_count: Option<u32>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub untrusted_source_trace: Vec<TraceHop>,
pub blast_radius: u32,
pub crosses_boundary: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityDeadCodeContext {
pub kind: SecurityDeadCodeKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub export_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub line: Option<u32>,
pub guidance: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum SecurityDeadCodeKind {
UnusedFile,
UnusedExport,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityUnresolvedCalleeDiagnostic {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub reason: SkippedSecurityCalleeReason,
pub expression_kind: SkippedSecurityCalleeExpressionKind,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityCandidateSink {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cwe: Option<u32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub callee: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub url_shape: Option<SecurityUrlShape>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityZoneCrossing {
pub from: String,
pub to: String,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityCandidateBoundary {
pub client_server: bool,
pub cross_module: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub architecture_zone: Option<SecurityZoneCrossing>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityNetworkContext {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub destination: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityCandidate {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_kind: Option<String>,
pub sink: SecurityCandidateSink,
pub boundary: SecurityCandidateBoundary,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub network: Option<SecurityNetworkContext>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TaintEndpoint {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TaintPath {
pub intra_module: bool,
pub cross_module_hops: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityTaintFlow {
pub source: TaintEndpoint,
pub sink: TaintEndpoint,
pub path: TaintPath,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum SecurityRuntimeState {
RuntimeHot,
RuntimeCold,
NeverExecuted,
LowTraffic,
CoverageUnavailable,
RuntimeUnknown,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityRuntimeContext {
pub state: SecurityRuntimeState,
pub function: String,
pub line: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub invocations: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stable_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub evidence: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum SecuritySeverity {
High,
Medium,
Low,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityDefensiveControl {
pub kind: SecurityControlKind,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub callee: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityDefensiveBoundary {
pub controls: Vec<SecurityDefensiveControl>,
pub verification_prompt: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityAttackSurfaceEntry {
pub source: TaintEndpoint,
pub sink: SecurityCandidateSink,
pub path: Vec<TraceHop>,
pub defensive_boundary: SecurityDefensiveBoundary,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct SecurityFinding {
pub finding_id: String,
pub kind: SecurityFindingKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cwe: Option<u32>,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub evidence: String,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub source_backed: bool,
#[serde(skip)]
pub source_read: Option<(u32, u32)>,
pub severity: SecuritySeverity,
pub trace: Vec<TraceHop>,
pub actions: Vec<IssueAction>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub dead_code: Option<SecurityDeadCodeContext>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub reachability: Option<SecurityReachability>,
pub candidate: SecurityCandidate,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub taint_flow: Option<SecurityTaintFlow>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub runtime: Option<SecurityRuntimeContext>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub attack_surface: Option<SecurityAttackSurfaceEntry>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedCatalogEntry {
pub entry_name: String,
pub catalog_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
#[serde(
default,
serialize_with = "serde_path::serialize_vec",
skip_serializing_if = "Vec::is_empty"
)]
pub hardcoded_consumers: Vec<PathBuf>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct EmptyCatalogGroup {
pub catalog_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnresolvedCatalogReference {
pub entry_name: String,
pub catalog_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub available_in_catalogs: Vec<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum DependencyOverrideSource {
#[serde(rename = "pnpm-workspace.yaml")]
PnpmWorkspaceYaml,
#[serde(rename = "package.json")]
PnpmPackageJson,
}
impl DependencyOverrideSource {
#[must_use]
pub const fn as_label(&self) -> &'static str {
match self {
Self::PnpmWorkspaceYaml => "pnpm-workspace.yaml",
Self::PnpmPackageJson => "package.json",
}
}
}
impl std::fmt::Display for DependencyOverrideSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_label())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct UnusedDependencyOverride {
pub raw_key: String,
pub target_package: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parent_package: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version_constraint: Option<String>,
pub version_range: String,
pub source: DependencyOverrideSource,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hint: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum DependencyOverrideMisconfigReason {
UnparsableKey,
EmptyValue,
}
impl DependencyOverrideMisconfigReason {
#[must_use]
pub const fn describe(self) -> &'static str {
match self {
Self::UnparsableKey => "override key cannot be parsed",
Self::EmptyValue => "override value is missing or empty",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct MisconfiguredDependencyOverride {
pub raw_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub target_package: Option<String>,
pub raw_value: String,
pub reason: DependencyOverrideMisconfigReason,
pub source: DependencyOverrideSource,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct TestOnlyDependency {
pub package_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct DevDependencyInProduction {
pub package_name: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CircularDependencyEdge {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(extend("required" = ["files", "length", "line", "col"])))]
pub struct CircularDependency {
#[serde(serialize_with = "serde_path::serialize_vec")]
pub files: Vec<PathBuf>,
pub length: usize,
#[serde(default)]
pub line: u32,
#[serde(default)]
pub col: u32,
#[serde(default)]
pub edges: Vec<CircularDependencyEdge>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub is_cross_package: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ReExportCycle {
#[serde(serialize_with = "serde_path::serialize_vec")]
pub files: Vec<PathBuf>,
pub kind: ReExportCycleKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum ReExportCycleKind {
MultiNode,
SelfLoop,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PackageCycleEdge {
pub from_package: String,
pub to_package: String,
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
#[serde(serialize_with = "serde_path::serialize")]
pub target_path: PathBuf,
pub line: u32,
pub col: u32,
pub type_only: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PackageCycle {
pub packages: Vec<String>,
#[serde(serialize_with = "serde_path::serialize_vec")]
pub package_roots: Vec<PathBuf>,
pub length: usize,
pub edges: Vec<PackageCycleEdge>,
pub group_truncated: bool,
}
impl PackageCycle {
pub const GROUP_TRUNCATED_NOTE: &'static str = "this package group has more cycles than listed";
#[must_use]
pub fn chain(&self, separator: &str) -> String {
let mut chain: Vec<&str> = self.packages.iter().map(String::as_str).collect();
if let Some(first) = chain.first().copied() {
chain.push(first);
}
chain.join(separator)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct BoundaryViolation {
#[serde(serialize_with = "serde_path::serialize")]
pub from_path: PathBuf,
#[serde(serialize_with = "serde_path::serialize")]
pub to_path: PathBuf,
pub from_zone: String,
pub to_zone: String,
pub import_specifier: String,
pub line: u32,
pub col: u32,
#[serde(
default,
serialize_with = "serde_path::serialize_option",
skip_serializing_if = "Option::is_none"
)]
pub via_path: Option<PathBuf>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct BoundaryCoverageViolation {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct BoundaryCallViolation {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub zone: String,
pub callee: String,
pub pattern: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum PolicyRuleKind {
BannedCall,
BannedImport,
BannedEffect,
BannedExport,
GdpProofProducer,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum PolicyViolationSeverity {
Error,
Warn,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PolicyViolation {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub pack: String,
pub rule_id: String,
pub kind: PolicyRuleKind,
pub matched: String,
pub severity: PolicyViolationSeverity,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum SuppressionOrigin {
Comment {
#[serde(default, skip_serializing_if = "Option::is_none")]
issue_kind: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
reason: Option<String>,
is_file_level: bool,
#[serde(default = "default_true", skip_serializing_if = "is_true")]
kind_known: bool,
},
JsdocTag {
export_name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
reason: Option<String>,
},
}
#[expect(
clippy::trivially_copy_pass_by_ref,
reason = "serde skip_serializing_if takes a reference by contract"
)]
const fn is_true(b: &bool) -> bool {
*b
}
const fn default_true() -> bool {
true
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct StaleSuppression {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
pub origin: SuppressionOrigin,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub missing_reason: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub finding_id: Option<String>,
pub actions: Vec<IssueAction>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::output_dead_code::deserialize_effective_severity"
)]
pub effective_severity: Option<crate::output_dead_code::EffectiveSeverity>,
}
impl StaleSuppression {
#[must_use]
pub fn actions_for(missing_reason: bool) -> Vec<IssueAction> {
let (kind, description) = if missing_reason {
(
FixActionType::AddSuppressionReason,
"Add a human-authored reason after `--` on the suppression",
)
} else {
(
FixActionType::RemoveStaleSuppression,
"Remove or update the stale suppression",
)
};
let mut actions = vec![IssueAction::Fix(FixAction {
kind,
auto_fixable: false,
description: description.to_string(),
note: None,
available_in_catalogs: None,
suggested_target: None,
})];
if !missing_reason {
actions.push(IssueAction::SuppressLine(SuppressLineAction {
kind: SuppressLineKind::SuppressLine,
auto_fixable: false,
description:
"Suppress this stale suppression finding with a comment above the suppression"
.to_string(),
comment: "// fallow-ignore-next-line stale-suppression".to_string(),
scope: Some(SuppressLineScope::PerLocation),
}));
}
actions
}
#[must_use]
pub fn description(&self) -> String {
match &self.origin {
SuppressionOrigin::Comment {
issue_kind,
reason,
is_file_level,
..
} => {
let directive = if *is_file_level {
"fallow-ignore-file"
} else {
"fallow-ignore-next-line"
};
match issue_kind {
Some(kind) => match reason {
Some(reason) => format!("// {directive} {kind} -- {reason}"),
None => format!("// {directive} {kind}"),
},
None => match reason {
Some(reason) => format!("// {directive} -- {reason}"),
None => format!("// {directive}"),
},
}
}
SuppressionOrigin::JsdocTag {
export_name,
reason,
} => match reason {
Some(reason) => format!("@expected-unused on {export_name} -- {reason}"),
None => format!("@expected-unused on {export_name}"),
},
}
}
#[must_use]
pub fn explanation(&self) -> String {
match &self.origin {
SuppressionOrigin::Comment {
issue_kind,
is_file_level,
kind_known,
..
} => {
if self.missing_reason {
return "suppression is missing a reason".to_string();
}
let scope = if *is_file_level {
"in this file"
} else {
"on the next line"
};
match issue_kind {
Some(kind) if !*kind_known => match closest_known_kind_name(kind) {
Some(suggestion) => format!(
"'{kind}' is not a recognized fallow issue kind. Did you mean '{suggestion}'? Other tokens on this line still apply."
),
None => format!(
"'{kind}' is not a recognized fallow issue kind. Other tokens on this line still apply."
),
},
Some(kind) => format!("no {kind} issue found {scope}"),
None => format!("no issues found {scope}"),
}
}
SuppressionOrigin::JsdocTag { export_name, .. } => {
if self.missing_reason {
return "suppression is missing a reason".to_string();
}
format!("{export_name} is now used")
}
}
}
#[must_use]
pub fn display_message(&self) -> String {
match &self.origin {
SuppressionOrigin::Comment {
kind_known: false, ..
} => format!("{} ({})", self.description(), self.explanation()),
SuppressionOrigin::Comment { .. } | SuppressionOrigin::JsdocTag { .. }
if self.missing_reason =>
{
format!("{} ({})", self.description(), self.explanation())
}
SuppressionOrigin::Comment { .. } | SuppressionOrigin::JsdocTag { .. } => {
self.description()
}
}
}
}
#[derive(Debug, Clone)]
pub struct ActiveSuppression {
pub path: PathBuf,
pub kind: Option<String>,
pub is_file_level: bool,
pub reason: Option<String>,
pub comment_line: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum FlagKind {
EnvironmentVariable,
SdkCall,
ConfigObject,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum FlagConfidence {
Low,
Medium,
High,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct FeatureFlag {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub flag_name: String,
pub kind: FlagKind,
pub confidence: FlagConfidence,
pub line: u32,
pub col: u32,
#[serde(skip)]
pub guard_span_start: Option<u32>,
#[serde(skip)]
pub guard_span_end: Option<u32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sdk_name: Option<String>,
#[serde(skip)]
pub guard_line_start: Option<u32>,
#[serde(skip)]
pub guard_line_end: Option<u32>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub guarded_dead_exports: Vec<String>,
}
const _: () = assert!(std::mem::size_of::<FeatureFlag>() <= 160);
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ExportUsage {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub export_name: String,
pub line: u32,
pub col: u32,
pub reference_count: usize,
pub reference_locations: Vec<ReferenceLocation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ReferenceLocation {
#[serde(serialize_with = "serde_path::serialize")]
pub path: PathBuf,
pub line: u32,
pub col: u32,
}
#[cfg(test)]
#[path = "results_tests.rs"]
mod tests;