Skip to content

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

feat(core): added rules for stuff I saw in the wild

Elijah Potter55dce6c736a4
diff --git a/harper-core/src/linting/confident.rs b/harper-core/src/linting/confident.rs
new file mode 100644
index 000000000..ec88f6591
--- /dev/null
+++ b/harper-core/src/linting/confident.rs
@@ -0,0 +1,163 @@
+use crate::{
+ Token,
+ char_string::char_string,
+ patterns::{AnyCapitalization, OwnedPatternExt, Pattern, SequencePattern},
+};
+
+use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+pub struct Confident {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for Confident {
+ fn default() -> Self {
+ let pattern = SequencePattern::default()
+ .then(
+ (|tok: &Token, _source: &[char]| tok.kind.is_verb() || tok.kind.is_article())
+ .or(Box::new(AnyCapitalization::new(char_string!("very")))),
+ )
+ .then_whitespace()
+ .t_aco("confidant");
+
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+}
+
+impl PatternLinter for Confident {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
+ let span = matched_tokens.last()?.span;
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::ReplaceWith("confident".chars().collect())],
+ message: "Use the adjective.".to_owned(),
+ priority: 127,
+ })
+ }
+
+ fn description(&self) -> &'static str {
+ unimplemented!()
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::Confident;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ #[test]
+ fn describing_person_incorrect() {
+ assert_suggestion_result(
+ "She felt confidant about her presentation.",
+ Confident::default(),
+ "She felt confident about her presentation.",
+ );
+ }
+
+ #[test]
+ fn describing_person_correct() {
+ assert_lint_count(
+ "She felt confident about her presentation.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn certainty_incorrect() {
+ assert_suggestion_result(
+ "I am confidant the test results are accurate.",
+ Confident::default(),
+ "I am confident the test results are accurate.",
+ );
+ }
+
+ #[test]
+ fn certainty_correct() {
+ assert_lint_count(
+ "I am confident the test results are accurate.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn demeanor_incorrect() {
+ assert_suggestion_result(
+ "He walked to the stage with a confidant stride.",
+ Confident::default(),
+ "He walked to the stage with a confident stride.",
+ );
+ }
+
+ #[test]
+ fn demeanor_correct() {
+ assert_lint_count(
+ "He walked to the stage with a confident stride.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn professional_incorrect() {
+ assert_suggestion_result(
+ "You should sound confidant during job interviews.",
+ Confident::default(),
+ "You should sound confident during job interviews.",
+ );
+ }
+
+ #[test]
+ fn professional_correct() {
+ assert_lint_count(
+ "You should sound confident during job interviews.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn assured_tone_incorrect() {
+ assert_suggestion_result(
+ "Present your argument in a confidant, persuasive manner.",
+ Confident::default(),
+ "Present your argument in a confident, persuasive manner.",
+ );
+ }
+
+ #[test]
+ fn assured_tone_correct() {
+ assert_lint_count(
+ "Present your argument in a confident, persuasive manner.",
+ Confident::default(),
+ 0,
+ );
+ }
+
+ #[test]
+ fn extra_text_between() {
+ assert_suggestion_result(
+ "She felt very confidant about her presentation.",
+ Confident::default(),
+ "She felt very confident about her presentation.",
+ );
+ }
+
+ #[test]
+ fn linking_verb_was_confidant() {
+ assert_suggestion_result(
+ "She was confidant about her presentation.",
+ Confident::default(),
+ "She was confident about her presentation.",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 0532da45e..75db4c9d5 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -14,6 +14,7 @@ use super::boring_words::BoringWords;
use super::capitalize_personal_pronouns::CapitalizePersonalPronouns;
use super::chock_full::ChockFull;
use super::compound_nouns::CompoundNouns;
+use super::confident::Confident;
use super::correct_number_suffix::CorrectNumberSuffix;
use super::despite_of::DespiteOf;
use super::dot_initialisms::DotInitialisms;
@@ -253,6 +254,7 @@ impl LintGroup {
insert_struct_rule!(LetsConfusion, true);
insert_struct_rule!(DespiteOf, true);
insert_struct_rule!(ChockFull, true);
+ insert_struct_rule!(Confident, true);
insert_struct_rule!(Oxymorons, true);
insert_struct_rule!(Hedging, true);
insert_struct_rule!(ExpandTimeShorthands, true);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 5a0395b6f..89895c846 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -10,6 +10,7 @@ mod capitalize_personal_pronouns;
mod chock_full;
mod closed_compounds;
mod compound_nouns;
+mod confident;
mod correct_number_suffix;
mod currency_placement;
mod dashes;
@@ -72,6 +73,7 @@ pub use boring_words::BoringWords;
pub use capitalize_personal_pronouns::CapitalizePersonalPronouns;
pub use chock_full::ChockFull;
pub use compound_nouns::CompoundNouns;
+pub use confident::Confident;
pub use correct_number_suffix::CorrectNumberSuffix;
pub use currency_placement::CurrencyPlacement;
pub use despite_of::DespiteOf;
diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rs
index 4ef9a9035..1dd5774d6 100644
--- a/harper-core/src/linting/phrase_corrections.rs
+++ b/harper-core/src/linting/phrase_corrections.rs
@@ -370,7 +370,13 @@ pub fn lint_group() -> LintGroup {
["blanket statement"],
"Use the more idiomatic phrasing.",
"Corrects common errors in the phrase `blanket statement`."
- )
+ ),
+ "SpokeTooSoon" => (
+ ["spoke to soon"],
+ ["spoke too soon"],
+ "Use the adverb `too` instead.",
+ "Identifies common misuse of the preposition `to` in the phrase `spoke too soon`."
+ ),
});
group.set_all_rules_to(Some(true));