Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(title-case): keep lowercase `x` as a connector word (#4238)

Norbert Biczo087d8afd876f
diff --git a/harper-core/src/linting/use_title_case.rs b/harper-core/src/linting/use_title_case.rs
index e4f0534ff..bba6ff9d5 100644
--- a/harper-core/src/linting/use_title_case.rs
+++ b/harper-core/src/linting/use_title_case.rs
@@ -125,4 +125,17 @@ mod tests {
UseTitleCase::new(FstDictionary::curated()),
);
}
+
+ #[test]
+ fn does_not_capitalize_standalone_x_between_words() {
+ assert_no_lints(
+ "# Project 1 x Project 2",
+ UseTitleCase::new(FstDictionary::curated()),
+ );
+ }
+
+ #[test]
+ fn capitalizes_standalone_x_when_last_word() {
+ assert_no_lints("# Project X", UseTitleCase::new(FstDictionary::curated()));
+ }
}
diff --git a/harper-core/src/title_case.rs b/harper-core/src/title_case.rs
index 2684ad705..e4aa971b9 100644
--- a/harper-core/src/title_case.rs
+++ b/harper-core/src/title_case.rs
@@ -213,6 +213,7 @@ fn should_capitalize_token(tok: &Token, source: &[char]) -> bool {
!is_short_preposition
&& !chars.eq_any_ignore_ascii_case_str(&["and", "but", "for", "or", "nor", "as"])
&& !chars.eq_any_ignore_ascii_case_str(&["a", "an", "the"])
+ && !(chars.len() == 1 && chars[0] == 'x')
}
_ => true,
}
@@ -670,4 +671,32 @@ mod tests {
"# Meeting at 9:05am"
);
}
+
+ #[test]
+ fn standalone_x_stays_lowercase_between_words() {
+ assert_eq!(
+ make_title_case_str(
+ "Project 1 x Project 2",
+ &PlainEnglish,
+ &FstDictionary::curated()
+ ),
+ "Project 1 x Project 2",
+ );
+ }
+
+ #[test]
+ fn standalone_x_stays_lowercase_at_start_is_capitalized() {
+ assert_eq!(
+ make_title_case_str("x marks the spot", &PlainEnglish, &FstDictionary::curated()),
+ "X Marks the Spot",
+ );
+ }
+
+ #[test]
+ fn standalone_x_stays_lowercase_as_last_word_is_capitalized() {
+ assert_eq!(
+ make_title_case_str("project x", &PlainEnglish, &FstDictionary::curated()),
+ "Project X",
+ );
+ }
}