Skip to content

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

feat(core): convert more `matcher` rules to the proper style

Elijah Pottera4c94a9577b0
diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rs
index f69824a64..9407f8632 100644
--- a/harper-core/src/linting/matcher.rs
+++ b/harper-core/src/linting/matcher.rs
@@ -103,37 +103,6 @@ impl Matcher {
// defined like it is now.
let mut triggers = Vec::new();
- // stylistic improvements
- triggers.extend(pt! {
- "all", "of", "the" => "all the",
- "and","also" => "and"
- });
-
- // phrase typos, each word passes spellcheck but one word is wrong
- triggers.extend(pt! {
- "an","in" => "and in",
- "bee","there" => "been there",
- "can","be","seem" => "can be seen",
- "eight","grade" => "eighth grade",
- "gong","to" => "going to",
- "I","a","m" => "I am",
- "It","cam" => "It can",
- "kid","regards" => "kind regards",
- "mu","house" => "my house",
- "no","to" => "not to",
- "No","to" => "not to",
- "the", "this" => "that this",
- "The","re" => "There",
- "though", "process" => "thought process"
- });
-
- // phrase capitalization
- triggers.extend(pt! {
- "black","sea" => "Black Sea",
- "geiger","counter" => "Geiger counter",
- "my","french" => "my French"
- });
-
// hyphenated phrases
triggers.extend(pt! {
"case", "sensitive" => "case-sensitive",
@@ -162,16 +131,6 @@ impl Matcher {
"w/o" => "without"
});
- // replace euphemisms
- triggers.extend(pt! {
- "fatal","outcome" => "death"
- });
-
- // spellos
- triggers.extend(pt! {
- "grammer" => "grammar"
- });
-
// expand compound words
triggers.extend(pt! {
"hashmap" => "hash map",
@@ -204,8 +163,6 @@ impl Matcher {
"could", "of" => "could have",
"could", "of" => "could've",
"couldn't", "of" => "couldn't have",
- "had", "of" => "had have",
- "had", "of" => "had've",
"hadn't", "of" => "hadn't have",
"should", "of" => "should have",
"should", "of" => "should've",
@@ -216,22 +173,7 @@ impl Matcher {
"discuss", "about" => "discuss",
"discussed", "about" => "discussed",
"discusses", "about" => "discusses",
- "discussing", "about" => "discussing",
- "same", "than" => "same as",
- "Same", "than" => "same as",
- "sooner","than","later" => "sooner rather than later",
- "sooner","than","later" => "sooner or later"
- });
-
- // belonging to multiple of the other categories
- triggers.extend(pt! {
- "same", "then" => "same as",
- "Same", "then" => "same as"
- });
-
- // near homophones
- triggers.extend(pt! {
- "want","be" => "won't be"
+ "discussing", "about" => "discussing"
});
// normalization
diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rs
index db0ec1a0a..671b70954 100644
--- a/harper-core/src/linting/phrase_corrections.rs
+++ b/harper-core/src/linting/phrase_corrections.rs
@@ -39,6 +39,8 @@ pub fn lint_group() -> LintGroup {
"SneakingSuspicion" => ("sneaking suspicion", 3),
"SpecialAttention" => ("special attention", 1),
"SupposedTo" => ("supposed to", 1),
+ "KindRegards" => ("kind regards", 1),
+ "ThoughtProcess" => ("thought process", 1),
});
macro_rules! add_exact_mappings {
@@ -118,6 +120,96 @@ pub fn lint_group() -> LintGroup {
["road map"],
"Did you mean `road map`?",
"Detects when `roadmap` is used instead of `road map`, prompting the correct spacing."
+ ),
+ "SameAs" => (
+ "same then",
+ ["same as"],
+ "Did you mean `same as`?",
+ "Corrects the incorrect phrase `same then` to the standard `same as`."
+ ),
+ "SoonerOrLater" => (
+ "sooner than later",
+ ["sooner rather than later", "sooner or later"],
+ "Did you mean `sooner rather than later` or `sooner or later`?",
+ "Fixes the improper phrase `sooner than later` by suggesting standard alternatives."
+ ),
+ "HadOf" => (
+ "had of",
+ ["had have", "had've"],
+ "Did you mean `had have` or `had've`?",
+ "Flags the unnecessary use of `of` after `had` and suggests the correct forms."
+ ),
+ "FatalOutcome" => (
+ "fatal outcome",
+ ["death"],
+ "Consider using `death` for clarity.",
+ "Replaces `fatal outcome` with the more direct term `death` for conciseness."
+ ),
+ "NotTo" => (
+ "no to",
+ ["not to"],
+ "Did you mean `not to`?",
+ "Corrects `no to` to `not to`, ensuring proper negation."
+ ),
+ "ThatThis" => (
+ "the this",
+ ["that this"],
+ "Did you mean `that this`?",
+ "Fixes `the this` to the correct phrase `that this`."
+ ),
+ "CondenseAllThe" => (
+ "all of the",
+ ["all the"],
+ "Consider simplifying to `all the`.",
+ "Suggests removing `of` in `all of the` for a more concise phrase."
+ ),
+ "AvoidAndAlso" => (
+ "and also",
+ ["and"],
+ "Consider using just `and`.",
+ "Reduces redundancy by replacing `and also` with `and`."
+ ),
+ "AndIn" => (
+ "an in",
+ ["and in"],
+ "Did you mean `and in`?",
+ "Fixes the incorrect phrase `an in` to `and in` for proper conjunction usage."
+ ),
+ "BeenThere" => (
+ "bee there",
+ ["been there"],
+ "Did you mean `been there`?",
+ "Corrects the misspelling `bee there` to the proper phrase `been there`."
+ ),
+ "CanBeSeen" => (
+ "can be seem",
+ ["can be seen"],
+ "Did you mean `can be seen`?",
+ "Corrects `can be seem` to the proper phrase `can be seen`."
+ ),
+ "GoingTo" => (
+ "gong to",
+ ["going to"],
+ "Did you mean `going to`?",
+ "Corrects `gong to` to the intended phrase `going to`."
+ ),
+ "IAm" => (
+ "I a m",
+ ["I am"],
+ "Did you mean `I am`?",
+ "Fixes the incorrect spacing in `I a m` to properly form `I am`."
+ ),
+ "ItCan" => (
+ "It cam",
+ ["It can"],
+ "Did you mean `It can`?",
+ "Corrects the misspelling `It cam` to the proper phrase `It can`."
+ ),
+ "MyHouse" => (
+ "mu house",
+ ["my house"],
+ "Did you mean `my house`?",
+ "Fixes the typo `mu house` to `my house`."
)
});
diff --git a/harper-core/src/linting/proper_noun_capitalization_linters.rs b/harper-core/src/linting/proper_noun_capitalization_linters.rs
index 988d634b0..8ac1cd12d 100644
--- a/harper-core/src/linting/proper_noun_capitalization_linters.rs
+++ b/harper-core/src/linting/proper_noun_capitalization_linters.rs
@@ -130,6 +130,52 @@ pub fn lint_group(dictionary: Arc<impl Dictionary + 'static>) -> LintGroup {
)),
);
+ group.add(
+ "OceansAndSeas",
+ Box::new(ProperNounCapitalizationLinter::new(
+ EitherPattern::new(vec![
+ Box::new(
+ SequencePattern::default()
+ .then_word_set(WordSet::all(&[
+ "Atlantic",
+ "Pacific",
+ "Indian",
+ "Southern",
+ "Arctic",
+ ]))
+ .then_whitespace()
+ .t_aco("Ocean")
+ ),
+ Box::new(
+ SequencePattern::default()
+ .then_word_set(WordSet::all(&[
+ "Mediterranean",
+ "Caribbean",
+ "Baltic",
+ "Red",
+ "Black",
+ "Caspian",
+ "Coral",
+ "Bering",
+ "North",
+ ]))
+ .then_whitespace()
+ .t_aco("Sea")
+ ),
+ Box::new(
+ SequencePattern::default()
+ .t_aco("South")
+ .then_whitespace()
+ .t_aco("China")
+ .then_whitespace()
+ .t_aco("Sea")
+ ),
+ ]),
+ "When referring to the world's oceans and seas, ensure they are treated as proper nouns.",
+ dictionary.clone()
+ ))
+);
+
group.add(
"Canada",
Box::new(ProperNounCapitalizationLinter::new(
@@ -927,4 +973,99 @@ mod tests {
"Microsoft Visual Studio",
);
}
+
+ #[test]
+ fn test_atlantic_ocean_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("atlantic ocean", group, "Atlantic Ocean");
+ }
+
+ #[test]
+ fn test_pacific_ocean_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("pacific ocean", group, "Pacific Ocean");
+ }
+
+ #[test]
+ fn test_indian_ocean_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("indian ocean", group, "Indian Ocean");
+ }
+
+ #[test]
+ fn test_southern_ocean_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("southern ocean", group, "Southern Ocean");
+ }
+
+ #[test]
+ fn test_arctic_ocean_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("arctic ocean", group, "Arctic Ocean");
+ }
+
+ // Lowercase tests for seas
+
+ #[test]
+ fn test_mediterranean_sea_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("mediterranean sea", group, "Mediterranean Sea");
+ }
+
+ #[test]
+ fn test_caribbean_sea_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("caribbean sea", group, "Caribbean Sea");
+ }
+
+ #[test]
+ fn test_south_china_sea_lowercase() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_suggestion_result("south china sea", group, "South China Sea");
+ }
+
+ // Tests that allow correctly capitalized names
+
+ #[test]
+ fn test_atlantic_ocean_correct() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_lint_count("Atlantic Ocean", group, 0);
+ }
+
+ #[test]
+ fn test_pacific_ocean_correct() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_lint_count("Pacific Ocean", group, 0);
+ }
+
+ #[test]
+ fn test_indian_ocean_correct() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_lint_count("Indian Ocean", group, 0);
+ }
+
+ #[test]
+ fn test_mediterranean_sea_correct() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_lint_count("Mediterranean Sea", group, 0);
+ }
+
+ #[test]
+ fn test_south_china_sea_correct() {
+ let dictionary = FstDictionary::curated();
+ let group = lint_group(dictionary);
+ assert_lint_count("South China Sea", group, 0);
+ }
}