Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): capitalization issue in `SpellCheck` (#2541)
Steve Kurch6c5b5d2ef7c5
diff --git a/harper-core/src/linting/spell_check.rs b/harper-core/src/linting/spell_check.rsindex b1a476848..baae49248 100644--- a/harper-core/src/linting/spell_check.rs+++ b/harper-core/src/linting/spell_check.rs@@ -87,7 +87,15 @@ impl<T: Dictionary> Linter for SpellCheck<T> {if let Some(mis_f) = word_chars.first()&& mis_f.is_uppercase(){- for sug_f in possibilities.iter_mut().filter_map(|w| w.first_mut()) {+ for sug_f in possibilities.iter_mut().filter_map(|w| {+ // Skip words that have uppercase chars in any position except the first.+ // (For words with specific capitalization, like 'macOS')+ w.iter()+ .skip(1)+ .all(|c| !c.is_uppercase())+ .then_some(w.first_mut())+ .flatten()+ }) {*sug_f = sug_f.to_uppercase().next().unwrap();}}@@ -134,7 +142,7 @@ mod tests {use super::SpellCheck;use crate::dict_word_metadata::DialectFlags;use crate::linting::Linter;- use crate::linting::tests::assert_no_lints;+ use crate::linting::tests::{assert_good_and_bad_suggestions, assert_no_lints};use crate::spell::{Dictionary, FstDictionary, MergedDictionary, MutableDictionary};use crate::{Dialect,@@ -513,4 +521,14 @@ mod tests {SpellCheck::new(FstDictionary::curated(), Dialect::American),);}++ #[test]+ fn no_improper_suggestion_for_macos() {+ assert_good_and_bad_suggestions(+ "MacOS",+ SpellCheck::new(FstDictionary::curated(), Dialect::American),+ &["macOS"],+ &["MacOS"],+ );+ }}