Skip to content

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

feat: clown one's judgment → cloud one's judgement (#4725)

Andrew Dunbarf7ec1d9f4225
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index eb8d77e53..82ced5fd6 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -967,6 +967,13 @@
"label": "Client Or Server Side"
}
},
+ {
+ "Bool": {
+ "name": "CloudOnesJudgement",
+ "state": true,
+ "label": "Cloud One's Judgment/Judgement"
+ }
+ },
{
"Bool": {
"name": "CommitmentTo",
diff --git a/harper-core/src/linting/cloud_ones_judgement.rs b/harper-core/src/linting/cloud_ones_judgement.rs
new file mode 100644
index 000000000..b7b2c7c34
--- /dev/null
+++ b/harper-core/src/linting/cloud_ones_judgement.rs
@@ -0,0 +1,136 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct CloudOnesJudgement {
+ expr: SequenceExpr,
+}
+
+impl Default for CloudOnesJudgement {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::word_set(["clown", "clowned", "clowning", "clowns"])
+ .t_ws()
+ .then_possessive_determiner()
+ .t_ws()
+ .t_set(["judgement", "judgment", "judgements", "judgments"]),
+ }
+ }
+}
+
+impl ExprLinter for CloudOnesJudgement {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let span = toks.first()?.span;
+
+ let mut corr = span.get_content(src).to_vec();
+ corr[3] = ((corr[3] as u8) - (b'w' - b'u')) as char;
+ corr[4] = ((corr[4] as u8) - (b'n' - b'd')) as char;
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Malapropism,
+ suggestions: vec![Suggestion::ReplaceWith(corr)],
+ message: "Unless this is intentional wordplay, the correct verb is `cloud`.".to_owned(),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Corrects the malapropism `clown one's judgement` to `cloud one's judgement`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
+
+ use super::CloudOnesJudgement;
+
+ #[test]
+ fn clowned_your_judgement() {
+ assert_suggestion_result(
+ "I think the dark side of the force has clowned your judgement young Padawan.",
+ CloudOnesJudgement::default(),
+ "I think the dark side of the force has clouded your judgement young Padawan.",
+ );
+ }
+
+ #[test]
+ fn clown_his_judgement() {
+ assert_suggestion_result(
+ "...because he knows that the sarcophagus will only clown his judgement and he can actually get ahead...",
+ CloudOnesJudgement::default(),
+ "...because he knows that the sarcophagus will only cloud his judgement and he can actually get ahead...",
+ );
+ }
+
+ #[test]
+ fn clown_your_judgement() {
+ assert_suggestion_result(
+ "stop letting infatuation clown your judgement.",
+ CloudOnesJudgement::default(),
+ "stop letting infatuation cloud your judgement.",
+ );
+ }
+
+ #[test]
+ fn cloning_my_judgement() {
+ assert_suggestion_result(
+ "...cloning my judgement knew the genius would rise...",
+ CloudOnesJudgement::default(),
+ "...cloning my judgement knew the genius would rise...",
+ );
+ }
+
+ #[test]
+ fn clown_your_judgements() {
+ assert_suggestion_result(
+ "You Should Never Allow Your Emotions Clown Your Judgements Over Somebody",
+ CloudOnesJudgement::default(),
+ "You Should Never Allow Your Emotions Cloud Your Judgements Over Somebody",
+ );
+ }
+
+ #[test]
+ fn clown_our_judgment() {
+ assert_suggestion_result(
+ "know-it-all attitude is what can clown our judgment when we become more experienced",
+ CloudOnesJudgement::default(),
+ "know-it-all attitude is what can cloud our judgment when we become more experienced",
+ );
+ }
+
+ #[test]
+ fn clowns_his_judgment() {
+ assert_suggestion_result(
+ "Yoda accuses him of hatred and clowns his judgment, questioning why he came",
+ CloudOnesJudgement::default(),
+ "Yoda accuses him of hatred and clouds his judgment, questioning why he came",
+ );
+ }
+
+ #[test]
+ fn clowning_my_judgment() {
+ assert_suggestion_result(
+ "trying to make a public POTD was somehow clowning my judgment",
+ CloudOnesJudgement::default(),
+ "trying to make a public POTD was somehow clouding my judgment",
+ );
+ }
+
+ #[test]
+ fn dont_flag_coincidence() {
+ assert_no_lints(
+ "Same old from this clown. His judgment of talent the last few years is less than sub par.",
+ CloudOnesJudgement::default(),
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index 04db7f49d..60601835f 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -64,6 +64,7 @@ use super::chicken_and_egg::ChickenAndEgg;
use super::chock_full::ChockFull;
use super::claim_to_fame::ClaimToFame;
use super::close_tight_knit::CloseTightKnit;
+use super::cloud_ones_judgement::CloudOnesJudgement;
use super::code_in_write_in::CodeInWriteIn;
use super::comfortable_with::ComfortableWith;
use super::comma_fixes::CommaFixes;
@@ -702,6 +703,7 @@ impl LintGroup {
insert_expr_rule!(ChockFull);
insert_expr_rule!(ClaimToFame);
insert_expr_rule!(CloseTightKnit);
+ insert_expr_rule!(CloudOnesJudgement);
insert_expr_rule!(CodeInWriteIn);
insert_expr_rule!(ComfortableWith);
insert_struct_rule!(CommaFixes);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 639c6744a..ff38fc291 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -62,6 +62,7 @@ mod chock_full;
mod claim_to_fame;
mod close_tight_knit;
mod closed_compounds;
+mod cloud_ones_judgement;
mod code_in_write_in;
mod comfortable_with;
mod comma_fixes;