fallow_types/results_policy_findings.rs
1//! Boundary coverage and call violations, and policy violations.
2
3use super::*;
4
5/// A source file that does not match any configured architecture boundary zone.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
8pub struct BoundaryCoverageViolation {
9 /// The unmatched source file.
10 #[serde(serialize_with = "serde_path::serialize")]
11 pub path: PathBuf,
12 /// 1-based line number used for diagnostics.
13 pub line: u32,
14 /// 0-based byte column offset used for diagnostics.
15 pub col: u32,
16}
17
18/// A call from a zoned file to a callee forbidden for that zone via
19/// `boundaries.calls.forbidden`. One finding is reported per call or `new`
20/// site.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
23pub struct BoundaryCallViolation {
24 /// The zoned source file making the forbidden call.
25 #[serde(serialize_with = "serde_path::serialize")]
26 pub path: PathBuf,
27 /// 1-based line number of the call site.
28 pub line: u32,
29 /// 0-based byte column offset of the call site.
30 pub col: u32,
31 /// The zone the calling file is classified into.
32 pub zone: String,
33 /// The callee path as written (e.g. `cp.exec`), with the prefix `new ` for a `new` expression.
34 pub callee: String,
35 /// The configured pattern that matched (e.g. `child_process.*`), so
36 /// consumers can see both the written path and the rule that fired.
37 pub pattern: String,
38}
39
40/// Which rule-pack rule kind produced a [`PolicyViolation`].
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
42#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
43#[serde(rename_all = "kebab-case")]
44pub enum PolicyRuleKind {
45 /// A call or `new` expression matched a `banned-call` rule's callee patterns.
46 BannedCall,
47 /// An import or re-export specifier matched a `banned-import` rule.
48 BannedImport,
49 /// A call site matched a catalogue-derived `banned-effect` rule.
50 BannedEffect,
51 /// An exported name matched a `banned-export` rule.
52 BannedExport,
53 /// A resolved gdp-ts proof factory call occurred outside allowed modules.
54 GdpProofProducer,
55}
56
57/// Effective severity of a single [`PolicyViolation`]. Per-rule `severity`
58/// overrides the `rules."policy-violation"` master; `off` rules emit nothing,
59/// so only `error` and `warn` appear on the wire. The exit-code gate inspects
60/// this per-finding value, not the master severity.
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
62#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
63#[serde(rename_all = "lowercase")]
64pub enum PolicyViolationSeverity {
65 /// Sets a non-zero exit code.
66 Error,
67 /// Reported without an effect on the exit code. The dead-code count gate
68 /// of the GitHub Action counts it unless `fail-on-issues` is `false`.
69 Warn,
70}
71
72/// A banned call, banned import, banned effect, or banned export matched by a
73/// declarative rule pack (`rulePacks` config). Banned-call and banned-effect
74/// findings report one entry per call site (`new` sites count for banned-call
75/// only), matching `boundary_call_violations`; banned-import findings anchor
76/// at each matching import or re-export declaration; banned-export findings
77/// anchor at matching export declarations.
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
80pub struct PolicyViolation {
81 /// The source file containing the banned call, import, or effectful usage.
82 #[serde(serialize_with = "serde_path::serialize")]
83 pub path: PathBuf,
84 /// 1-based line number of the call site or import declaration.
85 pub line: u32,
86 /// 0-based byte column offset of the call site or import declaration.
87 pub col: u32,
88 /// Name of the rule pack that declared the matching rule.
89 pub pack: String,
90 /// Id of the matching rule inside the pack. `pack` plus `rule_id` is the
91 /// finding's policy identity.
92 pub rule_id: String,
93 /// Which rule kind matched.
94 pub kind: PolicyRuleKind,
95 /// What matched: the written callee path for `banned-call` (e.g. `cp.exec`, or `new Date` for a `new` expression), `<effect>: <callee>` for `banned-effect`,
96 /// or the exported name for `banned-export`. For `gdp-proof-producer`, the canonical factory with its JSON-quoted literal label or `...` for a dynamic label.
97 /// For `banned-import`: the raw import specifier (e.g. `moment/locale/nl`), or `<specifier>: <binding>` when the rule sets `allowNames`.
98 /// `<binding>` is the source-side imported name, `default`, `*` for a namespace or star form,
99 /// or `side-effect`.
100 pub matched: String,
101 /// Effective severity for this finding (per-rule `severity`, else the
102 /// `rules."policy-violation"` master).
103 pub severity: PolicyViolationSeverity,
104 /// The rule's author-provided message, when set.
105 #[serde(default, skip_serializing_if = "Option::is_none")]
106 pub message: Option<String>,
107}