Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): don't flag a compound noun followed by a modal verb (#4630)
Yunus Ozenb5b007a635ee
diff --git a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs b/harper-core/src/linting/phrasal_verb_as_compound_noun.rsindex 4a8054c1b..5517cd9ed 100644--- a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs+++ b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs@@ -57,6 +57,7 @@ enum Context {ItsFollowedByThatOrWhich,ItsActuallyPartOfANounPhrase,ItsFollowedByVerb,+ ItsFollowedByAModalVerb,}impl PhrasalVerbAsCompoundNoun {@@ -202,6 +203,18 @@ impl PhrasalVerbAsCompoundNoun {return Err(Why::Contextual(Context::ItsFollowedByThatOrWhich));}+ // At the start, a modal verb after it means it's the subject, so it's a noun:+ // "setup can optionally install Hopper". After another word it can be a phrasal+ // verb ending a clause: "people that don't clean up can and will be banned".+ if maybe_prev_tok.is_none()+ && let Some(next_tok) = maybe_next_tok+ && next_tok.get_ch(source).eq_any_ignore_ascii_case_str(&[+ "can", "could", "may", "might", "must", "shall", "should", "will", "would",+ ])+ {+ return Err(Why::Contextual(Context::ItsFollowedByAModalVerb));+ }+// If the compound noun is followed by another noun, check for larger compound nouns.if let Some(next_tok) = maybe_next_tok.filter(|tok| tok.kind.is_noun())&& next_tok.get_ch(source).eq_any_ignore_ascii_case_str(@@ -808,4 +821,32 @@ mod tests {test_linter(),);}++ #[test]+ fn dont_flag_setup_before_modal_issue_4627() {+ assert_no_lints(+ "setup can optionally install Hopper with approval",+ test_linter(),+ );+ }++ #[test]+ fn dont_flag_compound_noun_before_other_modals() {+ assert_no_lints("Cleanup will remove the cache.", test_linter());+ assert_no_lints("Backup should run nightly.", test_linter());+ }++ #[test]+ fn flag_phrasal_verb_ending_a_clause_before_a_modal() {+ assert_suggestion_result(+ "People that don't cleanup can and will be banned from the space.",+ test_linter(),+ "People that don't clean up can and will be banned from the space.",+ );+ assert_suggestion_result(+ "Couples that decide to breakup can still choose to remain good friends.",+ test_linter(),+ "Couples that decide to break up can still choose to remain good friends.",+ );+ }}