Skip to content

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

fix: no longer prompt to change "new" to "knew" after "its", "his", "her" (#1293)

Andrew Dunbar7931306c783d
diff --git a/harper-core/src/linting/pronoun_knew.rs b/harper-core/src/linting/pronoun_knew.rs
index 3721368fb..88eb150ed 100644
--- a/harper-core/src/linting/pronoun_knew.rs
+++ b/harper-core/src/linting/pronoun_knew.rs
@@ -8,15 +8,30 @@ pub struct PronounKnew {
pattern: Box<dyn crate::patterns::Pattern>,
}
+trait PronounKnewExt {
+ fn then_pronoun(self) -> Self;
+}
+
impl Default for PronounKnew {
fn default() -> Self {
+ // The pronoun that would occur before a verb would be a subject pronoun.
+ // But "its" commonly occurs before "new" and is a possessive pronoun. (Much more commonly a determiner)
+ // Since "his" and "her" are possessive and object pronouns respectively, we ignore them too.
+ let pronoun_pattern = |tok: &Token, source: &[char]| {
+ if tok.kind.is_pronoun() {
+ let pronorm = tok.span.get_content_string(source).to_lowercase();
+ return pronorm != "its" && pronorm != "his" && pronorm != "her";
+ }
+ false
+ };
+
let pronoun_then_new = SequencePattern::default()
- .then_pronoun()
+ .then(pronoun_pattern)
.then_whitespace()
.then_any_capitalization_of("new");
let pronoun_adverb_then_new = SequencePattern::default()
- .then_pronoun()
+ .then(pronoun_pattern)
.then_whitespace()
.then(WordSet::new(&["always", "never", "also", "often"]))
.then_whitespace()
@@ -92,4 +107,23 @@ mod tests {
fn does_not_flag_other_context() {
assert_lint_count("They called it \"new\".", PronounKnew::default(), 0);
}
+
+ #[test]
+ fn does_not_flag_with_its() {
+ assert_lint_count(
+ "In 2015, the US was paying on average around 2% for its new issuance bonds.",
+ PronounKnew::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn does_not_flag_with_his() {
+ assert_lint_count("His new car is fast.", PronounKnew::default(), 0);
+ }
+
+ #[test]
+ fn does_not_flag_with_her() {
+ assert_lint_count("Her new car is fast.", PronounKnew::default(), 0);
+ }
}
diff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.yml
index 5a98cc53e..56d460241 100644
--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml
+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml
@@ -451,15 +451,6 @@ Message: |
-Lint: WordChoice (31 priority)
-Message: |
- 162 | He had changed since his New Haven years. Now he was a sturdy straw-haired man
- | ^~~ Did you mean “knew” (the past tense of “know”)?
-Suggest:
- - Replace with: “Knew”
-
-
-
Lint: Readability (127 priority)
Message: |
165 | appearance of always leaning aggressively forward. Not even the effeminate swank