mirror of
https://github.com/Automattic/harper.git
synced 2025-12-05 19:26:55 -06:00
fix(core): ignore inflections of be in compound noun rule (#2281)
This commit is contained in:
@@ -155,6 +155,7 @@ where
|
||||
pub 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 @@ where
|
||||
All::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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
1
harper-core/tests/test_sources/issue_1988.md
Normal file
1
harper-core/tests/test_sources/issue_1988.md
Normal file
@@ -0,0 +1 @@
|
||||
When this test is run, it returns a result.
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user