Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): false-positives (#1660)
Elijah Potter57c1a2d270ac
diff --git a/harper-core/src/expr/sequence_expr.rs b/harper-core/src/expr/sequence_expr.rsindex e2a54dc39..73a802f14 100644--- a/harper-core/src/expr/sequence_expr.rs+++ b/harper-core/src/expr/sequence_expr.rs@@ -255,6 +255,9 @@ impl SequenceExpr {// Determinersgen_then_from_is!(determiner);+ gen_then_from_is!(demonstrative_determiner);+ gen_then_from_is!(quantifier);+ gen_then_from_is!(non_quantifier_determiner);/// Push an [`IndefiniteArticle`] to the end of the operation list.pub fn then_indefinite_article(self) -> Self {diff --git a/harper-core/src/linting/its_possessive.rs b/harper-core/src/linting/its_possessive.rsindex 86e6acf68..1924daf73 100644--- a/harper-core/src/linting/its_possessive.rs+++ b/harper-core/src/linting/its_possessive.rs@@ -48,6 +48,7 @@ impl Default for ItsPossessive {.t_ws().then_unless(UPOSSet::new(&[UPOS::PART,+ UPOS::ADP,UPOS::NOUN,UPOS::PRON,UPOS::SCONJ,@@ -313,4 +314,12 @@ mod tests {ItsPossessive::default(),);}++ #[test]+ fn allow_issue_1658() {+ assert_no_lints(+ "It's kind of a nuisance, but it will work.",+ ItsPossessive::default(),+ );+ }}diff --git a/harper-core/src/linting/missing_preposition.rs b/harper-core/src/linting/missing_preposition.rsindex 011115311..1165fbe52 100644--- a/harper-core/src/linting/missing_preposition.rs+++ b/harper-core/src/linting/missing_preposition.rs@@ -20,7 +20,7 @@ impl Default for MissingPreposition {.then(AnchorStart.or_longest(SequenceExpr::default()- .then(UPOSSet::new(&[UPOS::DET]))+ .then_non_quantifier_determiner().t_ws(),),)@@ -138,4 +138,12 @@ mod tests {MissingPreposition::default(),);}++ #[test]+ fn allows_issue_1585() {+ assert_no_lints(+ "Each agent has specific tools and tasks orchestrated through a crew workflow.",+ MissingPreposition::default(),+ );+ }}diff --git a/harper-core/src/linting/pronoun_inflection_be.rs b/harper-core/src/linting/pronoun_inflection_be.rsindex 5b948a39c..a7537b37b 100644--- a/harper-core/src/linting/pronoun_inflection_be.rs+++ b/harper-core/src/linting/pronoun_inflection_be.rs@@ -6,6 +6,7 @@ use crate::expr::All;use crate::expr::AnchorStart;use crate::expr::ExprMap;use crate::expr::{Expr, SequenceExpr};+use crate::patterns::NominalPhrase;use crate::patterns::UPOSSet;use super::Suggestion;@@ -30,35 +31,55 @@ impl PronounInflectionBe {.then_third_person_singular_pronoun().then_optional(mod_term.clone()).t_ws()- .t_aco("are");+ .t_aco("are")+ .t_any()+ .then_unless(NominalPhrase);map.insert(are, "is");+ let are_at_start = SequenceExpr::default()+ .then(AnchorStart)+ .then_third_person_singular_pronoun()+ .then_optional(mod_term.clone())+ .t_ws()+ .t_aco("are")+ .t_any()+ .t_any();+ map.insert(are_at_start, "is");+let arent = SequenceExpr::default().then_third_person_singular_pronoun().then_optional(mod_term.clone()).t_ws()- .t_aco("aren't");+ .t_aco("aren't")+ .t_any()+ .t_any();map.insert(arent, "isn't");let is = SequenceExpr::default().then_third_person_plural_pronoun().then_optional(mod_term.clone()).t_ws()- .t_aco("is");+ .t_aco("is")+ .t_any()+ .t_any();map.insert(is, "are");let isnt = SequenceExpr::default().then_third_person_plural_pronoun().then_optional(mod_term.clone()).t_ws()- .t_aco("isn't");+ .t_aco("isn't")+ .t_any()+ .t_any();map.insert(isnt, "aren't");let was = SequenceExpr::default().then(|tok: &Token, _: &[char]| tok.kind.is_first_person_plural_pronoun()).then_optional(mod_term.clone()).t_ws()- .t_aco("was");+ .t_aco("was")+ .t_any()+ .t_any();map.insert(was, "were");// Special case for second and third-person@@ -69,7 +90,9 @@ impl PronounInflectionBe {}).then_optional(mod_term.clone()).t_ws()- .t_aco("was");+ .t_aco("was")+ .t_any()+ .t_any();map.insert(was_third, "were");let were = SequenceExpr::default()@@ -80,7 +103,10 @@ impl PronounInflectionBe {}).then_optional(mod_term.clone()).t_ws()- .t_aco("were");+ .t_aco("were")+ .t_any()+ .t_any();+map.insert(were, "was");let map = Lrc::new(map);@@ -108,7 +134,7 @@ impl ExprLinter for PronounInflectionBe {}fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {- let span = matched_tokens.last()?.span;+ let span = matched_tokens.get(matched_tokens.len() - 3)?.span;// Determine the correct inflection of "be".let correct = self.map.lookup(0, matched_tokens, source)?;@@ -134,7 +160,7 @@ impl ExprLinter for PronounInflectionBe {#[cfg(test)]mod tests {- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};use super::PronounInflectionBe;@@ -376,4 +402,12 @@ mod tests {"because he is tired.",);}++ #[test]+ fn allow_behind_him() {+ assert_no_lints(+ "Behind him are new shadows.",+ PronounInflectionBe::default(),+ );+ }}diff --git a/harper-core/tests/text/linters/Difficult sentences.snap.yml b/harper-core/tests/text/linters/Difficult sentences.snap.ymlindex 4b6168fa8..d4b5a771c 100644--- a/harper-core/tests/text/linters/Difficult sentences.snap.yml+++ b/harper-core/tests/text/linters/Difficult sentences.snap.yml@@ -307,15 +307,6 @@ Suggest:-Lint: Agreement (31 priority)-Message: |- 426 | What's the time? – It's quarter to four in the afternoon (or 3:45 pm).- | ^~~~ Prefer the possessive pronoun `its` here to denote ownership.-Suggest:- - Replace with: “Its”---Lint: Spelling (63 priority)Message: |443 | With their reputation on the line, they decided to fire their PR team.