Skip to content

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

fix(linting): flag bellow for below before determiners and numbers (#4540) (#4561)

yi111b23bb8c5e83d
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 6ef668edf..c8b7810dc 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -6228,6 +6228,13 @@
"label": "Behind The Scenes"
}
},
+ {
+ "Bool": {
+ "name": "BellowBelow",
+ "state": true,
+ "label": "Bellow Below"
+ }
+ },
{
"Bool": {
"name": "Cant",
diff --git a/harper-core/src/linting/bellow_below.rs b/harper-core/src/linting/bellow_below.rs
new file mode 100644
index 000000000..1d66bbef6
--- /dev/null
+++ b/harper-core/src/linting/bellow_below.rs
@@ -0,0 +1,221 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr, SpelledNumberExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct BellowBelow {
+ expr: SequenceExpr,
+}
+
+impl Default for BellowBelow {
+ fn default() -> Self {
+ Self {
+ // `bellow` (to shout) is intransitive, so a determiner (including
+ // possessive determiners like `their`, `his`, and `its`) or a number
+ // right after it almost always means `below` was intended.
+ // Only the exact word is matched: `below` is not inflectable, so an
+ // inflected form of `bellow` can never be a misspelling of it.
+ expr: SequenceExpr::aco("bellow").t_ws().then_any_of([
+ Box::new(|tok: &Token, _: &[char]| tok.kind.is_determiner()) as Box<dyn Expr>,
+ Box::new(SequenceExpr::number()),
+ Box::new(SpelledNumberExpr),
+ ]),
+ }
+ }
+}
+
+impl ExprLinter for BellowBelow {
+ type Unit = Chunk;
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let verb_span = toks.first()?.span;
+ let verb_chars = verb_span.get_content(src);
+
+ Some(Lint {
+ span: verb_span,
+ lint_kind: LintKind::Malapropism,
+ suggestions: vec![Suggestion::replace_with_match_case_str("below", verb_chars)],
+ message: "`Bellow` means to shout. You probably mean `below`.".to_owned(),
+ ..Default::default()
+ })
+ }
+
+ fn description(&self) -> &str {
+ "Looks for `bellow` wrongly used when `below` is intended."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::{bellow_below::BellowBelow, tests::assert_no_lints};
+
+ use super::BellowBelow as Rule;
+ use crate::linting::tests::assert_suggestion_result;
+
+ #[test]
+ fn correct_bellow_the_table() {
+ assert_suggestion_result(
+ "Going bellow the table",
+ Rule::default(),
+ "Going below the table",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_the_surface() {
+ assert_suggestion_result(
+ "The submarine descended bellow the surface",
+ Rule::default(),
+ "The submarine descended below the surface",
+ );
+ }
+
+ #[test]
+ fn correct_scroll_bellow_the_fold() {
+ assert_suggestion_result(
+ "Scroll bellow the fold to continue reading",
+ Rule::default(),
+ "Scroll below the fold to continue reading",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_their_target() {
+ assert_suggestion_result(
+ "Profits fell bellow their target this quarter",
+ Rule::default(),
+ "Profits fell below their target this quarter",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_his_knees() {
+ assert_suggestion_result(
+ "The water only came up to just bellow his knees",
+ Rule::default(),
+ "The water only came up to just below his knees",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_its_rim() {
+ assert_suggestion_result(
+ "Fill the jar to just bellow its rim",
+ Rule::default(),
+ "Fill the jar to just below its rim",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_the_stairs() {
+ assert_suggestion_result(
+ "She stored the boxes bellow the stairs",
+ Rule::default(),
+ "She stored the boxes below the stairs",
+ );
+ }
+
+ #[test]
+ fn correct_sentence_initial_case() {
+ assert_suggestion_result(
+ "Bellow the winter average, the lake froze solid",
+ Rule::default(),
+ "Below the winter average, the lake froze solid",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_a_threshold() {
+ assert_suggestion_result(
+ "Do not let the pressure drop bellow a safe threshold",
+ Rule::default(),
+ "Do not let the pressure drop below a safe threshold",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_digit() {
+ assert_suggestion_result(
+ "Readings bellow 5 were discarded as noise",
+ Rule::default(),
+ "Readings below 5 were discarded as noise",
+ );
+ }
+
+ #[test]
+ fn correct_descended_bellow_digit() {
+ assert_suggestion_result(
+ "The divers descended bellow 30 meters",
+ Rule::default(),
+ "The divers descended below 30 meters",
+ );
+ }
+
+ #[test]
+ fn correct_bellow_spelled_number() {
+ assert_suggestion_result(
+ "Keep the solution bellow five degrees",
+ Rule::default(),
+ "Keep the solution below five degrees",
+ );
+ }
+
+ #[test]
+ fn allow_verb_at_sentence_end() {
+ assert_no_lints("He bellowed.", BellowBelow::default());
+ }
+
+ #[test]
+ fn allow_verb_with_prepositional_phrase() {
+ assert_no_lints("She bellows with rage.", BellowBelow::default());
+ }
+
+ #[test]
+ fn allow_verb_with_adverb() {
+ assert_no_lints(
+ "Bulls bellow loudly during mating season.",
+ BellowBelow::default(),
+ );
+ }
+
+ #[test]
+ fn allow_verb_with_direct_object() {
+ assert_no_lints(
+ "The sergeant bellowed orders across the parade ground.",
+ BellowBelow::default(),
+ );
+ }
+
+ #[test]
+ fn allow_noun_a_bellow() {
+ assert_no_lints("He let out a bellow.", BellowBelow::default());
+ }
+
+ #[test]
+ fn allow_noun_possessive_bellow() {
+ assert_no_lints(
+ "The bull's bellow echoed across the valley.",
+ BellowBelow::default(),
+ );
+ }
+
+ #[test]
+ fn allow_noun_bellows_instrument() {
+ assert_no_lints("The blacksmith worked the bellows.", BellowBelow::default());
+ }
+
+ #[test]
+ fn allow_inflected_bellowing() {
+ assert_no_lints("The wind was bellowing all night.", BellowBelow::default());
+ }
+
+ #[test]
+ fn allow_correct_below() {
+ assert_no_lints("Going below the table", BellowBelow::default());
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index bc28d7727..750e2c61a 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -40,6 +40,7 @@ use super::bare_bones::BareBones;
use super::barely_un::BarelyUn;
use super::be_allowed::BeAllowed;
use super::behind_the_scenes::BehindTheScenes;
+use super::bellow_below::BellowBelow;
use super::best_of_all_time::BestOfAllTime;
use super::better_off_served::BetterOffServed;
use super::boring_words::BoringWords;
@@ -664,6 +665,7 @@ impl LintGroup {
insert_expr_rule_with_dict!(BarelyUn);
insert_expr_rule!(BeAllowed);
insert_expr_rule!(BehindTheScenes);
+ insert_expr_rule!(BellowBelow);
insert_struct_rule!(BestOfAllTime);
insert_expr_rule!(BetterOffServed);
insert_expr_rule!(BoringWords);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 156c0debc..6f122da9d 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -37,6 +37,7 @@ mod barely_un;
mod be_adjective_confusions;
mod be_allowed;
mod behind_the_scenes;
+mod bellow_below;
mod best_of_all_time;
mod better_off_served;
mod boring_words;