Reject structurally incomplete findings before presenting them as evidence. This checks presence, not the truth of the reviewer's judgment.
(&self)
| 122 | /// Reject structurally incomplete findings before presenting them as evidence. |
| 123 | /// This checks presence, not the truth of the reviewer's judgment. |
| 124 | pub fn validate(&self) -> Result<(), &'static str> { |
| 125 | if [ |
| 126 | self.analyzer.as_str(), |
| 127 | &self.change, |
| 128 | &self.summary, |
| 129 | &self.requirement_or_rule.id, |
| 130 | &self.requirement_or_rule.explanation, |
| 131 | &self.introduced_by_change.rationale, |
| 132 | &self.proposed_correction, |
| 133 | ] |
| 134 | .iter() |
| 135 | .any(|value| value.trim().is_empty()) |
| 136 | { |
| 137 | return Err( |
| 138 | "finding requires analyzer, change, summary, rule, rationale and correction", |
| 139 | ); |
| 140 | } |
| 141 | if self.locations.is_empty() |
| 142 | || self.locations.iter().any(|location| { |
| 143 | location.path.trim().is_empty() |
| 144 | || location.start_line == 0 |
| 145 | || location.end_line < location.start_line |
| 146 | }) |
| 147 | { |
| 148 | return Err("finding requires valid 1-based recorded source locations"); |
| 149 | } |
| 150 | if self.evidence.is_empty() |
| 151 | || self |
| 152 | .evidence |
| 153 | .iter() |
| 154 | .any(|item| item.reference.trim().is_empty() || item.observation.trim().is_empty()) |
| 155 | { |
| 156 | return Err("finding requires referenced supporting evidence"); |
| 157 | } |
| 158 | if self |
| 159 | .acceptance_criteria |
| 160 | .iter() |
| 161 | .any(|link| link.criterion.trim().is_empty() || link.rationale.trim().is_empty()) |
| 162 | { |
| 163 | return Err("criterion assessments require an exact criterion and evidenced rationale"); |
| 164 | } |
| 165 | Ok(()) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |