Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: have hard time → have a hard time (#3812)

Andrew Dunbar2d78e23e59f3
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index c0860532e..0f7734367 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -5397,6 +5397,13 @@
"label": "For The Nth Time"
}
},
+ {
+ "Bool": {
+ "name": "HaveAHardTime",
+ "state": true,
+ "label": "Have a Hard Time"
+ }
+ },
{
"Bool": {
"name": "ThrowBabyWithBathwater",
diff --git a/harper-core/src/linting/have_a_hard_time.rs b/harper-core/src/linting/have_a_hard_time.rs
new file mode 100644
index 000000000..c7152cb0f
--- /dev/null
+++ b/harper-core/src/linting/have_a_hard_time.rs
@@ -0,0 +1,139 @@
+use crate::{
+ Dialect, Lint, Token,
+ expr::{Expr, SequenceExpr},
+ indefinite_article::{InitialSound, starts_with_vowel},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct HaveAHardTime {
+ expr: SequenceExpr,
+ dialect: Dialect,
+}
+
+impl HaveAHardTime {
+ pub fn new(dialect: Dialect) -> Self {
+ Self {
+ expr: SequenceExpr::word_set(&["have", "had", "has", "having"])
+ .then_optional(SequenceExpr::whitespace().t_set(&["extremely", "real"]))
+ .t_ws()
+ .then_word_seq(&["hard", "time"]),
+ dialect,
+ }
+ }
+}
+
+impl ExprLinter for HaveAHardTime {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let first_space_idx = 1;
+ let next_word_idx = first_space_idx + 1;
+
+ let suggestions = match starts_with_vowel(toks[next_word_idx].get_ch(src), self.dialect) {
+ Some(InitialSound::Consonant) => &[&['a', ' '][..]][..],
+ Some(InitialSound::Vowel) => &[&['a', 'n', ' '][..]][..],
+ Some(InitialSound::Either) => &[&['a', ' '][..], &['a', 'n', ' '][..]][..],
+ _ => return None,
+ };
+
+ Some(Lint {
+ span: toks[first_space_idx].span,
+ lint_kind: LintKind::Usage,
+ suggestions: suggestions
+ .iter()
+ .map(|s| Suggestion::InsertAfter(s.to_vec()))
+ .collect(),
+ message: "This idiom requires the indefinite article `a`.".to_string(),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Corrects `have hard time` to `have a hard time`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::HaveAHardTime;
+ use crate::{
+ Dialect,
+ linting::tests::{assert_no_lints, assert_suggestion_result},
+ };
+
+ #[test]
+ fn had() {
+ assert_suggestion_result(
+ "I also had hard time to investigate why debug(error) only shows stack traces, but no other visible properties",
+ HaveAHardTime::new(Dialect::American),
+ "I also had a hard time to investigate why debug(error) only shows stack traces, but no other visible properties",
+ );
+ }
+
+ #[test]
+ fn has() {
+ assert_suggestion_result(
+ "Typescript has hard time finding declaration file for petite-vue",
+ HaveAHardTime::new(Dialect::American),
+ "Typescript has a hard time finding declaration file for petite-vue",
+ );
+ }
+
+ #[test]
+ fn have() {
+ assert_suggestion_result(
+ "I have hard time running getMeasuringContext(text, optionsopt) function.",
+ HaveAHardTime::new(Dialect::American),
+ "I have a hard time running getMeasuringContext(text, optionsopt) function.",
+ );
+ }
+
+ #[test]
+ fn having() {
+ assert_suggestion_result(
+ "Instructions for those who are having hard time to install from scratch.",
+ HaveAHardTime::new(Dialect::American),
+ "Instructions for those who are having a hard time to install from scratch.",
+ );
+ }
+
+ #[test]
+ fn having_extremely() {
+ assert_suggestion_result(
+ "Bug: having extremely hard time converting html",
+ HaveAHardTime::new(Dialect::American),
+ "Bug: having an extremely hard time converting html",
+ );
+ }
+
+ #[test]
+ fn having_real() {
+ assert_suggestion_result(
+ "I am having real hard time integrating kalidokit (face+body tracking)",
+ HaveAHardTime::new(Dialect::American),
+ "I am having a real hard time integrating kalidokit (face+body tracking)",
+ );
+ }
+
+ // Oddities and potential false positives
+
+ #[test]
+ fn dont_flag_an_hard_time() {
+ assert_no_lints(
+ "This feature will have an hard time working well with the other ...",
+ HaveAHardTime::new(Dialect::American),
+ );
+ }
+
+ #[test]
+ fn dont_flag_some_hard_time() {
+ assert_no_lints(
+ "we had some hard time finding the right tk because 8.6 has a \"t\" suffix.",
+ HaveAHardTime::new(Dialect::American),
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index 913eadeeb..437a43f3f 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -108,6 +108,7 @@ use super::go_to_war::GoToWar;
use super::good_at::GoodAt;
use super::handful::Handful;
use super::handful_of_more::HandfulOfMore;
+use super::have_a_hard_time::HaveAHardTime;
use super::have_pronoun::HavePronoun;
use super::have_take_a_look::HaveTakeALook;
use super::hedging::Hedging;
@@ -942,6 +943,7 @@ impl LintGroup {
insert_expr_rule!(GoodAt);
insert_expr_rule!(Handful);
insert_expr_rule!(HandfulOfMore);
+ insert_expr_rule_with_dialect!(HaveAHardTime);
insert_expr_rule!(HavePronoun);
insert_struct_rule_with_dialect!(HaveTakeALook);
insert_expr_rule!(Hedging);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 256d6699a..56e57b188 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -104,6 +104,7 @@ mod go_to_war;
mod good_at;
mod handful;
mod handful_of_more;
+mod have_a_hard_time;
mod have_pronoun;
mod have_take_a_look;
mod hedging;
diff --git a/harper-desktop/src-tauri/Cargo.toml b/harper-desktop/src-tauri/Cargo.toml
index b5f2aed08..f7251dffe 100644
--- a/harper-desktop/src-tauri/Cargo.toml
+++ b/harper-desktop/src-tauri/Cargo.toml
@@ -2,7 +2,6 @@
name = "harper-desktop"
version = "2.4.0"
description = "A Tauri App"
-authors = ["you"]
edition = "2024"
publish = false