Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat:a lot of/most of the times→time (#2141)
Andrew Dunbar2830b6749f4c
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 4440a48dc..079c1e455 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -89,6 +89,7 @@ use super::modal_of::ModalOf;use super::modal_seem::ModalSeem;use super::months::Months;use super::most_number::MostNumber;+use super::most_of_the_times::MostOfTheTimes;use super::multiple_sequential_pronouns::MultipleSequentialPronouns;use super::nail_on_the_head::NailOnTheHead;use super::no_french_spaces::NoFrenchSpaces;@@ -523,6 +524,7 @@ impl LintGroup {insert_expr_rule!(ModalSeem, true);insert_expr_rule!(Months, true);insert_expr_rule!(MostNumber, true);+ insert_expr_rule!(MostOfTheTimes, true);insert_expr_rule!(MultipleSequentialPronouns, true);insert_struct_rule!(NailOnTheHead, true);insert_struct_rule!(NoFrenchSpaces, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex ada0a16cb..f884dd66f 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -96,6 +96,7 @@ mod modal_of;mod modal_seem;mod months;mod most_number;+mod most_of_the_times;mod multiple_sequential_pronouns;mod nail_on_the_head;mod no_french_spaces;@@ -265,6 +266,7 @@ pub use modal_of::ModalOf;pub use modal_seem::ModalSeem;pub use months::Months;pub use most_number::MostNumber;+pub use most_of_the_times::MostOfTheTimes;pub use multiple_sequential_pronouns::MultipleSequentialPronouns;pub use nail_on_the_head::NailOnTheHead;pub use no_french_spaces::NoFrenchSpaces;diff --git a/harper-core/src/linting/most_of_the_times.rs b/harper-core/src/linting/most_of_the_times.rsnew file mode 100644index 000000000..4cd13b8dd--- /dev/null+++ b/harper-core/src/linting/most_of_the_times.rs@@ -0,0 +1,90 @@+use crate::expr::{Expr, FixedPhrase, SequenceExpr};+use crate::linting::{ExprLinter, LintKind, Suggestion};+use crate::patterns::Word;+use crate::{Lint, Token};++pub struct MostOfTheTimes {+ expr: Box<dyn Expr>,+}++impl Default for MostOfTheTimes {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::any_of(vec![+ Box::new(FixedPhrase::from_phrase("a lot")),+ Box::new(Word::new("most")),+ ])+ .t_ws()+ .then_fixed_phrase("of the times"),+ ),+ }+ }+}++impl ExprLinter for MostOfTheTimes {+ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let span = toks.last()?.span;+ Some(Lint {+ span,+ lint_kind: LintKind::Usage,+ suggestions: vec![Suggestion::replace_with_match_case(+ "time".chars().collect(),+ span.get_content(src),+ )],+ message: "Singular `time` is usually the correct form in this context.".to_string(),+ priority: 32,+ })+ }++ fn description(&self) -> &str {+ "Corrects `a lot of the times` and `most of the times` to use singular `time`."+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::assert_suggestion_result;++ use super::MostOfTheTimes;++ #[test]+ fn hangs_forever() {+ assert_suggestion_result(+ "restic backup hangs forever most of the times · Issue #2834",+ MostOfTheTimes::default(),+ "restic backup hangs forever most of the time · Issue #2834",+ );+ }++ #[test]+ fn options_are_ignored() {+ assert_suggestion_result(+ "but other options like device and options are ignored most of the times",+ MostOfTheTimes::default(),+ "but other options like device and options are ignored most of the time",+ );+ }++ #[test]+ fn parenthesized() {+ assert_suggestion_result(+ "prompted html code gets (most of the times) read by copilot but is not displayed.",+ MostOfTheTimes::default(),+ "prompted html code gets (most of the time) read by copilot but is not displayed.",+ );+ }++ #[test]+ fn i_cant_play() {+ assert_suggestion_result(+ "I cannot get the version 1.0 without c so I cant play a lot of the times with other people",+ MostOfTheTimes::default(),+ "I cannot get the version 1.0 without c so I cant play a lot of the time with other people",+ );+ }+}