Skip to content

Commit 13e2633

Browse files
committed
Also sanitize configuration
1 parent daf730c commit 13e2633

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

clippy_config/src/conf.rs

+24
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ impl ConfError {
9797
}
9898
}
9999

100+
// Remove code tags and code behind '# 's, as they are not needed for the lint docs and --explain
101+
pub fn sanitize_explanation(raw_docs: &str) -> String {
102+
// Remove tags and hidden code:
103+
let mut explanation = String::with_capacity(128);
104+
let mut in_code = false;
105+
for line in raw_docs.lines().map(str::trim) {
106+
if let Some(lang) = line.strip_prefix("```") {
107+
let tag = lang.split_once(',').map_or(lang, |(left, _)| left);
108+
if !in_code && matches!(tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail") {
109+
explanation += "```rust\n";
110+
} else {
111+
explanation += line;
112+
explanation.push('\n');
113+
}
114+
in_code = !in_code;
115+
} else if !(in_code && line.starts_with("# ")) {
116+
explanation += line;
117+
explanation.push('\n');
118+
}
119+
}
120+
121+
explanation
122+
}
123+
100124
macro_rules! wrap_option {
101125
() => {
102126
None

clippy_config/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ mod metadata;
2626
pub mod msrvs;
2727
pub mod types;
2828

29-
pub use conf::{Conf, get_configuration_metadata, lookup_conf_file};
29+
pub use conf::{Conf, get_configuration_metadata, lookup_conf_file, sanitize_explanation};
3030
pub use metadata::ClippyConfiguration;

clippy_lints/src/lib.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ mod zero_sized_map_values;
396396
mod zombie_processes;
397397
// end lints modules, do not remove this comment, it’s used in `update_lints`
398398

399-
use clippy_config::{Conf, get_configuration_metadata};
399+
use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation};
400400
use clippy_utils::macros::FormatArgsStorage;
401401
use rustc_data_structures::fx::FxHashSet;
402402
use rustc_lint::{Lint, LintId};
@@ -522,30 +522,6 @@ impl LintInfo {
522522
}
523523
}
524524

525-
// Remove code tags and code behind '# 's, as they are not needed for the lint docs and --explain
526-
pub fn sanitize_explanation(raw_docs: &str) -> String {
527-
// Remove tags and hidden code:
528-
let mut explanation = String::with_capacity(128);
529-
let mut in_code = false;
530-
for line in raw_docs.lines().map(|line| line.trim()) {
531-
if let Some(lang) = line.strip_prefix("```") {
532-
let tag = lang.split_once(',').map_or(lang, |(left, _)| left);
533-
if !in_code && matches!(tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail") {
534-
explanation += "```rust\n";
535-
} else {
536-
explanation += line;
537-
explanation.push('\n');
538-
}
539-
in_code = !in_code;
540-
} else if !(in_code && line.starts_with("# ")) {
541-
explanation += line;
542-
explanation.push('\n');
543-
}
544-
}
545-
546-
explanation
547-
}
548-
549525
pub fn explain(name: &str) -> i32 {
550526
let target = format!("clippy::{}", name.to_ascii_uppercase());
551527

tests/compile-test.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use cargo_metadata::Message;
66
use cargo_metadata::diagnostic::{Applicability, Diagnostic};
77
use clippy_config::ClippyConfiguration;
8+
use clippy_lints::LintInfo;
89
use clippy_lints::declared_lints::LINTS;
910
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
10-
use clippy_lints::{LintInfo, sanitize_explanation};
1111
use serde::{Deserialize, Serialize};
1212
use test_utils::IS_RUSTC_TEST_SUITE;
1313
use ui_test::custom_flags::Flag;
@@ -444,10 +444,6 @@ impl DiagnosticCollector {
444444
iter::zip(DEPRECATED, DEPRECATED_VERSION)
445445
.map(|((lint, reason), version)| LintMetadata::new_deprecated(lint, reason, version)),
446446
)
447-
.map(|mut metadata| {
448-
metadata.docs = sanitize_explanation(&metadata.docs);
449-
metadata
450-
})
451447
.collect();
452448

453449
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));

0 commit comments

Comments
 (0)