Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: wrong variants of "an arm and a leg" (#4726)
Andrew Dunbar788d0e90f402
diff --git a/harper-core/default_config.json b/harper-core/default_config.jsonindex 7cd0a6193..eb8d77e53 100644--- a/harper-core/default_config.json+++ b/harper-core/default_config.json@@ -904,25 +904,32 @@"label": "Ado"}},+ {+ "Bool": {+ "name": "AnArmAndALeg",+ "state": true,+ "label": "An Arm and a Leg"+ }+ },{"Bool": {"name": "ArgumentToBeMade","state": true,- "label": "Argument To Be Made"+ "label": "Argument to be Made"}},{"Bool": {"name": "AtAllCosts","state": true,- "label": "At All Costs"+ "label": "At all Costs"}},{"Bool": {"name": "AwaitFor","state": true,- "label": "Await For"+ "label": "Await for"}},{diff --git a/harper-core/src/linting/an_arm_and_a_leg.rs b/harper-core/src/linting/an_arm_and_a_leg.rsnew file mode 100644index 000000000..c2b8352a0--- /dev/null+++ b/harper-core/src/linting/an_arm_and_a_leg.rs@@ -0,0 +1,152 @@+use crate::{+ Lint, Token, TokenStringExt,+ expr::{All, Expr, OwnedExprExt, SequenceExpr},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},+};++pub struct AnArmAndALeg {+ expr: All,+}++impl Default for AnArmAndALeg {+ fn default() -> Self {+ Self {+ expr: SequenceExpr::word_set([+ "charge", "charged", "charges", "charging", "cost", "costed", "costing", "costs",+ "paid", "pay", "payed", "paying", "pays",+ ])+ .t_ws()+ .then_any_of([+ Box::new(+ SequenceExpr::optional(SequenceExpr::word_set(["a", "an", "the"]).t_ws())+ .t_set(["arm", "arms"])+ .t_ws()+ .t_aco("and")+ .t_ws()+ .then_optional(SequenceExpr::word_set(["a", "an", "the"]).t_ws())+ .t_set(["leg", "legs"]),+ ),+ Box::new(+ SequenceExpr::optional(SequenceExpr::word_set(["a", "an", "the"]).t_ws())+ .t_set(["leg", "legs"])+ .t_ws()+ .t_aco("and")+ .t_ws()+ .then_optional(SequenceExpr::word_set(["a", "an", "the"]).t_ws())+ .t_set(["arm", "arms"]),+ ),+ ])+ .but_not(+ SequenceExpr::anything()+ .t_any()+ .then_word_seq(&["an", "arm", "and", "a", "leg"]),+ ),+ }+ }+}++impl ExprLinter for AnArmAndALeg {+ type Unit = Chunk;++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let toks = &toks[2..];+ let span = toks.span()?;++ Some(Lint {+ span,+ lint_kind: LintKind::Usage,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "an arm and a leg",+ span.get_content(src),+ )],+ message: "Use the standard idiom `an arm and a leg` instead.".to_owned(),+ ..Default::default()+ })+ }++ fn expr(&self) -> &dyn Expr {+ &self.expr+ }++ fn description(&self) -> &str {+ "Corrects wrong variants of the idiom `an arm and a leg`."+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};++ use super::AnArmAndALeg;++ #[test]+ fn paying_a_leg_and_an_arm() {+ assert_suggestion_result(+ "I am sick and tired of paying a leg and an arm in NYC taxes.",+ AnArmAndALeg::default(),+ "I am sick and tired of paying an arm and a leg in NYC taxes.",+ );+ }++ #[test]+ fn charge_leg_and_arm() {+ assert_suggestion_result(+ "they just “fix things” but charge leg and arm for their services",+ AnArmAndALeg::default(),+ "they just “fix things” but charge an arm and a leg for their services",+ );+ }++ #[test]+ fn charging_arm_and_leg() {+ assert_suggestion_result(+ "higher education institute charging arm and leg for people to network",+ AnArmAndALeg::default(),+ "higher education institute charging an arm and a leg for people to network",+ );+ }++ #[test]+ fn cost_an_arm_and_leg() {+ assert_suggestion_result(+ "Professional workstations have always cost an arm and leg - both arms and both legs usually",+ AnArmAndALeg::default(),+ "Professional workstations have always cost an arm and a leg - both arms and both legs usually",+ );+ }++ #[test]+ fn pay_arm_and_a_leg() {+ assert_suggestion_result(+ "than continuing to pay arm and a leg for eternity",+ AnArmAndALeg::default(),+ "than continuing to pay an arm and a leg for eternity",+ );+ }++ #[test]+ fn costs_arm_and_leg() {+ assert_suggestion_result(+ "Using your own analogy car repair costs arm and leg with the dealer vs diy",+ AnArmAndALeg::default(),+ "Using your own analogy car repair costs an arm and a leg with the dealer vs diy",+ );+ }++ #[test]+ fn charge_an_arm_and_leg() {+ assert_suggestion_result(+ "They manage to charge an arm and leg for regular things that a lot of the world makes",+ AnArmAndALeg::default(),+ "They manage to charge an arm and a leg for regular things that a lot of the world makes",+ );+ }++ #[test]+ fn dont_flag_removal() {+ assert_no_lints(+ "As in, they require removal of an arm and a leg.",+ AnArmAndALeg::default(),+ );+ }+}diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex ea0786af3..04db7f49d 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -23,6 +23,7 @@ use super::allow_to::AllowTo;use super::am_in_the_morning::AmInTheMorning;use super::amounts_for::AmountsFor;use super::an_a::AnA;+use super::an_arm_and_a_leg::AnArmAndALeg;use super::analog_acoustic_bike::AnalogAcousticBike;use super::and_the_like::AndTheLike;use super::another_thing_coming::AnotherThingComing;@@ -662,6 +663,7 @@ impl LintGroup {insert_expr_rule!(AmountsFor);insert_struct_rule_with_dialect!(AnA);insert_expr_rule_with_dialect!(AnalogAcousticBike);+ insert_expr_rule!(AnArmAndALeg);insert_expr_rule!(AndTheLike);insert_expr_rule!(AnotherThingComing);insert_expr_rule!(AnotherThinkComing);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex fd49f7f64..639c6744a 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -19,6 +19,7 @@ mod allow_to;mod am_in_the_morning;mod amounts_for;mod an_a;+mod an_arm_and_a_leg;mod analog_acoustic_bike;mod and_the_like;mod another_thing_coming;diff --git a/harper-core/src/linting/pay_for_price.rs b/harper-core/src/linting/pay_for_price.rsindex 1855caf12..8234903fa 100644--- a/harper-core/src/linting/pay_for_price.rs+++ b/harper-core/src/linting/pay_for_price.rs@@ -143,7 +143,7 @@ mod tests {);}- // Edge cases / False positives / Not yet handlec+ // Edge cases / False positives / Not yet handled#[test]#[ignore = "Detecting this pattery will require more thought"]