Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: don't change 'you' to 'your' if the previous word is a verb (#2390)
Andrew Dunbar55a179170641
diff --git a/harper-core/src/linting/possessive_your.rs b/harper-core/src/linting/possessive_your.rsindex 964674b19..0e9101a09 100644--- a/harper-core/src/linting/possessive_your.rs+++ b/harper-core/src/linting/possessive_your.rs@@ -33,7 +33,20 @@ impl ExprLinter for PossessiveYour {self.expr.as_ref()}- fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {+ fn match_to_lint_with_context(+ &self,+ matched_tokens: &[Token],+ source: &[char],+ ctx: Option<(&[Token], &[Token])>,+ ) -> Option<Lint> {+ // Is 'you' the object of a verb? (#1920)+ if let [.., v, ws] = ctx?.0+ && ws.kind.is_whitespace()+ && v.kind.is_verb()+ {+ return None;+ }+let span = matched_tokens.first()?.span;let orig_chars = span.get_content(source);@@ -65,7 +78,7 @@ mod tests {use super::PossessiveYour;#[test]- #[should_panic] // currently fails because comments is a homographs (verb or noun)+ #[ignore = "currently fails because comments is a homographs (verb or noun)"]fn your_comments() {assert_suggestion_result("You comments may end up in the documentation.",@@ -136,4 +149,22 @@ mod tests {PossessiveYour::default(),);}++ #[test]+ fn dont_flag_1919_brought_you() {+ assert_lint_count(+ "team who also brought you [BloodHound Enterprise](http://specterops.io/bloodhound-verview/).",+ PossessiveYour::default(),+ 0,+ );+ }++ #[test]+ fn dont_flag_1919_teaches_you() {+ assert_lint_count(+ "Teaches you PyTorch and many machine learning concepts in a hands-on, code-first way.",+ PossessiveYour::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 b13469986..7c2d8ba44 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@@ -1997,17 +1997,6 @@ Message: |-Lint: WordChoice (127 priority)-Message: |- 1545 | feeble voice: “I heard every word you fellows were saying.”- | ^~~ The possessive version of this word is more common in this context.-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Spelling (63 priority)Message: |1555 | great hurry; “and their names were Elsie, Lacie, and Tillie; and they lived atdiff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.ymlindex 1fd24a6ff..b961fc476 100644--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml@@ -1009,17 +1009,6 @@ Suggest:-Lint: WordChoice (127 priority)-Message: |- 806 | “That dog?” He looked at it admiringly. “That dog will cost you ten dollars.”- | ^~~ The possessive version of this word is more common in this context.-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Style (31 priority)Message: |819 | We drove over to Fifth Avenue, warm and soft, almost pastoral, on the summer@@ -1773,18 +1762,6 @@ Suggest:-Lint: WordChoice (127 priority)-Message: |- 1428 | “I was in the Sixteenth until June nineteen-eighteen. I knew I’d seen you- | ^~~ The possessive version of this word is more common in this context.- 1429 | somewhere before.”-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Enhancement (31 priority)Message: |1457 | “I thought you knew, old sport. I’m afraid I’m not a very good host.”@@ -3035,17 +3012,6 @@ Message: |-Lint: WordChoice (127 priority)-Message: |- 1951 | “I’ll tell you God’s truth.” His right hand suddenly ordered divine retribution- | ^~~ The possessive version of this word is more common in this context.-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Readability (127 priority)Message: |1974 | “After that I lived like a young rajah in all the capitals of Europe—Paris,@@ -4405,17 +4371,6 @@ Suggest:-Lint: WordChoice (127 priority)-Message: |- 2968 | “I’m all out of practice, you see. I told you I couldn’t play. I’m all out of- | ^~~ The possessive version of this word is more common in this context.-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Repetition (63 priority)Message: |2968 | “I’m all out of practice, you see. I told you I couldn’t play. I’m all out of@@ -5752,17 +5707,6 @@ Suggest:-Lint: WordChoice (127 priority)-Message: |- 4115 | “I told you I went there,” said Gatsby.- | ^~~ The possessive version of this word is more common in this context.-Suggest:- - Replace with: “your”- - Replace with: “you're a”- - Replace with: “you're an”---Lint: Repetition (63 priority)Message: |4115 | “I told you I went there,” said Gatsby.