Skip to content

Commit 7025283

Browse files
committed
Remove cargo_metadata dependency from clippy_dev
1 parent b3f8415 commit 7025283

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

clippy_dev/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ version = "0.0.1"
44
edition = "2021"
55

66
[dependencies]
7-
bytecount = "0.6"
87
clap = "2.33"
98
indoc = "1.0"
109
itertools = "0.10.1"
1110
opener = "0.5"
1211
shell-escape = "0.1"
1312
walkdir = "2.3"
14-
cargo_metadata = "0.14"
15-
1613

1714
[features]
1815
deny-warnings = []

clippy_dev/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(let_else)]
12
#![feature(once_cell)]
23
#![feature(rustc_private)]
34
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

clippy_dev/src/new_lint.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,23 @@ fn to_camel_case(name: &str) -> String {
133133
}
134134

135135
fn get_stabilisation_version() -> String {
136-
let mut command = cargo_metadata::MetadataCommand::new();
137-
command.no_deps();
138-
if let Ok(metadata) = command.exec() {
139-
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
140-
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
141-
}
136+
fn parse_manifest(contents: &str) -> Option<String> {
137+
let version = contents
138+
.lines()
139+
.filter_map(|l| l.split_once('='))
140+
.find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))?;
141+
let Some(("0", version)) = version.get(1..version.len() - 1)?.split_once('.') else {
142+
return None;
143+
};
144+
let (minor, patch) = version.split_once('.')?;
145+
Some(format!(
146+
"{}.{}.0",
147+
minor.parse::<u32>().ok()?,
148+
patch.parse::<u32>().ok()?
149+
))
142150
}
143-
144-
String::from("<TODO set version(see doc/adding_lints.md)>")
151+
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
152+
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
145153
}
146154

147155
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {

0 commit comments

Comments
 (0)