Skip to content

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

feat: support "over 1000+" in addition to "over 1000 plus" (#3885)

Andrew Dunbar56625b60c7da
diff --git a/harper-core/src/expr/sequence_expr.rs b/harper-core/src/expr/sequence_expr.rs
index 22b79ea26..eb9b3ded2 100644
--- a/harper-core/src/expr/sequence_expr.rs
+++ b/harper-core/src/expr/sequence_expr.rs
@@ -673,6 +673,7 @@ impl SequenceExpr {
gen_then_from_is!(single_prime);
gen_then_from_is!(double_prime);
gen_then_from_is!(backtick);
+ gen_then_from_is!(plus);
// Other
diff --git a/harper-core/src/linting/over_plus.rs b/harper-core/src/linting/over_plus.rs
index 651b06b82..196022948 100644
--- a/harper-core/src/linting/over_plus.rs
+++ b/harper-core/src/linting/over_plus.rs
@@ -24,8 +24,14 @@ impl Default for OverPlus {
.then_optional(
SequenceExpr::whitespace().t_set(&["thousand", "million", "billion"]),
)
- .t_ws()
- .then(SequenceExpr::aco("plus").but_not(Word::new_exact("PLUS")))
+ .then_any_of([
+ Box::new(
+ SequenceExpr::whitespace()
+ .t_aco("plus")
+ .but_not(Word::new_exact("PLUS")),
+ ) as Box<dyn Expr>,
+ Box::new(SequenceExpr::default().then_plus()),
+ ])
.but_not(SequenceExpr::anything().t_any().t_aco("one")),
}
}
@@ -49,11 +55,14 @@ impl ExprLinter for OverPlus {
return None;
}
- let slices = [toks.get_rel_slice(0, -3)?, &toks[2..]];
+ let token_slices = [
+ toks.get_rel_slice(0, -2 - (toks.last()?.kind.is_word() as isize))?,
+ &toks[2..],
+ ];
let span = toks.span()?;
- let suggestions = slices
+ let suggestions = token_slices
.iter()
.map(|t| {
Suggestion::replace_with_match_case(
@@ -221,4 +230,17 @@ mod tests {
OverPlus::default(),
);
}
+
+ #[test]
+ fn fix_plus_sign() {
+ assert_good_and_bad_suggestions(
+ "It took me over 1000+ blocks to make \"Livin' on a Prayer\" in Stardew Valley",
+ OverPlus::default(),
+ &[
+ "It took me over 1000 blocks to make \"Livin' on a Prayer\" in Stardew Valley",
+ "It took me 1000+ blocks to make \"Livin' on a Prayer\" in Stardew Valley",
+ ],
+ &[],
+ );
+ }
}