(r: &Trace)
| 22 | } |
| 23 | |
| 24 | pub fn lint(r: &Trace) -> Vec<LintWarning> { |
| 25 | let mut out = vec![]; |
| 26 | if r.description.trim().is_empty() { |
| 27 | out.push(LintWarning { |
| 28 | kind: LintKind::EmptyDescription, |
| 29 | step_id: None, |
| 30 | message: "trace description is empty".into(), |
| 31 | }); |
| 32 | } |
| 33 | let todo_re = todo_re(); |
| 34 | let mut step_referenced: std::collections::HashSet<&str> = std::collections::HashSet::new(); |
| 35 | for (step_id, step) in &r.steps { |
| 36 | if step.does.trim().is_empty() { |
| 37 | out.push(LintWarning { |
| 38 | kind: LintKind::EmptyDescription, |
| 39 | step_id: Some(step_id.clone()), |
| 40 | message: format!("step `{}` has empty `does`", step_id), |
| 41 | }); |
| 42 | } else if todo_re.is_match(&step.does) { |
| 43 | out.push(LintWarning { |
| 44 | kind: LintKind::TodoInDoes, |
| 45 | step_id: Some(step_id.clone()), |
| 46 | message: format!("step `{}` does contains TODO/FIXME/XXX", step_id), |
| 47 | }); |
| 48 | } |
| 49 | for fs in &step.from_steps { |
| 50 | step_referenced.insert(fs.as_str()); |
| 51 | if let Some(target) = r.steps.get(fs) { |
| 52 | if target.deprecated { |
| 53 | out.push(LintWarning { |
| 54 | kind: LintKind::DeprecatedReferenced, |
| 55 | step_id: Some(step_id.clone()), |
| 56 | message: format!( |
| 57 | "step `{}` depends on deprecated step `{}`", |
| 58 | step_id, fs |
| 59 | ), |
| 60 | }); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | for (step_id, step) in &r.steps { |
| 66 | // A terminal step that feeds the deliverable is not an orphan. Deliverable |
| 67 | // assets are run-relative (`<step_id>/<file>`), so match that prefix as well |
| 68 | // as a bare filename. |
| 69 | let prefix = format!("{}/", step_id); |
| 70 | let step_in_deliverable = r |
| 71 | .deliverable |
| 72 | .assets |
| 73 | .iter() |
| 74 | .any(|d| d.starts_with(&prefix) || step.assets.iter().any(|a| d == a)); |
| 75 | if !step_referenced.contains(step_id.as_str()) && !step_in_deliverable { |
| 76 | out.push(LintWarning { |
| 77 | kind: LintKind::OrphanStep, |
| 78 | step_id: Some(step_id.clone()), |
| 79 | message: format!( |
| 80 | "step `{}` is not referenced by any other step's from_steps", |
| 81 | step_id |
searching dependent graphs…