Skip to content

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

feat: flag verb agreement errors in questions (#4823)

mcampald9b094ccbec0
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 0f0e1e98e..39a06aa54 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -4091,6 +4091,13 @@
"label": "Quantifier Numeral Conflict"
}
},
+ {
+ "Bool": {
+ "name": "QuestionVerbAgreement",
+ "state": true,
+ "label": "Question Verb Agreement"
+ }
+ },
{
"Bool": {
"name": "ReadsAndWrites",
diff --git a/harper-core/src/linting/weir_rules/QuestionVerbAgreement/AreToIs.weir b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/AreToIs.weir
new file mode 100644
index 000000000..013dbd09c
--- /dev/null
+++ b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/AreToIs.weir
@@ -0,0 +1,41 @@
+expr wh [what, where, when, why, how, who, which]
+expr subj [he, she, it]
+# "But why are it and twitter the only whitelisted entries?" has a compound subject, which takes "are".
+expr after ![NOUN, PROPN, and, or]
+expr time [yesterday, today, tonight, tomorrow, now, then, there, here, last]
+expr main <[(@wh are @subj @time), (@wh are @subj @after), (@wh are @subj?), (@wh are @subj.), (are @subj PROG)], are>
+
+let message "The verb should agree with the subject: `is`."
+let description "Corrects `are` before `he`, `she` or `it` in questions, like `Where are it?`"
+let kind "Agreement"
+let scope "Sentence"
+let becomes "is"
+let strategy "MatchCase"
+
+# real sentences from GitHub issues and Hacker News
+test "Where are it in this new version?" "Where is it in this new version?"
+test "Where are it trying to get them from?" "Where is it trying to get them from?"
+test "Why are it looking for them?" "Why is it looking for them?"
+test "i saw it has permission,so where are it?" "i saw it has permission,so where is it?"
+test "Are it working?" "Is it working?"
+test "Why are it now the car companies who decide how it works?" "Why is it now the car companies who decide how it works?"
+# made-up sentences
+test "Where are she today?" "Where is she today?"
+test "What are he doing?" "What is he doing?"
+test "Why are she so late?" "Why is she so late?"
+# harder cases that must still be caught
+test "WHAT ARE HE SAYING?" "WHAT IS HE SAYING?"
+
+# correct text
+allows "What is he doing?"
+allows "Where are they now?"
+allows "What are his plans?"
+# real look-alikes that must not be flagged (Hacker News)
+allows "But why are it and twitter the only whitelisted entries?"
+allows "What are it's limitations?"
+# made-up look-alikes
+allows "Who are she and her team?"
+allows "Where are he and Ana?"
+allows "The odds are he will say yes."
+allows "Chances are it is fine."
+allows "Where are its docs?"
diff --git a/harper-core/src/linting/weir_rules/QuestionVerbAgreement/IsToAre.weir b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/IsToAre.weir
new file mode 100644
index 000000000..76a746f0e
--- /dev/null
+++ b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/IsToAre.weir
@@ -0,0 +1,46 @@
+expr wh [what, where, when, why, how, who, which]
+# "What is we use ..." is almost always a typo for "What if we ...", so a bare verb after
+# the subject doesn't count. "Why is you leaving early any different?" uses `you leaving`
+# as a gerund subject, so `you` only counts before an adjective, adverb or preposition.
+expr after [ADJ, ADV, ADP]
+expr ending [(we?), (we.), (they?), (they.), (you?), (you.)]
+expr time [yesterday, today, tonight, tomorrow, now, then, there, here, last]
+expr main <[(@wh is [we, they, you] @time), (@wh is [we, they] PROG), (@wh is [we, they, you] @after), (@wh is @ending), (is [we, they] PROG)], is>
+
+let message "The verb should agree with the subject: `are`."
+let description "Corrects `is` before `we`, `they` or `you` in questions, like `Why is they grey?`"
+let kind "Agreement"
+let scope "Sentence"
+let becomes "are"
+let strategy "MatchCase"
+
+# real sentences from GitHub issues and Ask Ubuntu
+test "Why is they grey?" "Why are they grey?"
+test "I remember there was a Broken Radio and Broken Flashlight but where is they?" "I remember there was a Broken Radio and Broken Flashlight but where are they?"
+test "how is they different and what are their differences." "how are they different and what are their differences."
+# made-up sentences
+test "Where is they now?" "Where are they now?"
+test "What is we waiting for?" "What are we waiting for?"
+test "Where is they going?" "Where are they going?"
+test "Is we going now?" "Are we going now?"
+test "Why is you so quiet?" "Why are you so quiet?"
+# harder cases that must still be caught
+test "WHAT IS WE DOING?" "WHAT ARE WE DOING?"
+test "So what is they saying, exactly?" "So what are they saying, exactly?"
+
+# correct text
+allows "What are we waiting for?"
+allows "How is it going?"
+allows "Here is what we are doing next."
+# real look-alikes that must not be flagged (Hacker News, GitHub)
+allows "The problem is we don't know a lot about the probabilities of abiogenesis."
+allows "Sure and the reason why is they were kids and their parents handled everything."
+allows "Does this help you understand what it is we're trying to do?"
+allows "But why is you visiting it okay, but others not?"
+allows "Why is they'll ambiguous?"
+allows "What is we use triangular pyramids instead of triangles?"
+allows "Why is you code panic'in?"
+# made-up look-alikes
+allows "Why is you leaving early any different?"
+allows "All I know is you are doing great."
+allows "What is, they asked, the point?"
diff --git a/harper-core/src/linting/weir_rules/QuestionVerbAgreement/WasToWere.weir b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/WasToWere.weir
new file mode 100644
index 000000000..0568a47e8
--- /dev/null
+++ b/harper-core/src/linting/weir_rules/QuestionVerbAgreement/WasToWere.weir
@@ -0,0 +1,40 @@
+expr wh [what, where, when, why, how, who, which]
+expr subj [we, they, you]
+# "How was you experience?" is a typo for "your", so a noun after the subject doesn't count.
+expr after ![NOUN, PROPN, and, or]
+expr time [yesterday, today, tonight, tomorrow, now, then, there, here, last]
+expr main <[(@wh was [we, they, you] @time), (@wh was @subj @after), (@wh was @subj?), (@wh was @subj.), (was @subj PROG)], was>
+
+let message "The verb should agree with the subject: `were`."
+let description "Corrects `was` before `we`, `they` or `you` in questions, like `Where was you?`"
+let kind "Agreement"
+let scope "Sentence"
+let becomes "were"
+let strategy "MatchCase"
+
+# real sentences from Hacker News, GitHub and Stack Overflow
+test "Where was you reading this?" "Where were you reading this?"
+test "what was you investigated for?" "what were you investigated for?"
+test "What was you showing during the waiting time?" "What were you showing during the waiting time?"
+test "What was they fired for?" "What were they fired for?"
+test "How was you able to get this code to run in floydhub?" "How were you able to get this code to run in floydhub?"
+# made-up sentences
+test "Where was you yesterday?" "Where were you yesterday?"
+test "Was you sleeping?" "Were you sleeping?"
+test "Why was we not told?" "Why were we not told?"
+# harder cases that must still be caught
+test "WHERE WAS YOU?" "WHERE WERE YOU?"
+test "And how was you feeling, after that?" "And how were you feeling, after that?"
+
+# correct text
+allows "Where were you yesterday?"
+allows "What was it you said?"
+allows "How was it?"
+# real look-alikes that must not be flagged (Hacker News)
+allows "How was you experience?"
+allows "What was they keyboard layout?"
+# made-up look-alikes
+allows "The reason was they forgot."
+allows "The plan was we would ship Friday."
+allows "My guess was you were busy."
+allows "That was what we needed."