Skip to content

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

feat: implement "ticking time clock"

hippietrail3dd1c87f901e
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 1206155ef..920d68438 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -186,4 +186,31 @@ mod tests {
// Applying the suggestions should fix all the lints.
assert_lint_count(&transformed_str, linter, 0);
}
+
+ /// Runs a provided linter on text, applies the second suggestion from each
+ /// lint and asserts whether the result is equal to a given value.
+ pub fn assert_second_suggestion_result(
+ text: &str,
+ mut linter: impl Linter,
+ expected_result: &str,
+ ) {
+ let test = Document::new_markdown_default_curated(text);
+ let lints = linter.lint(&test);
+
+ let mut text: Vec<char> = text.chars().collect();
+
+ for lint in lints {
+ dbg!(&lint);
+ if let Some(sug) = lint.suggestions.get(1) {
+ sug.apply(lint.span, &mut text);
+ }
+ }
+
+ let transformed_str: String = text.iter().collect();
+
+ assert_eq!(transformed_str.as_str(), expected_result);
+
+ // Applying the suggestions should fix all the lints.
+ assert_lint_count(&transformed_str, linter, 0);
+ }
}
diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rs
index a7c6c4742..87ac335a0 100644
--- a/harper-core/src/linting/phrase_corrections.rs
+++ b/harper-core/src/linting/phrase_corrections.rs
@@ -603,7 +603,7 @@ pub fn lint_group() -> LintGroup {
"Use `haphazard` for randomness or lack of organization.",
"Corrects the eggcorn `half hazard` to `haphazard`, which properly means lacking organization or being random."
),
- "DayAndAge" => (
+ "DayAndAge" => (
["day in age"],
["day and age"],
"Use `day and age` for referring to the present time.",
@@ -615,6 +615,12 @@ pub fn lint_group() -> LintGroup {
"Use `nerve-racking` for something that causes anxiety or tension.",
"Corrects common misspellings and missing hyphen in `nerve-racking`."
),
+ "TickingTimeClock" => (
+ ["ticking time clock"],
+ ["ticking time bomb", "ticking clock"],
+ "Use `ticking time bomb` for disastrous consequences, otherwise avoid redundancy with just `ticking clock`.",
+ "Corrects `ticking time clock` to `ticking time bomb` for idiomatic urgency or `ticking clock` otherwise."
+ ),
});
group.set_all_rules_to(Some(true));
@@ -624,7 +630,9 @@ pub fn lint_group() -> LintGroup {
#[cfg(test)]
mod tests {
- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+ use crate::linting::tests::{
+ assert_lint_count, assert_second_suggestion_result, assert_suggestion_result,
+ };
use super::lint_group;
@@ -851,4 +859,22 @@ mod tests {
"It's nerve-racking to think about it because I have code inside the callback that resolves the member and somehow I feel like it's so ..",
);
}
+
+ #[test]
+ fn suggests_ticking_time_bomb() {
+ assert_suggestion_result(
+ "One element that can help up the stakes (and tension!) is a “ticking time clock.”",
+ lint_group(),
+ "One element that can help up the stakes (and tension!) is a “ticking time bomb.”",
+ );
+ }
+
+ #[test]
+ fn suggests_ticking_clock() {
+ assert_second_suggestion_result(
+ "The opportunity itself has a ticking time clock as all great opportunities do.",
+ lint_group(),
+ "The opportunity itself has a ticking clock as all great opportunities do.",
+ );
+ }
}