Skip to content

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

fix: "will of -> will have" false positives (#2226)

Lionel Karlen26760275cb52
diff --git a/harper-core/src/linting/modal_of.rs b/harper-core/src/linting/modal_of.rs
index 8936b8297..09213d86c 100644
--- a/harper-core/src/linting/modal_of.rs
+++ b/harper-core/src/linting/modal_of.rs
@@ -24,6 +24,17 @@ impl Default for ModalOf {
.t_aco("of"),
);
+ // "will of" is a false positive if "will" is a noun
+ // "The will of the many"
+ let noun_will_of_naive = Lrc::new(
+ SequenceExpr::default()
+ .then_word_set(&["the", "a"])
+ .then_whitespace()
+ .t_aco("will")
+ .then_whitespace()
+ .t_aco("of"),
+ );
+
let ws_course = Lrc::new(SequenceExpr::default().then_whitespace().t_aco("course"));
let modal_of_course = Lrc::new(
@@ -52,6 +63,7 @@ impl Default for ModalOf {
Box::new(anyword_might_of_course),
Box::new(modal_of_course),
Box::new(anyword_might_of),
+ Box::new(noun_will_of_naive),
Box::new(modal_of),
])),
}
@@ -299,4 +311,19 @@ mod tests {
fn catches_mixed_case_could_of_put() {
assert_lint_count("... for now you could of Put ...", ModalOf::default(), 1);
}
+
+ #[test]
+ fn doesnt_catch_noun_will_of() {
+ assert_lint_count("the will of the many", ModalOf::default(), 0);
+ }
+
+ #[test]
+ fn doesnt_catch_noun_will_of_edgecase() {
+ assert_lint_count("he sent us a will of his", ModalOf::default(), 0);
+ }
+
+ #[test]
+ fn catch_modal_will_of() {
+ assert_lint_count("that will of an impact", ModalOf::default(), 1);
+ }
}