From cb4f7d11af74aa794daade03286a8f9700e1ac0b Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 13 Jan 2019 17:50:37 -0800 Subject: [PATCH] lint: Check that affected_paths start with crate name Uses the crate name as fetched from the crates.io API to ensure all `affected_paths` begin with the crate name (i.e. are canonical) --- .travis.yml | 5 ++++- src/main.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e6e05dc..0ed1e1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: rust -script: cargo run check # check that the advisory-db is well-formed +cache: cargo + +# check that the advisory-db is well-formed +script: cargo run check branches: only: diff --git a/src/main.rs b/src/main.rs index 209eea4..04562bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,4 +102,19 @@ fn check_advisory(cratesio_client: &crates_io_api::SyncClient, advisory: &rustse advisory.package.as_str() ); } + + // Check that each path in `affected_paths` starts with the crate name + if let Some(ref version_req_paths) = advisory.affected_paths { + for (_, paths) in version_req_paths.iter() { + for path in paths { + if path.crate_name() != response.crate_data.name { + panic!( + "{}: affected_path does not begin with crate name: {}", + response.crate_data.name, + path.crate_name() + ) + } + } + } + } }