Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: mixed bad→mixed bag (#1946)
Andrew Dunbar2856961293d6
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex eb0a85ac1..9ec731e63 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -68,6 +68,7 @@ use super::long_sentences::LongSentences;use super::looking_forward_to::LookingForwardTo;use super::merge_words::MergeWords;use super::missing_preposition::MissingPreposition;+use super::mixed_bag::MixedBag;use super::modal_of::ModalOf;use super::months::Months;use super::most_number::MostNumber;@@ -449,7 +450,6 @@ impl LintGroup {insert_struct_rule!(FirstAidKit, true);insert_struct_rule!(ForNoun, true);insert_expr_rule!(FriendOfMe, true);- insert_expr_rule!(SimplePastToPastParticiple, true);insert_expr_rule!(HavePronoun, true);insert_expr_rule!(Hedging, true);insert_expr_rule!(Hereby, true);@@ -468,6 +468,7 @@ impl LintGroup {insert_expr_rule!(LookingForwardTo, true);insert_struct_rule!(MergeWords, true);insert_expr_rule!(MissingPreposition, true);+ insert_expr_rule!(MixedBag, true);insert_expr_rule!(ModalOf, true);insert_expr_rule!(Months, true);insert_expr_rule!(MostNumber, true);@@ -481,21 +482,21 @@ impl LintGroup {insert_expr_rule!(NounCountability, true);insert_struct_rule!(NumberSuffixCapitalization, true);insert_struct_rule!(OfCourse, true);- insert_struct_rule!(OughtToBe, true);insert_expr_rule!(OnFloor, true);insert_expr_rule!(OneAndTheSame, true);insert_expr_rule!(OpenCompounds, true);insert_expr_rule!(OpenTheLight, true);+ insert_struct_rule!(OughtToBe, true);insert_expr_rule!(OutOfDate, true);insert_struct_rule!(OxfordComma, true);insert_expr_rule!(Oxymorons, true);insert_struct_rule!(PhrasalVerbAsCompoundNoun, true);insert_expr_rule!(PiqueInterest, true);insert_expr_rule!(PossessiveYour, true);+ insert_expr_rule!(ProgressiveNeedsBe, true);insert_struct_rule!(PronounContraction, true);insert_expr_rule!(PronounInflectionBe, true);insert_struct_rule!(PronounKnew, true);- insert_expr_rule!(ProgressiveNeedsBe, true);insert_struct_rule!(PunctuationClusters, true);insert_expr_rule!(QuantifierNeedsOf, true);insert_expr_rule!(QuiteQuiet, true);@@ -504,6 +505,7 @@ impl LintGroup {insert_struct_rule!(SaveToSafe, true);insert_expr_rule!(SemicolonApostrophe, true);insert_expr_rule!(ShootOneselfInTheFoot, true);+ insert_expr_rule!(SimplePastToPastParticiple, true);insert_expr_rule!(SinceDuration, true);insert_expr_rule!(SomewhatSomething, true);insert_expr_rule!(SoughtAfter, true);diff --git a/harper-core/src/linting/mixed_bag.rs b/harper-core/src/linting/mixed_bag.rsnew file mode 100644index 000000000..d3e4dac7b--- /dev/null+++ b/harper-core/src/linting/mixed_bag.rs@@ -0,0 +1,182 @@+use crate::CharStringExt;+use crate::linting::expr_linter::find_the_only_token_matching;+use crate::linting::{ExprLinter, LintKind, Suggestion};+use crate::{+ Lint, Token, TokenKind,+ expr::{Expr, SequenceExpr},+};++pub struct MixedBag {+ expr: Box<dyn Expr>,+}++impl Default for MixedBag {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::default()+ .then_kind_any_or_words(+ &[TokenKind::is_adjective, TokenKind::is_adverb] as &[_],+ &["a"],+ )+ .t_ws()+ .t_aco("mixed")+ .t_ws()+ .t_aco("bad"),+ ),+ }+ }+}++impl ExprLinter for MixedBag {+ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let bad_span = find_the_only_token_matching(toks, src, |tok, _src| {+ tok.span+ .get_content(src)+ .eq_ignore_ascii_case_chars(&['b', 'a', 'd'])+ })?+ .span;++ Some(Lint {+ span: bad_span,+ lint_kind: LintKind::Eggcorn,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "bag",+ bad_span.get_content(src),+ )],+ message: "Corrects the eggcorn `mixed bad` to `mixed bag`.".to_string(),+ ..Default::default()+ })+ }++ fn description(&self) -> &'static str {+ "Corrects the eggcorn `mixed bad` to `mixed bag`."+ }+}++#[cfg(test)]+mod tests {+ use super::MixedBag;+ use crate::linting::tests::assert_suggestion_result;++ #[test]+ fn a_mixed_bad() {+ assert_suggestion_result(+ "CommandLine interface is already a mixed bad of wstring and #ifdef to string or wstring.",+ MixedBag::default(),+ "CommandLine interface is already a mixed bag of wstring and #ifdef to string or wstring.",+ );+ }++ #[test]+ fn big_mixed_bag() {+ assert_suggestion_result(+ "Speaking of dungeons , the dungeons in this game are a big mixed bad.",+ MixedBag::default(),+ "Speaking of dungeons , the dungeons in this game are a big mixed bag.",+ );+ }++ #[test]+ fn damn_mixed_bag() {+ assert_suggestion_result(+ "This is a damn mixed bad which left me frustrated, and yet longing for more.",+ MixedBag::default(),+ "This is a damn mixed bag which left me frustrated, and yet longing for more.",+ );+ }++ #[test]+ fn huge_mixed_bag() {+ assert_suggestion_result(+ "Also a huge mixed bad of no name monitors of different sizes that all have different color settings on.",+ MixedBag::default(),+ "Also a huge mixed bag of no name monitors of different sizes that all have different color settings on.",+ );+ }++ #[test]+ fn large_mixed_bag() {+ assert_suggestion_result(+ "I’m still struggling to comprehend how it throws such a large mixed bad of symptoms in the mix this time.",+ MixedBag::default(),+ "I’m still struggling to comprehend how it throws such a large mixed bag of symptoms in the mix this time.",+ );+ }++ #[test]+ fn massive_mixed_bad() {+ assert_suggestion_result(+ "Anyway. In topic, Swano was a massive mixed bad in this game.",+ MixedBag::default(),+ "Anyway. In topic, Swano was a massive mixed bag in this game.",+ );+ }++ #[test]+ fn massively_mixed_bag() {+ assert_suggestion_result(+ "While certain things are more common to be either way, it's a massively mixed bad overall.",+ MixedBag::default(),+ "While certain things are more common to be either way, it's a massively mixed bag overall.",+ );+ }++ #[test]+ fn pretty_mixed_bag() {+ assert_suggestion_result(+ "It's a pretty mixed bad for me: Evolution Xavier for comic Xavier. Evolution Magneto for comic Magneto.",+ MixedBag::default(),+ "It's a pretty mixed bag for me: Evolution Xavier for comic Xavier. Evolution Magneto for comic Magneto.",+ );+ }++ #[test]+ fn rather_mixed_bag() {+ assert_suggestion_result(+ "Well chaps, as expected the TS contains a rather mixed bad of promise and disappointment.",+ MixedBag::default(),+ "Well chaps, as expected the TS contains a rather mixed bag of promise and disappointment.",+ );+ }++ #[test]+ fn really_mixed_bag() {+ assert_suggestion_result(+ "This is a really mixed bad On one hand you have some of Eminem's highest highs and his lowest lows but ever.",+ MixedBag::default(),+ "This is a really mixed bag On one hand you have some of Eminem's highest highs and his lowest lows but ever.",+ );+ }++ #[test]+ fn slightly_mixed_bag() {+ assert_suggestion_result(+ "I absolutely love Yes Minister and Yes Prime Minister but it did end up a slightly mixed bad in terms of impact.",+ MixedBag::default(),+ "I absolutely love Yes Minister and Yes Prime Minister but it did end up a slightly mixed bag in terms of impact.",+ );+ }++ #[test]+ fn somewhat_mixed_bag() {+ assert_suggestion_result(+ "A somewhat mixed bad. The space is pleasant with a rustic vibe.",+ MixedBag::default(),+ "A somewhat mixed bag. The space is pleasant with a rustic vibe.",+ );+ }++ #[test]+ fn very_mixed_bag() {+ assert_suggestion_result(+ "AVAILABLE MEN is a very mixed bad of short films about gay subjects that very from excellent to weak.",+ MixedBag::default(),+ "AVAILABLE MEN is a very mixed bag of short films about gay subjects that very from excellent to weak.",+ );+ }+}diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 457d89b51..501ce85a3 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -74,6 +74,7 @@ mod mass_plurals;mod merge_linters;mod merge_words;mod missing_preposition;+mod mixed_bag;mod modal_of;mod months;mod most_number;@@ -211,6 +212,7 @@ pub use map_phrase_set_linter::MapPhraseSetLinter;pub use mass_plurals::MassPlurals;pub use merge_words::MergeWords;pub use missing_preposition::MissingPreposition;+pub use mixed_bag::MixedBag;pub use modal_of::ModalOf;pub use months::Months;pub use most_number::MostNumber;