Skip to content

Commit 1a206fc

Browse files
committed
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
2 parents c701c30 + f7c5742 commit 1a206fc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

clippy_utils/src/diagnostics.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ use std::env;
88

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

0 commit comments

Comments
 (0)