Skip to content

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

feat:interested at/into/on/with→interested in (#1809)

Andrew Dunbarbf445757b5a0
diff --git a/harper-core/src/linting/ask_no_preposition.rs b/harper-core/src/linting/ask_no_preposition.rs
index 36788235d..af852336a 100644
--- a/harper-core/src/linting/ask_no_preposition.rs
+++ b/harper-core/src/linting/ask_no_preposition.rs
@@ -21,7 +21,7 @@ impl Default for AskNoPreposition {
let pattern = SequenceExpr::default()
.then(verbs)
.then_whitespace()
- .then_exact_word("to")
+ .t_aco("to")
.then_whitespace()
.then(objs);
@@ -74,6 +74,15 @@ mod tests {
);
}
+ #[test]
+ fn flags_ask_all_caps() {
+ assert_suggestion_result(
+ "NORA ASKED TO US ABOUT THE CONCERT LINEUP.",
+ AskNoPreposition::default(),
+ "NORA ASKED US ABOUT THE CONCERT LINEUP.",
+ );
+ }
+
#[test]
fn flags_tell() {
assert_suggestion_result(
diff --git a/harper-core/src/linting/inflected_verb_after_to.rs b/harper-core/src/linting/inflected_verb_after_to.rs
index 1ab0c523b..097d54a7d 100644
--- a/harper-core/src/linting/inflected_verb_after_to.rs
+++ b/harper-core/src/linting/inflected_verb_after_to.rs
@@ -1,4 +1,5 @@
use super::{Lint, LintKind, Linter, Suggestion};
+use crate::char_string::CharStringExt;
use crate::spell::Dictionary;
use crate::{Document, Span, TokenStringExt};
@@ -30,7 +31,7 @@ impl<T: Dictionary> Linter for InflectedVerbAfterTo<T> {
continue;
}
let prep_to = document.get_span_content(&prep.span);
- if prep_to != ['t', 'o'] && prep_to != ['T', 'o'] {
+ if !prep_to.eq_ignore_ascii_case_chars(&['t', 'o']) {
continue;
}
diff --git a/harper-core/src/linting/interested_in.rs b/harper-core/src/linting/interested_in.rs
new file mode 100644
index 000000000..1666a97d7
--- /dev/null
+++ b/harper-core/src/linting/interested_in.rs
@@ -0,0 +1,166 @@
+use crate::{
+ CharStringExt, Token, TokenKind,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, Lint, LintKind, Suggestion},
+};
+
+pub struct InterestedIn {
+ expr: Box<dyn Expr>,
+}
+
+impl Default for InterestedIn {
+ fn default() -> Self {
+ let pattern = SequenceExpr::default()
+ .t_aco("interested")
+ .t_ws()
+ .then_kind_except(
+ TokenKind::is_preposition,
+ &["around", "for", "through", "to", "within"],
+ );
+
+ Self {
+ expr: Box::new(pattern),
+ }
+ }
+}
+
+impl ExprLinter for InterestedIn {
+ fn expr(&self) -> &dyn Expr {
+ self.expr.as_ref()
+ }
+
+ fn match_to_lint(&self, tokens: &[Token], source: &[char]) -> Option<Lint> {
+ let prep_span = tokens.last().unwrap().span;
+ let prep_chars = prep_span.get_content(source);
+
+ if prep_chars.eq_ignore_ascii_case_chars(&['i', 'n']) {
+ return None;
+ }
+
+ Some(Lint {
+ span: prep_span,
+ lint_kind: LintKind::Grammar,
+ suggestions: vec![Suggestion::replace_with_match_case(
+ "in".chars().collect(),
+ prep_chars,
+ )],
+ message: "The correct preposition to use with `interested` is `in`.".to_string(),
+ ..Default::default()
+ })
+ }
+
+ fn description(&self) -> &str {
+ "Ensures the correct preposition is used with the word `interested` (e.g. `interested in`)."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::InterestedIn;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ #[test]
+ fn fix_about() {
+ assert_suggestion_result(
+ "It suggests some useful programs the user could be interested about - NyarchLinux/NyarchWizard.",
+ InterestedIn::default(),
+ "It suggests some useful programs the user could be interested in - NyarchLinux/NyarchWizard.",
+ );
+ }
+
+ #[test]
+ fn dont_flag_around() {
+ assert_lint_count(
+ "We want to figure out why this is, and how to keep those interested around for longer.",
+ InterestedIn::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn fix_at() {
+ assert_suggestion_result(
+ "If someone is interested at the processed data, please email me.",
+ InterestedIn::default(),
+ "If someone is interested in the processed data, please email me.",
+ );
+ }
+
+ #[test]
+ #[ignore = "Requires more context because 'interested for now/for sure' are not errors"]
+ fn fix_for() {
+ assert_suggestion_result(
+ "but the user is only interested for the examples in one of the modes",
+ InterestedIn::default(),
+ "but the user is only interested in the examples in one of the modes",
+ );
+ }
+
+ #[test]
+ fn dont_flag_for_sure() {
+ assert_lint_count("I am interested for sure!", InterestedIn::default(), 0);
+ }
+
+ #[test]
+ fn fix_into() {
+ assert_suggestion_result(
+ "This is one of the first complex software I wrote, and it prefigures so much of the reasons why I was interested into working on designing HTML and CSS.",
+ InterestedIn::default(),
+ "This is one of the first complex software I wrote, and it prefigures so much of the reasons why I was interested in working on designing HTML and CSS.",
+ );
+ }
+
+ #[test]
+ fn fix_of() {
+ assert_suggestion_result(
+ "If you are interested of tinkering.",
+ InterestedIn::default(),
+ "If you are interested in tinkering.",
+ );
+ }
+
+ #[test]
+ fn fix_on() {
+ assert_suggestion_result(
+ "The creator of Photopea, a great free alternative to Photoshop, is not interested on making an offline version, so I took it upon myself to make it.",
+ InterestedIn::default(),
+ "The creator of Photopea, a great free alternative to Photoshop, is not interested in making an offline version, so I took it upon myself to make it.",
+ );
+ }
+
+ #[test]
+ fn dont_flag_through() {
+ assert_lint_count(
+ "I'm happy to help walk anyone interested through doing this",
+ InterestedIn::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn does_not_flag_to() {
+ assert_lint_count(
+ "Hi, As title suggest i am interested to know if we can run a custom model trained on yolov9 inference running on two GPU-s.",
+ InterestedIn::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn fix_with() {
+ assert_suggestion_result(
+ "no_std support (is anybody interested with this?)",
+ InterestedIn::default(),
+ "no_std support (is anybody interested in this?)",
+ );
+ }
+
+ #[test]
+ fn dont_flag_within() {
+ assert_lint_count(
+ "But with no one being interested within 8 months, what help would it be.",
+ InterestedIn::default(),
+ 0,
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index a2bfbc398..5cd9c9a93 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -56,6 +56,7 @@ use super::hyphenate_number_day::HyphenateNumberDay;
use super::i_am_agreement::IAmAgreement;
use super::in_on_the_cards::InOnTheCards;
use super::inflected_verb_after_to::InflectedVerbAfterTo;
+use super::interested_in::InterestedIn;
use super::its_contraction::ItsContraction;
use super::its_possessive::ItsPossessive;
use super::left_right_hand::LeftRightHand;
@@ -418,8 +419,6 @@ impl LintGroup {
insert_expr_rule!(Cant, true);
insert_struct_rule!(CapitalizePersonalPronouns, true);
insert_expr_rule!(ChockFull, true);
- insert_struct_rule!(PunctuationClusters, true);
- insert_struct_rule!(NoFrenchSpaces, true);
insert_struct_rule!(CommaFixes, true);
insert_struct_rule!(CompoundNouns, true);
insert_expr_rule!(Confident, true);
@@ -447,6 +446,7 @@ impl LintGroup {
insert_struct_rule!(HowTo, true);
insert_expr_rule!(HyphenateNumberDay, true);
insert_expr_rule!(IAmAgreement, true);
+ insert_expr_rule!(InterestedIn, true);
insert_struct_rule!(ItsContraction, true);
insert_struct_rule!(ItsPossessive, true);
insert_expr_rule!(LeftRightHand, true);
@@ -483,6 +483,7 @@ impl LintGroup {
insert_struct_rule!(PronounContraction, true);
insert_expr_rule!(PronounInflectionBe, true);
insert_struct_rule!(PronounKnew, true);
+ insert_struct_rule!(PunctuationClusters, true);
insert_expr_rule!(QuantifierNeedsOf, true);
insert_expr_rule!(RedundantAdditiveAdverbs, true);
insert_struct_rule!(RepeatedWords, true);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index afbffafea..20ff0a23e 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -53,6 +53,7 @@ mod in_on_the_cards;
mod inflected_verb_after_to;
mod initialism_linter;
mod initialisms;
+mod interested_in;
mod it_is;
mod it_would_be;
mod its_contraction;
@@ -86,7 +87,7 @@ mod noun_countability;
mod noun_verb_confusion;
mod number_suffix_capitalization;
mod of_course;
-pub mod on_floor;
+mod on_floor;
mod one_and_the_same;
mod open_compounds;
mod open_the_light;
@@ -184,6 +185,7 @@ pub use i_am_agreement::IAmAgreement;
pub use in_on_the_cards::InOnTheCards;
pub use inflected_verb_after_to::InflectedVerbAfterTo;
pub use initialism_linter::InitialismLinter;
+pub use interested_in::InterestedIn;
pub use its_contraction::ItsContraction;
pub use its_possessive::ItsPossessive;
pub use left_right_hand::LeftRightHand;