Skip to content

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

Hereby: require verb that is not also a noun (#3213)

Joaquin Huife23e24f0ed1
diff --git a/harper-core/src/linting/hereby.rs b/harper-core/src/linting/hereby.rs
index 9da7230e7..643565ce4 100644
--- a/harper-core/src/linting/hereby.rs
+++ b/harper-core/src/linting/hereby.rs
@@ -1,6 +1,6 @@
use crate::expr::Expr;
use crate::expr::SequenceExpr;
-use crate::{Token, TokenStringExt};
+use crate::{Token, TokenKind, TokenStringExt};
use super::{ExprLinter, Lint, LintKind, Suggestion};
use crate::linting::expr_linter::Chunk;
@@ -11,11 +11,14 @@ pub struct Hereby {
impl Default for Hereby {
fn default() -> Self {
+ // Require a verb that is not also a noun. Otherwise sentences like
+ // "I got here by skill" — where "skill" is a noun object of "by" —
+ // match because "skill" is tagged as both verb and noun.
let pattern = SequenceExpr::aco("here")
.then_whitespace()
.t_aco("by")
.then_whitespace()
- .then_verb();
+ .then_kind_is_but_is_not(TokenKind::is_verb, TokenKind::is_noun);
Self { expr: pattern }
}
@@ -62,4 +65,10 @@ mod tests {
"I hereby declare this state to be free.",
);
}
+
+ #[test]
+ fn allows_here_by_noun() {
+ use crate::linting::tests::assert_no_lints;
+ assert_no_lints("I got here by skill.", Hereby::default());
+ }
}