Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): use POS tags for `PronounKnew` accuracy (#1413)
Elijah Potter677a0f2a9eda
diff --git a/harper-core/src/linting/pronoun_knew.rs b/harper-core/src/linting/pronoun_knew.rsindex 626f91bf1..637c09724 100644--- a/harper-core/src/linting/pronoun_knew.rs+++ b/harper-core/src/linting/pronoun_knew.rs@@ -1,3 +1,5 @@+use harper_brill::UPOS;+use crate::expr::Expr;use crate::expr::LongestMatchOf;use crate::expr::SequenceExpr;@@ -21,12 +23,16 @@ impl Default for PronounKnew {// 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() {+ if !tok.kind.is_upos(UPOS::PRON) {+ return false;+ }++ if tok.kind.is_possessive_determiner() {return false;}let pronorm = tok.span.get_content_string(source).to_lowercase();- let excluded = ["its", "his", "her", "every", "something", "nothing"];+ let excluded = ["every", "something", "nothing"];!excluded.contains(&&*pronorm)};@@ -136,4 +142,68 @@ mod tests {fn does_not_flag_with_nothing_1298() {assert_lint_count("This is nothing new.", PronounKnew::default(), 0);}++ #[test]+ fn issue_1381_tricks() {+ assert_lint_count("To learn some new tricks.", PronounKnew::default(), 0);+ }++ #[test]+ fn issue_1381_template() {+ assert_lint_count(+ "Let's build this new template function.",+ PronounKnew::default(),+ 0,+ );+ }++ #[test]+ fn issue_1381_file() {+ assert_lint_count(+ "Move the function definition inside of that new file.",+ PronounKnew::default(),+ 0,+ );+ }++ #[test]+ fn fixes_i_knew_what() {+ assert_suggestion_result(+ "I new what to do.",+ PronounKnew::default(),+ "I knew what to do.",+ );+ }++ #[test]+ fn fixes_she_knew_what() {+ assert_suggestion_result(+ "She new what to do.",+ PronounKnew::default(),+ "She knew what to do.",+ );+ }++ #[test]+ fn flags_she_new_danger() {+ assert_lint_count("She new danger lurked nearby.", PronounKnew::default(), 1);+ }++ #[test]+ fn does_not_flag_with_this_new_template() {+ assert_lint_count(+ "Let's build this new template function.",+ PronounKnew::default(),+ 0,+ );+ }++ #[test]+ fn does_not_flag_with_that_new_file() {+ assert_lint_count(+ "Move the function definition inside of that new file.",+ PronounKnew::default(),+ 0,+ );+ }}diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.ymlindex ee78514c2..1d26da86f 100644--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml@@ -135,16 +135,6 @@ Suggest:-Lint: WordChoice (31 priority)-Message: |- 67 | have to ask them what the name of the country is, you know. Please, Ma’am, is- 68 | this New Zealand or Australia?” (and she tried to curtsey as she spoke—fancy- | ^~~ Did you mean “knew” (the past tense of “know”)?-Suggest:- - Replace with: “Knew”---Lint: Spelling (63 priority)Message: |68 | this New Zealand or Australia?” (and she tried to curtsey as she spoke—fancy