Skip to content

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

feat: xyz are the one → xyz are the ones (#4686)

Andrew Dunbar6686732be77f
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 5a98860e0..a162d8bd4 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -3776,6 +3776,13 @@
"label": "Is Been Aux Sequence"
}
},
+ {
+ "Bool": {
+ "name": "ItAreTheOne",
+ "state": true,
+ "label": "It are the One"
+ }
+ },
{
"Bool": {
"name": "KnowNothingVerb",
diff --git a/harper-core/src/linting/it_are_the_one.rs b/harper-core/src/linting/it_are_the_one.rs
new file mode 100644
index 000000000..9ab2d6126
--- /dev/null
+++ b/harper-core/src/linting/it_are_the_one.rs
@@ -0,0 +1,122 @@
+use crate::{
+ Lint, Token,
+ char_string::CharStringExt,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct ItAreTheOne {
+ expr: SequenceExpr,
+}
+
+impl Default for ItAreTheOne {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::default()
+ .then_word_except(&["you", "they"])
+ .t_ws()
+ .t_set(["are", "were"])
+ .t_ws()
+ .t_aco("the")
+ .t_ws()
+ .then_optional(SequenceExpr::aco("only").t_ws())
+ .t_aco("one")
+ .t_ws()
+ .t_set(["which", "who", "whose", "that", "whom"]),
+ }
+ }
+}
+
+impl ExprLinter for ItAreTheOne {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let span = toks
+ .get(if toks.get(6)?.get_ch(src).eq_str("only") {
+ 8
+ } else {
+ 6
+ })?
+ .span;
+
+ let mut one = span.get_content(src).to_vec();
+ one.push((*one.last()? as u8 + (b's' - b'e')) as char);
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Agreement,
+ suggestions: vec![Suggestion::ReplaceWith(one)],
+ message: "Since `are` is plural, `ones` also needs to be plural.".to_owned(),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "A linter skeleton for contributors to copy into `harper_core/src/linting/` and rename."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::assert_suggestion_result;
+
+ use super::ItAreTheOne;
+
+ #[test]
+ fn are_the_one_who() {
+ assert_suggestion_result(
+ "Amateurs are the one who argue about syntax.",
+ ItAreTheOne::default(),
+ "Amateurs are the ones who argue about syntax.",
+ );
+ }
+
+ #[test]
+ fn are_the_only_one_who() {
+ assert_suggestion_result(
+ "those approved addressed are the only one who can change the rate of the token",
+ ItAreTheOne::default(),
+ "those approved addressed are the only ones who can change the rate of the token",
+ );
+ }
+
+ #[test]
+ fn are_the_one_which() {
+ assert_suggestion_result(
+ "graphics and gfx folder are the one which have different svgs and jpg files",
+ ItAreTheOne::default(),
+ "graphics and gfx folder are the ones which have different svgs and jpg files",
+ );
+ }
+
+ #[test]
+ fn were_the_only_one_that() {
+ assert_suggestion_result(
+ "SGN were the only one that actually sent me a sensible map",
+ ItAreTheOne::default(),
+ "SGN were the only ones that actually sent me a sensible map",
+ );
+ }
+
+ #[test]
+ fn we_are_the_one_who() {
+ assert_suggestion_result(
+ "They call us Dremers, but we are the one who don't sleep.",
+ ItAreTheOne::default(),
+ "They call us Dremers, but we are the ones who don't sleep.",
+ );
+ }
+
+ #[test]
+ fn are_the_one_that() {
+ assert_suggestion_result(
+ "things you don't want to share are the one that would interest your friends the most",
+ ItAreTheOne::default(),
+ "things you don't want to share are the ones that would interest your friends the most",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index 81bd98d44..336b64f03 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -152,6 +152,7 @@ use super::in_stock::InStock;
use super::in_time_from_now::InTimeFromNow;
use super::inflected_verb_after_to::InflectedVerbAfterTo;
use super::interested_in::InterestedIn;
+use super::it_are_the_one::ItAreTheOne;
use super::it_looks_like_that::ItLooksLikeThat;
use super::its_contraction::ItsContraction;
use super::its_possessive::ItsPossessive;
@@ -784,6 +785,7 @@ impl LintGroup {
insert_expr_rule!(InTimeFromNow);
insert_struct_rule_with_dict!(InflectedVerbAfterTo);
insert_expr_rule!(InterestedIn);
+ insert_expr_rule!(ItAreTheOne);
insert_expr_rule!(ItLooksLikeThat);
insert_struct_rule!(ItsContraction);
insert_expr_rule!(ItsPossessive);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 8e8394936..eea604c1d 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -158,6 +158,7 @@ mod informal_laughter;
mod initialism_linter;
mod initialisms;
mod interested_in;
+mod it_are_the_one;
mod it_is;
mod it_looks_like_that;
mod it_would_be;