Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: a handful of more → a handful more (#3223)
Andrew Dunbar47fc44482345
diff --git a/harper-core/default_config.json b/harper-core/default_config.jsonindex ae2ebe369..213693500 100644--- a/harper-core/default_config.json+++ b/harper-core/default_config.json@@ -1296,6 +1296,13 @@"label": "Inflection Point"}},+ {+ "Bool": {+ "name": "HandfulOfMore",+ "state": true,+ "label": "Handful Of More"+ }+ },{"Bool": {"name": "FormativeYears",diff --git a/harper-core/src/linting/handful_of_more.rs b/harper-core/src/linting/handful_of_more.rsnew file mode 100644index 000000000..dce9f8646--- /dev/null+++ b/harper-core/src/linting/handful_of_more.rs@@ -0,0 +1,80 @@+use crate::{+ Lint, Token, TokenKind, TokenStringExt,+ expr::{Expr, SequenceExpr},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},+};++pub struct HandfulOfMore {+ expr: SequenceExpr,+}++impl Default for HandfulOfMore {+ fn default() -> Self {+ Self {+ expr: SequenceExpr::aco("handful")+ .t_ws()+ .t_aco("of")+ .t_ws()+ .t_aco("more")+ .t_ws()+ .then_kind_is_but_is_not(TokenKind::is_noun, TokenKind::is_adjective),+ }+ }+}++impl ExprLinter for HandfulOfMore {+ type Unit = Chunk;++ fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {+ let (first_ws_idx, of_idx) = (1, 2);++ Some(Lint {+ span: matched_tokens[first_ws_idx..=of_idx].span()?,+ lint_kind: LintKind::Nonstandard,+ suggestions: vec![Suggestion::Remove],+ message: "Using `of` in this construction is not standard.".to_string(),+ ..Default::default()+ })+ }++ fn expr(&self) -> &dyn Expr {+ &self.expr+ }++ fn description(&self) -> &str {+ "A linter skeleton for contributors to copy into `harper_core/src/linting/` and rename."+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};++ use super::HandfulOfMore;++ #[test]+ fn fix_handful_of_more_times() {+ assert_suggestion_result(+ "(and possibly a handful of more times as needed to resolve any issues)",+ HandfulOfMore::default(),+ "(and possibly a handful more times as needed to resolve any issues)",+ );+ }++ #[test]+ fn fix_handful_of_more_prs() {+ assert_suggestion_result(+ "(maybe as soon as tomorrow, but trying to get a handful of more PRs merged...)",+ HandfulOfMore::default(),+ "(maybe as soon as tomorrow, but trying to get a handful more PRs merged...)",+ );+ }++ #[test]+ fn dont_flag_comparative() {+ assert_no_lints(+ "After writing a handful of more advanced recipes I often found myself running into situations where the context wasn't recognized",+ HandfulOfMore::default(),+ );+ }+}diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex f7c8fe0c7..df109c603 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -101,6 +101,7 @@ use super::go_so_far_as_to::GoSoFarAsTo;use super::go_to_war::GoToWar;use super::good_at::GoodAt;use super::handful::Handful;+use super::handful_of_more::HandfulOfMore;use super::have_pronoun::HavePronoun;use super::have_take_a_look::HaveTakeALook;use super::hedging::Hedging;@@ -665,6 +666,7 @@ impl LintGroup {insert_expr_rule!(GoToWar, true);insert_expr_rule!(GoodAt, true);insert_expr_rule!(Handful, true);+ insert_expr_rule!(HandfulOfMore, true);insert_expr_rule!(HavePronoun, true);insert_struct_rule_with_dialect!(HaveTakeALook, true);insert_expr_rule!(Hedging, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex d95e902ac..533e7921e 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -97,6 +97,7 @@ mod go_so_far_as_to;mod go_to_war;mod good_at;mod handful;+mod handful_of_more;mod have_pronoun;mod have_take_a_look;mod hedging;