Skip to content

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

fix(core): edge case in `ItsPossessive` rule (#2857)

Elijah Potter594b58e3a64e
diff --git a/harper-core/src/linting/its_possessive.rs b/harper-core/src/linting/its_possessive.rs
index 1524bbcee..5cf923cf6 100644
--- a/harper-core/src/linting/its_possessive.rs
+++ b/harper-core/src/linting/its_possessive.rs
@@ -60,6 +60,22 @@ impl Default for ItsPossessive {
map.insert(start_of_sentence_noun, 0);
+ let start_of_sentence_noun_subject = SequenceExpr::with(AnchorStart)
+ .t_aco("it's")
+ .t_ws()
+ .then(
+ UPOSSet::new(&[UPOS::NOUN, UPOS::PROPN]).or(|tok: &Token, _: &[char]| {
+ tok.kind.as_number().is_some_and(|n| n.suffix.is_some())
+ || ((tok.kind.is_noun() || tok.kind.is_proper_noun())
+ && !tok.kind.is_adjective()
+ && !tok.kind.is_adverb())
+ }),
+ )
+ .t_ws()
+ .then(UPOSSet::new(&[UPOS::VERB, UPOS::AUX]));
+
+ map.insert(start_of_sentence_noun_subject, 0);
+
let start_of_sentence_adjective = SequenceExpr::with(AnchorStart)
.t_aco("it's")
.t_ws()
@@ -202,6 +218,15 @@ mod tests {
);
}
+ #[test]
+ fn fixes_its_ancestor() {
+ assert_suggestion_result(
+ "It's ancestor is still around.",
+ ItsPossessive::default(),
+ "Its ancestor is still around.",
+ );
+ }
+
#[test]
fn device_reached_its_100th_cycle() {
assert_lint_count(
@@ -397,6 +422,11 @@ mod tests {
assert_no_lints("It's big enough.", ItsPossessive::default());
}
+ #[test]
+ fn allows_its_awesome() {
+ assert_no_lints("It's awesome.", ItsPossessive::default());
+ }
+
#[test]
fn flags_all_its_possessive_in_list() {
assert_lint_count(