Skip to content

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

feat: have low standard → low standards (#4583)

Andrew Dunbar759288acd04f
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index d7529b269..2503de336 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -5025,6 +5025,13 @@
"label": "Hidden In"
}
},
+ {
+ "Bool": {
+ "name": "HighLowStandards",
+ "state": true,
+ "label": "High/Low Standards"
+ }
+ },
{
"Bool": {
"name": "HopHope",
diff --git a/harper-core/src/linting/high_low_standards.rs b/harper-core/src/linting/high_low_standards.rs
new file mode 100644
index 000000000..68ad61d93
--- /dev/null
+++ b/harper-core/src/linting/high_low_standards.rs
@@ -0,0 +1,156 @@
+use crate::{
+ CharStringExt, Lint, Token,
+ expr::{AnchorEnd, Expr, SequenceExpr},
+ linting::{
+ ExprLinter, LintKind, Suggestion,
+ expr_linter::{Chunk, find_the_only_token_matching},
+ },
+};
+
+pub struct HighLowStandards {
+ expr: SequenceExpr,
+}
+
+impl Default for HighLowStandards {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::word_set(["got", "had", "has", "have", "having"])
+ .then_optional(SequenceExpr::whitespace().then_degree_adverb())
+ .t_ws()
+ .t_set(["high", "low"])
+ .t_ws()
+ .t_aco("standard")
+ .then_any_of([
+ Box::new(AnchorEnd) as Box<dyn Expr>,
+ Box::new(SequenceExpr::whitespace().then(|t: &Token, s: &[char]| {
+ (t.kind.is_preposition() && !t.get_ch(s).eq_str("of"))
+ || t.get_ch(s)
+ .eq_any_ignore_ascii_case_str(&["and", "even", "when"])
+ })),
+ ]),
+ }
+ }
+}
+
+impl ExprLinter for HighLowStandards {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let span =
+ find_the_only_token_matching(toks, src, |t, _| t.get_ch(src).eq_str("standard"))?.span;
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Usage,
+ suggestions: vec![Suggestion::replace_with_match_case_str(
+ "standards",
+ span.get_content(src),
+ )],
+ message: "This idiom uses plural `standards`.".to_owned(),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Corrects `high/low standard` to `high/low standards` when `standard` is a noun."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
+
+ use super::HighLowStandards;
+
+ #[test]
+ fn at_end() {
+ assert_suggestion_result(
+ "I have low standard",
+ HighLowStandards::default(),
+ "I have low standards",
+ );
+ }
+
+ #[test]
+ fn followed_by_for() {
+ assert_suggestion_result(
+ "I have high standard for men",
+ HighLowStandards::default(),
+ "I have high standards for men",
+ );
+ }
+
+ #[test]
+ fn dont_flag_standard_deviation() {
+ assert_no_lints(
+ "It's very difficult for any model to predict accurately when trained with data having such high standard deviation.",
+ HighLowStandards::default(),
+ );
+ }
+
+ #[test]
+ fn dont_flag_followed_by_when() {
+ assert_suggestion_result(
+ "I tend to have high standard when answering questions.",
+ HighLowStandards::default(),
+ "I tend to have high standards when answering questions.",
+ );
+ }
+
+ #[test]
+ fn followed_by_comma() {
+ assert_suggestion_result(
+ "Most student would choose supervisor who doesn’t have high standard, but what i did is precisely the opposite.",
+ HighLowStandards::default(),
+ "Most student would choose supervisor who doesn’t have high standards, but what i did is precisely the opposite.",
+ );
+ }
+
+ #[test]
+ fn very_high() {
+ assert_suggestion_result(
+ "I picked a supervisor who has very high standard, strict, and very well detailed.",
+ HighLowStandards::default(),
+ "I picked a supervisor who has very high standards, strict, and very well detailed.",
+ );
+ }
+
+ #[test]
+ fn followed_by_and() {
+ assert_suggestion_result(
+ "Great way to tell you have low standard and can't detect latency.",
+ HighLowStandards::default(),
+ "Great way to tell you have low standards and can't detect latency.",
+ );
+ }
+
+ #[test]
+ fn dont_flag_standard_of_living() {
+ assert_no_lints(
+ "US has high standard of living, but it is not among the top 5 countreis with the highest minimum hourly-wage.",
+ HighLowStandards::default(),
+ );
+ }
+
+ #[test]
+ fn followed_by_on() {
+ assert_suggestion_result(
+ "We should also recognize the fact that, Swedes have very high standard on their expectation of English fluency.",
+ HighLowStandards::default(),
+ "We should also recognize the fact that, Swedes have very high standards on their expectation of English fluency.",
+ );
+ }
+
+ #[test]
+ fn followed_by_in() {
+ assert_suggestion_result(
+ "We have high standard in product manufacturing and foreign trade",
+ HighLowStandards::default(),
+ "We have high standards in product manufacturing and foreign trade",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index 8655e34f2..eaea6c826 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -134,6 +134,7 @@ use super::hedging::Hedging;
use super::hello_greeting::HelloGreeting;
use super::helped_past::HelpedPast;
use super::hereby::Hereby;
+use super::high_low_standards::HighLowStandards;
use super::hop_hope::HopHope;
use super::how_does_compared::HowDoesCompared;
use super::how_to::HowTo;
@@ -758,6 +759,7 @@ impl LintGroup {
insert_expr_rule!(HelloGreeting);
insert_expr_rule_with_dict!(HelpedPast);
insert_expr_rule!(Hereby);
+ insert_expr_rule!(HighLowStandards);
insert_struct_rule!(HopHope);
insert_expr_rule!(HowDoesCompared);
insert_expr_rule!(HowTo);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 0dfa3ddd1..c97922c1f 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -135,6 +135,7 @@ mod hedging;
mod hello_greeting;
mod helped_past;
mod hereby;
+mod high_low_standards;
mod hop_hope;
mod hope_youre;
mod how_does_compared;