Auto merge of #6915 - smoelius:docs-link, r=llogiq

Do not show docs link when lint doesn't start with "clippy::"

This small change ensures that if the diagnostic functions are called from outside of Clippy, a docs link is not displayed.

---

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: restrict docs links
This commit is contained in:
bors 2021-03-16 07:08:48 +00:00
commit 1a206fc4ab

View file

@ -8,14 +8,16 @@ use std::env;
fn docs_link(diag: &mut DiagnosticBuilder<'_>, lint: &'static Lint) {
if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() {
diag.help(&format!(
"for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{}",
&option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| {
// extract just major + minor version and ignore patch versions
format!("rust-{}", n.rsplitn(2, '.').nth(1).unwrap())
}),
lint.name_lower().replacen("clippy::", "", 1)
));
if let Some(lint) = lint.name_lower().strip_prefix("clippy::") {
diag.help(&format!(
"for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{}",
&option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| {
// extract just major + minor version and ignore patch versions
format!("rust-{}", n.rsplitn(2, '.').nth(1).unwrap())
}),
lint
));
}
}
}