Skip to content

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

feat: we see us → we see each other (#4802)

Andrew Dunbar6d20dfa1d13c
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 16fdffc15..0f0e1e98e 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -4328,6 +4328,13 @@
"label": "Went Ahead and Agreement"
}
},
+ {
+ "Bool": {
+ "name": "WeSeeUs",
+ "state": true,
+ "label": "We See Us"
+ }
+ },
{
"Bool": {
"name": "WillContain",
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index e99fd3be4..27f323c51 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -341,6 +341,7 @@ use super::vicious_loop::{ViciousCircle, ViciousCircleOrCycle, ViciousCycle};
use super::waist_waste::WaistWaste;
use super::was_aloud::WasAloud;
use super::way_too_adjective::WayTooAdjective;
+use super::we_see_us::WeSeeUs;
use super::web_scraping::WebScraping;
use super::well_educated::WellEducated;
use super::went_ahead_and_agreement::WentAheadAndAgreement;
@@ -982,6 +983,7 @@ impl LintGroup {
insert_expr_rule!(WaistWaste);
insert_expr_rule!(WasAloud);
insert_expr_rule!(WayTooAdjective);
+ insert_expr_rule!(WeSeeUs);
insert_expr_rule!(WellEducated);
insert_expr_rule_with_dict!(WentAheadAndAgreement);
insert_expr_rule!(Whereas);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index fbb5c40ab..3d3581cc1 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -361,6 +361,7 @@ mod vicious_loop;
mod waist_waste;
mod was_aloud;
mod way_too_adjective;
+mod we_see_us;
mod web_scraping;
mod weir_rules;
mod well_educated;
diff --git a/harper-core/src/linting/we_see_us.rs b/harper-core/src/linting/we_see_us.rs
new file mode 100644
index 000000000..af7f0e7ce
--- /dev/null
+++ b/harper-core/src/linting/we_see_us.rs
@@ -0,0 +1,189 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+ patterns::WordSet,
+};
+
+pub struct WeSeeUs {
+ expr: SequenceExpr,
+}
+
+impl Default for WeSeeUs {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::aco("we")
+ .t_ws()
+ .then_any_of([
+ Box::new(WordSet::new(["see", "saw"])) as Box<dyn Expr>,
+ Box::new(
+ SequenceExpr::word_set([
+ "can",
+ "could",
+ "may",
+ "might",
+ "must",
+ "shall",
+ "should",
+ "will",
+ "would",
+ "can't",
+ "couldn't",
+ "mightn't",
+ "mustn't",
+ "shan't",
+ "shouldn't",
+ "won't",
+ "wouldn't",
+ "cannot",
+ ])
+ .t_ws()
+ .t_aco("see"),
+ ),
+ Box::new(SequenceExpr::word_set(["have", "had"]).t_ws().t_aco("seen")),
+ Box::new(SequenceExpr::word_seq(&["are", "seeing"])),
+ ])
+ .t_ws()
+ .t_aco("us"),
+ }
+ }
+}
+
+impl ExprLinter for WeSeeUs {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
+ // "us" and "Us" look like the pronoun, but "US" looks like the country
+ let us_tok = matched_tokens.last()?;
+ let us_ch = us_tok.get_ch(source);
+ if us_ch == ['U', 'S'] {
+ return None;
+ }
+ let span = us_tok.span;
+ let lint_kind = LintKind::Miscellaneous;
+ let suggestions = vec![Suggestion::replace_with_match_case_str(
+ "each other",
+ span.get_content(source),
+ )];
+ let message = "Did you mean `each other`?".to_owned();
+ Some(Lint {
+ span,
+ lint_kind,
+ suggestions,
+ message,
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Looks for the common Germanic phrase `we see us` and suggests `we see each other` as a replacement."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
+
+ use super::WeSeeUs;
+
+ #[test]
+ fn see() {
+ assert_suggestion_result(
+ "In the example below we see us using a schema to validate a configuration and setup defaults.",
+ WeSeeUs::default(),
+ "In the example below we see each other using a schema to validate a configuration and setup defaults.",
+ );
+ }
+
+ #[test]
+ fn saw() {
+ assert_suggestion_result(
+ "From time to time we saw us in front of meaningless stack traces.",
+ WeSeeUs::default(),
+ "From time to time we saw each other in front of meaningless stack traces.",
+ )
+ }
+
+ #[test]
+ fn can_see() {
+ assert_suggestion_result(
+ "We can see us chucking the nodes or in this case, we most likely have to give it back to them",
+ WeSeeUs::default(),
+ "We can see each other chucking the nodes or in this case, we most likely have to give it back to them",
+ )
+ }
+
+ #[test]
+ fn cant_see() {
+ assert_suggestion_result(
+ "On the list endpoints, we can't see us ever leaving the older (current) endpoints behind",
+ WeSeeUs::default(),
+ "On the list endpoints, we can't see each other ever leaving the older (current) endpoints behind",
+ )
+ }
+
+ #[test]
+ fn should_see() {
+ assert_suggestion_result(
+ "If we can see shadows on the ground, we should see us making shadows.",
+ WeSeeUs::default(),
+ "If we can see shadows on the ground, we should see each other making shadows.",
+ )
+ }
+
+ #[test]
+ fn will_see() {
+ assert_suggestion_result(
+ "we will see us through others and we will connect our experiences with testimonies of people",
+ WeSeeUs::default(),
+ "we will see each other through others and we will connect our experiences with testimonies of people",
+ );
+ }
+
+ #[test]
+ fn have_seen() {
+ assert_suggestion_result(
+ "We have seen us almost every Day for the last 5 years.",
+ WeSeeUs::default(),
+ "We have seen each other almost every Day for the last 5 years.",
+ )
+ }
+
+ #[test]
+ fn had_seen() {
+ assert_suggestion_result(
+ "We are very lucky about the fact that we had seen us in 2009, while we were spending our vacation with you.",
+ WeSeeUs::default(),
+ "We are very lucky about the fact that we had seen each other in 2009, while we were spending our vacation with you.",
+ )
+ }
+
+ #[test]
+ fn are_seeing() {
+ assert_suggestion_result(
+ "We are seeing us through their eyes.",
+ WeSeeUs::default(),
+ "We are seeing each other through their eyes.",
+ )
+ }
+
+ #[test]
+ fn dont_flag_see_us_caps() {
+ assert_no_lints(
+ "From the array, above we see US customers are listed as \"USA\"",
+ WeSeeUs::default(),
+ )
+ }
+
+ #[test]
+ fn dont_flag_can_see_us_caps() {
+ assert_no_lints(
+ "We can see US is the largest contributor of netflix",
+ WeSeeUs::default(),
+ )
+ }
+}