Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): ignore inflections of `be` in compound noun rule (#2281)
Elijah Potter5d7bbeefc9bb
diff --git a/harper-core/src/expr/mod.rs b/harper-core/src/expr/mod.rsindex 952ef5031..51b8833ce 100644--- a/harper-core/src/expr/mod.rs+++ b/harper-core/src/expr/mod.rs@@ -155,6 +155,7 @@ wherepub trait OwnedExprExt {fn or(self, other: impl Expr + 'static) -> FirstMatchOf;fn and(self, other: impl Expr + 'static) -> All;+ fn and_not(self, other: impl Expr + 'static) -> All;fn or_longest(self, other: impl Expr + 'static) -> LongestMatchOf;}@@ -172,6 +173,11 @@ whereAll::new(vec![Box::new(self), Box::new(other)])}+ /// Returns an expression that matches only if the current one matches and the expression contained in `other` does not.+ fn and_not(self, other: impl Expr + 'static) -> All {+ self.and(UnlessStep::new(other, |_tok: &Token, _src: &[char]| true))+ }+/// Returns an expression that matches the longest of the current one or the expression contained in `other`.////// If you don't need the longest match, prefer using the short-circuiting [`Self::or()`] instead.diff --git a/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs b/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rsindex 56a47d47d..6b2045a7b 100644--- a/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs+++ b/harper-core/src/linting/compound_nouns/compound_noun_after_det_adj.rs@@ -1,7 +1,9 @@use crate::expr::All;use crate::expr::Expr;use crate::expr::MergeableWords;+use crate::expr::OwnedExprExt;use crate::expr::SequenceExpr;+use crate::patterns::InflectionOfBe;use crate::{CharStringExt, TokenStringExt, linting::ExprLinter};use super::{Lint, LintKind, Suggestion, is_content_word, predicate};@@ -31,7 +33,7 @@ impl Default for CompoundNounAfterDetAdj {.t_ws().then(is_content_word).t_ws()- .then(is_content_word);+ .then(is_content_word.and_not(InflectionOfBe::default()));let split_expr = Lrc::new(MergeableWords::new(|meta_closed, meta_open| {predicate(meta_closed, meta_open)diff --git a/harper-core/tests/run_tests.rs b/harper-core/tests/run_tests.rsindex 61b8df5e0..ca46220a2 100644--- a/harper-core/tests/run_tests.rs+++ b/harper-core/tests/run_tests.rs@@ -89,6 +89,7 @@ create_test!(misc_closed_compound_clean.md, 0, Dialect::American);create_test!(yogurt_british_clean.md, 0, Dialect::British);create_test!(issue_1581.md, 0, Dialect::British);create_test!(issue_2054.md, 6, Dialect::British);+create_test!(issue_1988.md, 0, Dialect::American);create_test!(issue_2054_clean.md, 0, Dialect::British);create_test!(issue_1873.md, 0, Dialect::British);create_test!(issue_2233.md, 0, Dialect::American);diff --git a/harper-core/tests/test_sources/issue_1988.md b/harper-core/tests/test_sources/issue_1988.mdnew file mode 100644index 000000000..187611b90--- /dev/null+++ b/harper-core/tests/test_sources/issue_1988.md@@ -0,0 +1 @@+When this test is run, it returns a result.diff --git a/harper-core/tests/text/linters/The Constitution of the United States.snap.yml b/harper-core/tests/text/linters/The Constitution of the United States.snap.ymlindex 4df3d006a..2dcd5fcc0 100644--- a/harper-core/tests/text/linters/The Constitution of the United States.snap.yml+++ b/harper-core/tests/text/linters/The Constitution of the United States.snap.yml@@ -225,16 +225,6 @@ Message: |-Lint: WordChoice (63 priority)-Message: |- 89 | third Class at the Expiration of the sixth Year, so that one third may be- | ^~~~~~ Did you mean the closed compound noun “maybe”?- 90 | chosen every second Year; and when vacancies happen in the representation of-Suggest:- - Replace with: “maybe”---Lint: Readability (127 priority)Message: |96 | No Person shall be a Senator who shall not have attained to the Age of thirty