Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: try one‘s hands at→try one‘s hand at (#2614)
Andrew Dunbarf5ba1ea892c1
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 6af9715e1..6d5d4b0b9 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -201,6 +201,7 @@ use super::to_adverb::ToAdverb;use super::to_two_too::ToTwoToo;use super::touristic::Touristic;use super::transposed_space::TransposedSpace;+use super::try_ones_hand_at::TryOnesHandAt;use super::unclosed_quotes::UnclosedQuotes;use super::update_place_names::UpdatePlaceNames;use super::use_title_case::UseTitleCase;@@ -587,6 +588,7 @@ impl LintGroup {insert_expr_rule!(ToAdverb, true);insert_struct_rule!(ToTwoToo, true);insert_expr_rule!(Touristic, true);+ insert_expr_rule!(TryOnesHandAt, true);insert_struct_rule!(UnclosedQuotes, true);insert_expr_rule!(UpdatePlaceNames, true);insert_expr_rule!(VerbToAdjective, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 2c0c6cd21..51470eedd 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -212,6 +212,7 @@ mod to_adverb;mod to_two_too;mod touristic;mod transposed_space;+mod try_ones_hand_at;mod unclosed_quotes;mod update_place_names;mod use_title_case;diff --git a/harper-core/src/linting/try_ones_hand_at.rs b/harper-core/src/linting/try_ones_hand_at.rsnew file mode 100644index 000000000..e0b838ae4--- /dev/null+++ b/harper-core/src/linting/try_ones_hand_at.rs@@ -0,0 +1,133 @@+use crate::{+ Lint, Token,+ expr::{Expr, SequenceExpr},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},+};++pub struct TryOnesHandAt {+ expr: Box<dyn Expr>,+}++impl Default for TryOnesHandAt {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::word_set(&["try", "tried", "tries", "trying"])+ .t_ws()+ .then_possessive_determiner()+ .t_ws()+ .t_aco("hands")+ .t_ws()+ .t_aco("at"),+ ),+ }+ }+}++impl ExprLinter for TryOnesHandAt {+ type Unit = Chunk;++ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let hands_idx = 4;+ let hands_tok = toks.get(hands_idx)?;+ let hands_span = hands_tok.span;+ let hands_chars = hands_span.get_content(src);++ Some(Lint {+ span: hands_span,+ lint_kind: LintKind::Usage,+ suggestions: vec![Suggestion::replace_with_match_case(+ vec!['h', 'a', 'n', 'd'],+ hands_chars,+ )],+ message: "This idiom uses the singular `hand`.".to_string(),+ ..Default::default()+ })+ }++ fn description(&self) -> &str {+ "Corrects `try one's hands at` to `try one's hand at`."+ }+}++#[cfg(test)]+mod tests {+ use super::TryOnesHandAt;+ use crate::linting::tests::assert_suggestion_result;++ #[test]+ fn fix_tried_my() {+ assert_suggestion_result(+ "I tried my hands at a little test to see how different parameters I get for the same deck and the same material.",+ TryOnesHandAt::default(),+ "I tried my hand at a little test to see how different parameters I get for the same deck and the same material.",+ )+ }++ #[test]+ fn fix_tried_their() {+ assert_suggestion_result(+ "If there isn't any obvious reason why no one has tried their hands at it yet, I might try implementing it.",+ TryOnesHandAt::default(),+ "If there isn't any obvious reason why no one has tried their hand at it yet, I might try implementing it.",+ )+ }++ #[test]+ fn fix_tries_his() {+ assert_suggestion_result(+ "A fellow programmer from India who tries his hands at everything he can.",+ TryOnesHandAt::default(),+ "A fellow programmer from India who tries his hand at everything he can.",+ )+ }++ #[test]+ fn fix_try_my() {+ assert_suggestion_result(+ "I am happy to try my hands at implementing one, but not being that proficient in C/C++ need some guidance on where to start.",+ TryOnesHandAt::default(),+ "I am happy to try my hand at implementing one, but not being that proficient in C/C++ need some guidance on where to start.",+ )+ }++ #[test]+ fn fix_try_our() {+ assert_suggestion_result(+ "One way to make some of the requirements for this more concrete is to try our hands at implementing a language server.",+ TryOnesHandAt::default(),+ "One way to make some of the requirements for this more concrete is to try our hand at implementing a language server.",+ )+ }++ #[test]+ fn fix_try_their() {+ assert_suggestion_result(+ "At the end the user will be able to create a list of decimal numbers to try their hands at the Diagonal Argument on their own.",+ TryOnesHandAt::default(),+ "At the end the user will be able to create a list of decimal numbers to try their hand at the Diagonal Argument on their own.",+ )+ }++ #[test]+ fn fix_try_your() {+ assert_suggestion_result(+ "You'll likely need to try your hands at a bit of Lua to make it work.",+ TryOnesHandAt::default(),+ "You'll likely need to try your hand at a bit of Lua to make it work.",+ )+ }++ #[test]+ fn fix_trying_my() {+ assert_suggestion_result(+ "I wouldn't mind trying my hands at a PR if the solution would be accepted.",+ TryOnesHandAt::default(),+ "I wouldn't mind trying my hand at a PR if the solution would be accepted.",+ )+ }+}