Remove cargo_metadata dependency from clippy_dev

This commit is contained in:
Jason Newcomb 2022-03-29 08:32:12 -04:00
parent b3f8415032
commit 7025283f3e
3 changed files with 17 additions and 11 deletions

View file

@ -4,15 +4,12 @@ version = "0.0.1"
edition = "2021"
[dependencies]
bytecount = "0.6"
clap = "2.33"
indoc = "1.0"
itertools = "0.10.1"
opener = "0.5"
shell-escape = "0.1"
walkdir = "2.3"
cargo_metadata = "0.14"
[features]
deny-warnings = []

View file

@ -1,3 +1,4 @@
#![feature(let_else)]
#![feature(once_cell)]
#![feature(rustc_private)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

View file

@ -133,15 +133,23 @@ fn to_camel_case(name: &str) -> String {
}
fn get_stabilisation_version() -> String {
let mut command = cargo_metadata::MetadataCommand::new();
command.no_deps();
if let Ok(metadata) = command.exec() {
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
}
fn parse_manifest(contents: &str) -> Option<String> {
let version = contents
.lines()
.filter_map(|l| l.split_once('='))
.find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))?;
let Some(("0", version)) = version.get(1..version.len() - 1)?.split_once('.') else {
return None;
};
let (minor, patch) = version.split_once('.')?;
Some(format!(
"{}.{}.0",
minor.parse::<u32>().ok()?,
patch.parse::<u32>().ok()?
))
}
String::from("<TODO set version(see doc/adding_lints.md)>")
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
}
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {