Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: another thing coming vs another think coming (#1438)
Andrew Dunbar105ff137c3e1
diff --git a/harper-core/src/linting/another_thing_coming.rs b/harper-core/src/linting/another_thing_coming.rsnew file mode 100644index 000000000..feac36b36--- /dev/null+++ b/harper-core/src/linting/another_thing_coming.rs@@ -0,0 +1,89 @@+use crate::{+ Token, TokenStringExt,+ expr::{Expr, FixedPhrase, SequenceExpr},+ linting::{ExprLinter, Lint, LintKind, Suggestion},+ patterns::WordSet,+};++/// Both `another thing coming` and `another think coming` are correct, but `another think coming` is more common.+pub struct AnotherThingComing {+ expr: Box<dyn Expr>,+}++impl Default for AnotherThingComing {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::default()+ .then(WordSet::new(&["had", "has", "have", "got"]))+ .then(FixedPhrase::from_phrase(" another think coming")),+ ),+ }+ }+}++impl ExprLinter for AnotherThingComing {+ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ Some(Lint {+ span: toks[2..].span()?,+ lint_kind: LintKind::WordChoice,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "another thing coming",+ toks.span()?.get_content(src),+ )],+ message: "Corrects `another think coming` to `another thing coming`".to_string(),+ priority: 63,+ })+ }++ fn description(&self) -> &str {+ "Though `another think coming` is the original phrase, `another thing coming` is now more common."+ }+}++#[cfg(test)]+pub mod tests {+ use super::AnotherThingComing;+ use crate::linting::tests::assert_suggestion_result;++ #[test]+ fn fix_have_another_think_coming() {+ assert_suggestion_result(+ "If you think that, you have another think coming, English.",+ AnotherThingComing::default(),+ "If you think that, you have another thing coming, English.",+ );+ }++ #[test]+ fn fix_has_another_think_coming() {+ assert_suggestion_result(+ "If the wage earner thinks that he will obtain anything from either of the old parties he has another think coming.",+ AnotherThingComing::default(),+ "If the wage earner thinks that he will obtain anything from either of the old parties he has another thing coming.",+ );+ }++ #[test]+ #[ignore = "A lettercase bug results in 'another thiNG COMing.'"]+ fn fix_got_another_think_coming() {+ assert_suggestion_result(+ "The correct phrase is, “You've got another THINK coming.”",+ AnotherThingComing::default(),+ "The correct phrase is, “You've got another THING coming.”",+ );+ }++ #[test]+ fn fix_had_another_think_coming() {+ assert_suggestion_result(+ "Guess I had another think coming.",+ AnotherThingComing::default(),+ "Guess I had another thing coming.",+ );+ }+}diff --git a/harper-core/src/linting/another_think_coming.rs b/harper-core/src/linting/another_think_coming.rsnew file mode 100644index 000000000..cc29ed0a6--- /dev/null+++ b/harper-core/src/linting/another_think_coming.rs@@ -0,0 +1,88 @@+use crate::{+ Token, TokenStringExt,+ expr::{Expr, FixedPhrase, SequenceExpr},+ linting::{ExprLinter, Lint, LintKind, Suggestion},+ patterns::WordSet,+};++/// Both `another thing coming` and `another think coming` are correct, but `another think coming` is the original.+pub struct AnotherThinkComing {+ expr: Box<dyn Expr>,+}++impl Default for AnotherThinkComing {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::default()+ .then(WordSet::new(&["had", "has", "have", "got"]))+ .then(FixedPhrase::from_phrase(" another thing coming")),+ ),+ }+ }+}++impl ExprLinter for AnotherThinkComing {+ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ Some(Lint {+ span: toks[2..].span()?,+ lint_kind: LintKind::WordChoice,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "another think coming",+ toks.span()?.get_content(src),+ )],+ message: "Corrects `another thing coming` to `another think coming`".to_string(),+ priority: 63,+ })+ }++ fn description(&self) -> &str {+ "Though `another thing coming` is now more common, `another think coming` is the original phrase."+ }+}++#[cfg(test)]+pub mod tests {+ use super::AnotherThinkComing;+ use crate::linting::tests::assert_suggestion_result;++ #[test]+ fn fix_got_another_thing_coming() {+ assert_suggestion_result(+ "If Microsoft thinks my Team and I are going to REINSTALL Windows fresh on over 1500 PC's they've got another thing coming!!",+ AnotherThinkComing::default(),+ "If Microsoft thinks my Team and I are going to REINSTALL Windows fresh on over 1500 PC's they've got another think coming!!",+ );+ }++ #[test]+ fn fix_has_another_thing_coming() {+ assert_suggestion_result(+ "Anyone who thinks it's easy to raise a child has another thing coming.",+ AnotherThinkComing::default(),+ "Anyone who thinks it's easy to raise a child has another think coming.",+ );+ }++ #[test]+ fn fix_have_another_thing_coming() {+ assert_suggestion_result(+ "And if you think they're predictable, you have another thing coming still.",+ AnotherThinkComing::default(),+ "And if you think they're predictable, you have another think coming still.",+ );+ }++ #[test]+ fn fix_had_another_thing_coming() {+ assert_suggestion_result(+ "And wouldn't you know it I had another thing coming.",+ AnotherThinkComing::default(),+ "And wouldn't you know it I had another think coming.",+ );+ }+}diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 6c950c2cd..7b59eeefe 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -16,6 +16,8 @@ use super::adjective_of_a::AdjectiveOfA;use super::am_in_the_morning::AmInTheMorning;use super::amounts_for::AmountsFor;use super::an_a::AnA;+use super::another_thing_coming::AnotherThingComing;+use super::another_think_coming::AnotherThinkComing;use super::ask_no_preposition::AskNoPreposition;use super::avoid_curses::AvoidCurses;use super::back_in_the_day::BackInTheDay;@@ -364,6 +366,8 @@ impl LintGroup {insert_struct_rule!(AmInTheMorning, true);insert_pattern_rule!(AmountsFor, true);insert_struct_rule!(AnA, true);+ insert_pattern_rule!(AnotherThingComing, true);+ insert_pattern_rule!(AnotherThinkComing, false);insert_pattern_rule!(AskNoPreposition, true);insert_struct_rule!(AvoidCurses, true);insert_pattern_rule!(BackInTheDay, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex f3fd2b7b5..baa6adc87 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -7,6 +7,8 @@ mod adjective_of_a;mod am_in_the_morning;mod amounts_for;mod an_a;+mod another_thing_coming;+mod another_think_coming;mod ask_no_preposition;mod avoid_curses;mod back_in_the_day;@@ -104,6 +106,8 @@ pub use adjective_of_a::AdjectiveOfA;pub use am_in_the_morning::AmInTheMorning;pub use amounts_for::AmountsFor;pub use an_a::AnA;+pub use another_thing_coming::AnotherThingComing;+pub use another_think_coming::AnotherThinkComing;pub use ask_no_preposition::AskNoPreposition;pub use avoid_curses::AvoidCurses;pub use back_in_the_day::BackInTheDay;