Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions src/contains_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ pub fn check_contains_regex(
.map_err(|err| format!("could not parse template: {}", err))?;
let text = read_file(path).map_err(|err| format!("could not read {}: {}", path, err))?;

println!("Searching for \"{}\" in {}...", pattern, path);
println!("Searching for \"{pattern}\" in {path}...");
match re.find(&text) {
Some(m) => {
let line_no = text[..m.start()].lines().count();
println!("{} (line {}) ... ok", path, line_no + 1);
Ok(())
}
None => Err(format!("could not find \"{}\" in {}", pattern, path)),
None => Err(format!("could not find \"{pattern}\" in {path}")),
}
}

Expand Down Expand Up @@ -113,11 +113,11 @@ pub fn check_only_contains_regex(
.build()
.map_err(|err| format!("could not parse template: {}", err))?;

let semver_re = Regex::new(&SEMVER_RE).unwrap();
let semver_re = Regex::new(SEMVER_RE).unwrap();

let text = read_file(path).map_err(|err| format!("could not read {}: {}", path, err))?;

println!("Searching for \"{}\" in {}...", template, path);
println!("Searching for \"{template}\" in {path}...");
let mut errors = 0;
let mut has_match = false;

Expand All @@ -142,24 +142,23 @@ pub fn check_only_contains_regex(
);
}
Ok(()) => {
println!("{} (line {}) ... ok", path, line_no);
println!("{path} (line {line_no}) ... ok");
}
}
}
}

if !has_match {
return Err(format!(
"{} ... found no matches for \"{}\"",
path, template
"{path} ... found no matches for \"{template}\""
));
}

if errors > 0 {
return Err(format!("{} ... found {} errors", path, errors));
return Err(format!("{path} ... found {errors} errors"));
}

return Ok(());
Ok(())
}

#[cfg(test)]
Expand All @@ -172,15 +171,13 @@ mod tests {
// the (?m) prefix.
assert_eq!(
check_contains_regex("README.md", "Version {version} [ups", "foobar", "1.2.3"),
Err(String::from(
[
Err([
r"could not parse template: regex parse error:",
r" Version 1\.2\.3 [ups",
r" ^",
r"error: unclosed character class"
]
.join("\n")
))
.join("\n"))
)
}

Expand All @@ -203,13 +200,11 @@ mod tests {
"foo*bar",
"1.2.3"
),
Err(String::from(
[
Err([
r#"could not find "escaped: foo\*bar-1\.2\.3,"#,
r#"not escaped: foo*bar-1.2.3" in README.md"#
]
.join(" ")
))
.join(" "))
)
}

Expand Down Expand Up @@ -244,7 +239,7 @@ mod tests {
// users call check_only_contains_regex with a string like
// "foo {version}" which also contains more than just
// "{version}".
let re = Regex::new(&format!("^{}$", SEMVER_RE)).unwrap();
let re = Regex::new(&format!("^{SEMVER_RE}$")).unwrap();
assert!(re.is_match("1.2.3"));
assert!(re.is_match("1.2"));
assert!(re.is_match("1"));
Expand Down
8 changes: 4 additions & 4 deletions src/contains_substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ pub fn check_contains_substring(
//
// but allows the user to leave out unnecessary placeholders.
let pattern = template
.replace("{name}", &pkg_name)
.replace("{version}", &pkg_version);
.replace("{name}", pkg_name)
.replace("{version}", pkg_version);

let text = read_file(path).map_err(|err| format!("could not read {}: {}", path, err))?;

println!("Searching for \"{}\" in {}...", pattern, path);
println!("Searching for \"{pattern}\" in {path}...");
match text.find(&pattern) {
Some(idx) => {
let line_no = text[..idx].lines().count();
println!("{} (line {}) ... ok", path, line_no + 1);
Ok(())
}
None => Err(format!("could not find \"{}\" in {}", pattern, path)),
None => Err(format!("could not find \"{pattern}\" in {path}")),
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/html_root_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ fn url_matches(value: &str, pkg_name: &str, version: &Version) -> Result<()> {
// Finally, we check that the package name and version matches.
if name != pkg_name {
Err(format!(
"expected package \"{}\", found \"{}\"",
pkg_name, name
"expected package \"{pkg_name}\", found \"{name}\""
))
} else {
// The Rust API Guidelines[1] suggest using an exact version
Expand Down Expand Up @@ -75,7 +74,7 @@ pub fn check_html_root_url(path: &str, pkg_name: &str, pkg_version: &str) -> Res
let krate: syn::File = syn::parse_file(&code)
.map_err(|_| format!("could not parse {}: please run \"cargo build\"", path))?;

println!("Checking doc attributes in {}...", path);
println!("Checking doc attributes in {path}...");
for attr in krate.attrs {
if let syn::AttrStyle::Outer = attr.style {
continue;
Expand Down Expand Up @@ -290,7 +289,7 @@ mod test_check_html_root_url {
} else {
"The system cannot find the file specified. (os error 2)"
};
let errmsg = format!("could not read no-such-file.md: {}", no_such_file);
let errmsg = format!("could not read no-such-file.md: {no_such_file}");
assert_eq!(
check_html_root_url("no-such-file.md", "foobar", "1.2.3"),
Err(errmsg)
Expand Down
14 changes: 7 additions & 7 deletions src/markdown_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ fn extract_version_request(pkg_name: &str, block: &str) -> Result<VersionReq> {
match version {
Some(version) => VersionReq::parse(version)
.map_err(|err| format!("could not parse dependency: {}", err)),
None => Err(format!("no dependency on {}", pkg_name)),
None => Err(format!("no dependency on {pkg_name}")),
}
}
Err(err) => Err(format!("{}", err)),
Err(err) => Err(format!("{err}")),
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn check_markdown_deps(path: &str, pkg_name: &str, pkg_version: &str) -> Res
let version = Version::parse(pkg_version)
.map_err(|err| format!("bad package version {:?}: {}", pkg_version, err))?;

println!("Checking code blocks in {}...", path);
println!("Checking code blocks in {path}...");
let mut failed = false;
for block in find_toml_blocks(&text) {
let result = extract_version_request(pkg_name, &block.content)
Expand All @@ -146,7 +146,7 @@ pub fn check_markdown_deps(path: &str, pkg_name: &str, pkg_version: &str) -> Res
}

if failed {
return Err(format!("dependency errors in {}", path));
return Err(format!("dependency errors in {path}"));
}
Ok(())
}
Expand Down Expand Up @@ -195,7 +195,7 @@ mod tests {
```\n\
Trailing text";
assert_eq!(
find_toml_blocks(&text),
find_toml_blocks(text),
vec![CodeBlock {
content: String::from("foo\n"),
first_line: 3
Expand All @@ -215,7 +215,7 @@ mod tests {
> ```\n\
";
assert_eq!(
find_toml_blocks(&text),
find_toml_blocks(text),
vec![CodeBlock {
content: String::from("foo\n\n bar\n\n"),
first_line: 4
Expand Down Expand Up @@ -314,7 +314,7 @@ mod tests {
} else {
"The system cannot find the file specified. (os error 2)"
};
let errmsg = format!("could not read no-such-file.md: {}", no_such_file);
let errmsg = format!("could not read no-such-file.md: {no_such_file}");
assert_eq!(
check_markdown_deps("no-such-file.md", "foobar", "1.2.3"),
Err(errmsg)
Expand Down