7836: Check for path dev-dependencies with a version number r=lnicola a=lnicola

Closes https://github.com/rust-analyzer/rust-analyzer/pull/7828#issuecomment-788174522.

This looks a bit ugly, but at least fixes an issues where we missed target-specific dependencies.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2021-03-02 08:38:25 +00:00 committed by GitHub
commit 61c73caa30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,22 +101,45 @@ fn cargo_files_are_tidy() {
let mut section = None; let mut section = None;
for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() { for (line_no, text) in read_file(&cargo).unwrap().lines().enumerate() {
let text = text.trim(); let text = text.trim();
if text.starts_with("[") { if text.starts_with('[') {
section = Some(text); if !text.ends_with(']') {
continue;
}
if !section.map(|it| it.starts_with("[dependencies")).unwrap_or(false) {
continue;
}
let text: String = text.split_whitespace().collect();
if text.contains("path=") && !text.contains("version") {
panic!( panic!(
"\ncargo internal dependencies should have version.\n\ "\nplease don't add comments or trailing whitespace in section lines.\n\
{}:{}\n", {}:{}\n",
cargo.display(), cargo.display(),
line_no + 1 line_no + 1
) )
} }
section = Some(text);
continue;
}
let text: String = text.split_whitespace().collect();
if !text.contains("path=") {
continue;
}
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
);
}
}
_ => {}
}
} }
} }
} }