Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: all hell break out→all hell break loose (#2813)
Andrew Dunbar5f9b86353a74
diff --git a/harper-core/src/linting/all_hell_break_loose.rs b/harper-core/src/linting/all_hell_break_loose.rsnew file mode 100644index 000000000..48ebf391b--- /dev/null+++ b/harper-core/src/linting/all_hell_break_loose.rs@@ -0,0 +1,102 @@+use crate::{+ Lint, Token,+ expr::{Expr, SequenceExpr},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},+};++pub struct AllHellBreakLoose {+ expr: Box<dyn Expr>,+}++impl Default for AllHellBreakLoose {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::aco("all")+ .t_ws()+ .t_aco("hell")+ .t_ws()+ .then_word_set(&["break", "breaking", "breaks", "broke", "broken"])+ .t_ws()+ .t_aco("out"),+ ),+ }+ }+}++impl ExprLinter for AllHellBreakLoose {+ type Unit = Chunk;++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let outtok = toks.last()?;+ let outspan = outtok.span;+ let outchars = outspan.get_content(src);++ Some(Lint {+ lint_kind: LintKind::Eggcorn,+ span: outspan,+ suggestions: vec![Suggestion::replace_with_match_case_str("loose", outchars)],+ message: "The correct idiom is `all hell breaks loose`.".to_string(),+ ..Default::default()+ })+ }++ fn description(&self) -> &str {+ "Corrects forms of `all hell breaks out` to `all hell breaks loose`."+ }++ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }+}++#[cfg(test)]+mod tests {+ use super::AllHellBreakLoose;+ use crate::linting::tests::assert_suggestion_result;++ #[test]+ fn fix_break() {+ assert_suggestion_result(+ "Just run around planting satchels charges while you're alive and let all hell break out when you die.",+ AllHellBreakLoose::default(),+ "Just run around planting satchels charges while you're alive and let all hell break loose when you die.",+ );+ }++ #[test]+ fn fix_breaks() {+ assert_suggestion_result(+ "we upgraded 2 months ago, and now we upgrade prod and all hell breaks out",+ AllHellBreakLoose::default(),+ "we upgraded 2 months ago, and now we upgrade prod and all hell breaks loose",+ );+ }++ #[test]+ fn fix_breaking() {+ assert_suggestion_result(+ "Next scene, all hell breaking out!",+ AllHellBreakLoose::default(),+ "Next scene, all hell breaking loose!",+ );+ }++ #[test]+ fn fix_broke() {+ assert_suggestion_result(+ "this time going from 1.3.4 to 1.4.2 and all hell broke out",+ AllHellBreakLoose::default(),+ "this time going from 1.3.4 to 1.4.2 and all hell broke loose",+ );+ }++ #[test]+ fn fix_broken() {+ assert_suggestion_result(+ "I’m using silenced weapons but as soon as I fire it’s all hell broken out.",+ AllHellBreakLoose::default(),+ "I’m using silenced weapons but as soon as I fire it’s all hell broken loose.",+ );+ }+}diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 399a03a9a..66ab70e52 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -17,6 +17,7 @@ use super::addicting::Addicting;use super::adjective_double_degree::AdjectiveDoubleDegree;use super::adjective_of_a::AdjectiveOfA;use super::after_later::AfterLater;+use super::all_hell_break_loose::AllHellBreakLoose;use super::all_intents_and_purposes::AllIntentsAndPurposes;use super::allow_to::AllowTo;use super::am_in_the_morning::AmInTheMorning;@@ -429,6 +430,7 @@ impl LintGroup {insert_expr_rule!(AdjectiveDoubleDegree, true);insert_struct_rule!(AdjectiveOfA, true);insert_expr_rule!(AfterLater, true);+ insert_expr_rule!(AllHellBreakLoose, true);insert_expr_rule!(AllIntentsAndPurposes, true);insert_expr_rule!(AllowTo, true);insert_expr_rule!(AmInTheMorning, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex c03b75ee4..9c5f84f39 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -8,6 +8,7 @@ mod addicting;mod adjective_double_degree;mod adjective_of_a;mod after_later;+mod all_hell_break_loose;mod all_intents_and_purposes;mod allow_to;mod am_in_the_morning;