Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(core): added `ThanOthers` phrase linter
Elijah Potter73dc67748cd7
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex f54273131..d26cf0c6b 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -19,7 +19,7 @@ use super::number_suffix_capitalization::NumberSuffixCapitalization;use super::phrase_corrections::{AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,- SupposeTo, ThatChallenged, TurnItOff,+ SupposeTo, ThanOthers, ThatChallenged, TurnItOff,};use super::plural_conjugate::PluralConjugate;use super::pronoun_contraction::PronounContraction;@@ -219,6 +219,7 @@ create_lint_group_config!(SneakingSuspicion => true,SupposeTo => true,SpecialAttention => true,+ ThanOthers => true);impl<T: Dictionary + Default> Default for LintGroup<T> {diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rsindex 9aaea55b5..b8ca04b95 100644--- a/harper-core/src/linting/matcher.rs+++ b/harper-core/src/linting/matcher.rs@@ -156,10 +156,6 @@ impl Matcher {"want","be" => "won't be","more","then" => "more than","gong","to" => "going to",- "then","others" => "than others",- "Then","others" => "than others",- "then","before" => "than before",- "Then","before" => "than before","then","last","week" => "than last week","then","her" => "than her","then","hers" => "than hers",diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 139a82a09..46ee2ed4a 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -68,7 +68,7 @@ pub use pattern_linter::PatternLinter;pub use phrase_corrections::{AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,- SupposeTo, ThatChallenged, TurnItOff,+ SupposeTo, ThanOthers, ThatChallenged, TurnItOff,};pub use plural_conjugate::PluralConjugate;pub use pronoun_contraction::PronounContraction;diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rsindex 6dddd3e4f..4c832dbf5 100644--- a/harper-core/src/linting/phrase_corrections.rs+++ b/harper-core/src/linting/phrase_corrections.rs@@ -85,6 +85,7 @@ create_linter_for_phrase!(LoAndBehold, "lo and behold", 2);create_linter_for_phrase!(SneakingSuspicion, "sneaking suspicion", 3);create_linter_for_phrase!(SupposeTo, "suppose to", 1);create_linter_for_phrase!(SpecialAttention, "special attention", 1);+create_linter_for_phrase!(ThanOthers, "than others", 1);#[cfg(test)]mod tests {@@ -92,7 +93,7 @@ mod tests {use super::{BadRap, BatedBreath, ChangeTack, EnMasse, HungerPang, LetAlone, LoAndBehold, OfCourse,- SneakingSuspicion, SpecialAttention, SupposeTo, TurnItOff,+ SneakingSuspicion, SpecialAttention, SupposeTo, ThanOthers, TurnItOff,};#[test]@@ -195,4 +196,9 @@ mod tests {"special attention",);}++ #[test]+ fn than_others() {+ assert_suggestion_result("Then others", ThanOthers::default(), "Than others");+ }}diff --git a/harper-core/src/patterns/within_edit_distance.rs b/harper-core/src/patterns/within_edit_distance.rsindex 9cc2c6690..a706a407e 100644--- a/harper-core/src/patterns/within_edit_distance.rs+++ b/harper-core/src/patterns/within_edit_distance.rs@@ -1,5 +1,5 @@use super::Pattern;-use crate::{CharString, Token, TokenKind};+use crate::{CharString, CharStringExt, Token, TokenKind};use crate::edit_distance::edit_distance;@@ -36,7 +36,7 @@ impl Pattern for WithinEditDistance {let content = first.span.get_content(source);- if edit_distance(content, &self.word) <= self.max_edit_dist {+ if edit_distance(&content.to_lower(), &self.word.to_lower()) <= self.max_edit_dist {1} else {0