Skip to content
/ rust Public
forked from rust-lang/rust

Commit 14e4f9f

Browse files
committed
Suggest switching underscores for dashes
1 parent f3cbc39 commit 14e4f9f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/tools/tidy/src/unstable_book.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ fn collect_unstable_book_lib_features_section_file_names(base_src_path: &Path) -
7272
collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
7373
}
7474

75+
/// Would switching underscores for dashes work?
76+
fn maybe_suggest_dashes(names: &BTreeSet<String>, feature_name: &str, bad: &mut bool) {
77+
let with_dashes = feature_name.replace('_', "-");
78+
if names.contains(&with_dashes) {
79+
tidy_error!(
80+
bad,
81+
"the file `{}.md` contains underscores; use dashes instead: `{}.md`",
82+
feature_name,
83+
with_dashes,
84+
);
85+
}
86+
}
87+
7588
pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
7689
let lang_features = features.lang;
7790
let lib_features = features
@@ -99,6 +112,7 @@ pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
99112
correspond to an unstable library feature",
100113
feature_name
101114
);
115+
maybe_suggest_dashes(&unstable_lib_feature_names, &feature_name, bad);
102116
}
103117

104118
// Check for Unstable Book sections that don't have a corresponding unstable feature.
@@ -110,7 +124,8 @@ pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
110124
"The Unstable Book has a 'language feature' section '{}' which doesn't \
111125
correspond to an unstable language feature",
112126
feature_name
113-
)
127+
);
128+
maybe_suggest_dashes(&unstable_lang_feature_names, &feature_name, bad);
114129
}
115130

116131
// List unstable features that don't have Unstable Book sections.

0 commit comments

Comments
 (0)