Skip to content

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

feat: cool, calm, and collective → ... and collected (#4743)

Andrew Dunbarc56809b1ccbe
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 5c5b19a18..004c76c9d 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -4863,6 +4863,13 @@
"label": "Convenient Store"
}
},
+ {
+ "Bool": {
+ "name": "CoolCalmCollected",
+ "state": true,
+ "label": "Cool, Calm, Collected"
+ }
+ },
{
"Bool": {
"name": "CoursingThroughVeins",
diff --git a/harper-core/src/linting/cool_calm_collected.rs b/harper-core/src/linting/cool_calm_collected.rs
new file mode 100644
index 000000000..d25088f91
--- /dev/null
+++ b/harper-core/src/linting/cool_calm_collected.rs
@@ -0,0 +1,96 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Sentence},
+};
+
+pub struct CoolCalmCollected {
+ expr: SequenceExpr,
+}
+
+impl Default for CoolCalmCollected {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::aco("cool")
+ .then_optional_comma()
+ .t_ws()
+ .t_aco("calm")
+ .then_optional_comma()
+ .t_ws()
+ .t_aco("and")
+ .then_optional_comma()
+ .t_ws()
+ .t_aco("collective"),
+ }
+ }
+}
+
+impl ExprLinter for CoolCalmCollected {
+ type Unit = Sentence;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let span = toks.last()?.span;
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Malapropism,
+ suggestions: vec![Suggestion::replace_with_match_case_str(
+ "collected",
+ span.get_content(src),
+ )],
+ message: "`A `collective` is a kind of group. This idiom uses the word `collected`.`"
+ .to_owned(),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Corrects the malapropism `cool, calm, and collective` to use the correct `collected`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::assert_suggestion_result;
+
+ use super::CoolCalmCollected;
+
+ #[test]
+ fn first_comma_only() {
+ assert_suggestion_result(
+ "One thing that annoys me the most is when people say “cool, calm and collective”.",
+ CoolCalmCollected::default(),
+ "One thing that annoys me the most is when people say “cool, calm and collected”.",
+ );
+ }
+
+ #[test]
+ fn both_commas() {
+ assert_suggestion_result(
+ "\"Cool, calm, and collective\" is apart of a list of my favorite blundered sayings.",
+ CoolCalmCollected::default(),
+ "\"Cool, calm, and collected\" is apart of a list of my favorite blundered sayings.",
+ );
+ }
+
+ #[test]
+ fn only_comma_is_in_wrong_position() {
+ assert_suggestion_result(
+ "Your all cool calm and, collective With your shity paddles",
+ CoolCalmCollected::default(),
+ "Your all cool calm and, collected With your shity paddles",
+ );
+ }
+
+ #[test]
+ fn no_commas() {
+ assert_suggestion_result(
+ "But being able to stay cool calm and collective in that situation is extremely important in this job.",
+ CoolCalmCollected::default(),
+ "But being able to stay cool calm and collected in that situation is extremely important in this job.",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index eecb68702..bc1c901c0 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -73,6 +73,7 @@ use super::compound_nouns::CompoundNouns;
use super::compound_subject_i::CompoundSubjectI;
use super::confident::Confident;
use super::convenient_store::ConvenientStore;
+use super::cool_calm_collected::CoolCalmCollected;
use super::correct_number_suffix::CorrectNumberSuffix;
use super::crave_for::CraveFor;
use super::criteria_phenomena::CriteriaPhenomena;
@@ -995,6 +996,9 @@ impl LintGroup {
// Uses Sentence rather than Chunk
out.add("ConvenientStore", ConvenientStore::default());
+ // Uses Sentence rather than Chunk
+ out.add("CoolCalmCollected", CoolCalmCollected::default());
+
// Uses Sentence rather than Chunk
out.add("Damages", Damages::default());
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 9ef5a6af1..207ee67b3 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -71,6 +71,7 @@ mod compound_nouns;
mod compound_subject_i;
mod confident;
mod convenient_store;
+mod cool_calm_collected;
mod correct_number_suffix;
mod crave_for;
mod criteria_phenomena;