diff --git a/src/contains_regex.rs b/src/contains_regex.rs index 71e1687..942f122 100644 --- a/src/contains_regex.rs +++ b/src/contains_regex.rs @@ -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}")), } } @@ -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; @@ -142,7 +142,7 @@ pub fn check_only_contains_regex( ); } Ok(()) => { - println!("{} (line {}) ... ok", path, line_no); + println!("{path} (line {line_no}) ... ok"); } } } @@ -150,16 +150,15 @@ pub fn check_only_contains_regex( 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)] @@ -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")) ) } @@ -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(" ")) ) } @@ -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")); diff --git a/src/contains_substring.rs b/src/contains_substring.rs index 21249f6..88ef0cd 100644 --- a/src/contains_substring.rs +++ b/src/contains_substring.rs @@ -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}")), } } diff --git a/src/html_root_url.rs b/src/html_root_url.rs index fac390e..1a4f840 100644 --- a/src/html_root_url.rs +++ b/src/html_root_url.rs @@ -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 @@ -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; @@ -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) diff --git a/src/markdown_deps.rs b/src/markdown_deps.rs index 035bb17..9917d56 100644 --- a/src/markdown_deps.rs +++ b/src/markdown_deps.rs @@ -34,10 +34,10 @@ fn extract_version_request(pkg_name: &str, block: &str) -> Result { 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}")), } } @@ -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) @@ -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(()) } @@ -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 @@ -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 @@ -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)