From 203cfff8265b10fe4b428fb1d9b8166239cedbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 1 Mar 2021 21:13:16 +0200 Subject: Check for path dev-dependencies with a version number --- xtask/src/tidy.rs | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index 63116ec6b..349ca14d0 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs @@ -101,21 +101,44 @@ fn cargo_files_are_tidy() { let mut section = None; for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() { let text = text.trim(); - if text.starts_with("[") { + if text.starts_with('[') { + if !text.ends_with(']') { + panic!( + "\nplease don't add comments or trailing whitespace in section lines.\n\ + {}:{}\n", + cargo.display(), + line_no + 1 + ) + } section = Some(text); continue; } - if !section.map(|it| it.starts_with("[dependencies")).unwrap_or(false) { + let text: String = text.split_whitespace().collect(); + if !text.contains("path=") { continue; } - let text: String = text.split_whitespace().collect(); - if text.contains("path=") && !text.contains("version") { - panic!( - "\ncargo internal dependencies should have version.\n\ - {}:{}\n", - cargo.display(), - line_no + 1 - ) + match section { + Some(s) if s.contains("dev-dependencies") => { + if text.contains("version") { + panic!( + "\ncargo internal dev-dependencies should not have a version.\n\ + {}:{}\n", + cargo.display(), + line_no + 1 + ); + } + } + Some(s) if s.contains("dependencies") => { + if !text.contains("version") { + panic!( + "\ncargo internal dependencies should have a version.\n\ + {}:{}\n", + cargo.display(), + line_no + 1 + ); + } + } + _ => {} } } } -- cgit v1.2.3