Skip to content

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

feat(core): more rules

Elijah Potterfaa5ae9186a5
diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dict
index e373f5464..c9899f6b4 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -26744,7 +26744,8 @@ heyday/1SM
hf/
hgt/1
hgwy/1
-hi/15SD
+hi/15D
+his/8
hiatus/1MS
hibachi/1MS
hibernate/4GNDS
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 2398451da..24c41e896 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -32,8 +32,13 @@ use super::merge_words::MergeWords;
use super::multiple_sequential_pronouns::MultipleSequentialPronouns;
use super::nobody::Nobody;
use super::number_suffix_capitalization::NumberSuffixCapitalization;
+use super::phrase_corrections::BaitedBreath;
+use super::phrase_corrections::BareInMind;
+use super::phrase_corrections::EludedTo;
use super::phrase_corrections::FaceFirst;
use super::phrase_corrections::FastPaste;
+use super::phrase_corrections::MutePoint;
+use super::phrase_corrections::OtherThen;
use super::phrase_corrections::StateOfTheArt;
use super::phrase_corrections::WantBe;
use super::phrase_corrections::{
@@ -41,6 +46,7 @@ use super::phrase_corrections::{
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,
SupposedTo, ThanOthers, ThatChallenged, TurnItOff,
};
+use super::pique_interest::PiqueInterest;
use super::plural_conjugate::PluralConjugate;
use super::possessive_your::PossessiveYour;
use super::pronoun_contraction::PronounContraction;
@@ -58,6 +64,7 @@ use super::terminating_conjunctions::TerminatingConjunctions;
use super::that_which::ThatWhich;
use super::unclosed_quotes::UnclosedQuotes;
use super::use_genitive::UseGenitive;
+use super::was_aloud::WasAloud;
use super::whereas::Whereas;
use super::wrong_quotes::WrongQuotes;
use super::{CurrencyPlacement, Lint, Linter, NoOxfordComma, OxfordComma};
@@ -182,6 +189,13 @@ macro_rules! create_lint_group_config {
}
create_lint_group_config!(
+ MutePoint => true,
+ PiqueInterest => true,
+ BareInMind => true,
+ BaitedBreath => true,
+ EludedTo => true,
+ OtherThen => true,
+ WasAloud => true,
HyphenateNumberDay => true,
FaceFirst => true,
LeftRightHand => true,
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 707597f43..f9269e767 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -35,6 +35,7 @@ mod number_suffix_capitalization;
mod oxford_comma;
mod pattern_linter;
mod phrase_corrections;
+mod pique_interest;
mod plural_conjugate;
mod possessive_your;
mod pronoun_contraction;
@@ -50,6 +51,7 @@ mod terminating_conjunctions;
mod that_which;
mod unclosed_quotes;
mod use_genitive;
+mod was_aloud;
mod whereas;
mod wrong_quotes;
@@ -91,8 +93,13 @@ pub use nobody::Nobody;
pub use number_suffix_capitalization::NumberSuffixCapitalization;
pub use oxford_comma::OxfordComma;
pub use pattern_linter::PatternLinter;
+pub use phrase_corrections::BaitedBreath;
+pub use phrase_corrections::BareInMind;
+pub use phrase_corrections::EludedTo;
pub use phrase_corrections::FaceFirst;
pub use phrase_corrections::FastPaste;
+pub use phrase_corrections::MutePoint;
+pub use phrase_corrections::OtherThen;
pub use phrase_corrections::StateOfTheArt;
pub use phrase_corrections::WantBe;
pub use phrase_corrections::{
@@ -100,6 +107,7 @@ pub use phrase_corrections::{
LetAlone, LoAndBehold, NeedHelp, NoLonger, OfCourse, SneakingSuspicion, SpecialAttention,
SupposedTo, ThanOthers, ThatChallenged, TurnItOff,
};
+pub use pique_interest::PiqueInterest;
pub use plural_conjugate::PluralConjugate;
pub use possessive_your::PossessiveYour;
pub use pronoun_contraction::PronounContraction;
@@ -118,6 +126,7 @@ pub use terminating_conjunctions::TerminatingConjunctions;
pub use that_which::ThatWhich;
pub use unclosed_quotes::UnclosedQuotes;
pub use use_genitive::UseGenitive;
+pub use was_aloud::WasAloud;
pub use whereas::Whereas;
pub use wrong_quotes::WrongQuotes;
diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rs
index a4f675a0e..933325f73 100644
--- a/harper-core/src/linting/phrase_corrections.rs
+++ b/harper-core/src/linting/phrase_corrections.rs
@@ -105,6 +105,43 @@ create_linter_map_phrase!(
"Ensures `face first` is correctly hyphenated as `face-first` when used before `into`."
);
+create_linter_map_phrase!(
+ OtherThen,
+ ExactPhrase::from_phrase("other then"),
+ "other than",
+ "Did you mean `other than`?",
+ "Corrects the misuse of `other then` to `other than`."
+);
+
+create_linter_map_phrase!(
+ EludedTo,
+ ExactPhrase::from_phrase("eluded to"),
+ "alluded to",
+ "Did you mean `alluded to`?",
+ "Corrects `eluded to` to `alluded to` in contexts referring to indirect references."
+);
+
+create_linter_map_phrase!(
+ BaitedBreath,
+ ExactPhrase::from_phrase("baited breath"),
+ "bated breath",
+ "Did you mean `bated breath`?",
+ "Ensures `bated breath` is written correctly, as `baited breath` is incorrect."
+);
+
+create_linter_map_phrase!(
+ BareInMind,
+ ExactPhrase::from_phrase("bare in mind"),
+ "bear in mind",
+ "Did you mean `bear in mind`?",
+ "Ensures the phrase `bear in mind` is used correctly instead of `bare in mind`."
+);
+
+create_linter_map_phrase!(MutePoint, ExactPhrase::from_phrase("mute point"),
+ "moot point",
+ "Did you mean `moot point`?",
+ "Ensures `moot point` is used instead of `mute point`, as `moot` means debatable or irrelevant.");
+
#[cfg(test)]
mod tests {
use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
diff --git a/harper-core/src/linting/pique_interest.rs b/harper-core/src/linting/pique_interest.rs
new file mode 100644
index 000000000..1579452b4
--- /dev/null
+++ b/harper-core/src/linting/pique_interest.rs
@@ -0,0 +1,73 @@
+use crate::{
+ patterns::{Pattern, SequencePattern},
+ Token,
+};
+
+use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+pub struct PiqueInterest {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for PiqueInterest {
+ fn default() -> Self {
+ let pattern = SequencePattern::aco("peak")
+ .then_whitespace()
+ .then_singular_subject()
+ .then_whitespace()
+ .t_aco("interest");
+
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+}
+
+impl PatternLinter for PiqueInterest {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {
+ let span = matched_tokens[0].span;
+
+ Lint {
+ span,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::replace_with_match_case(
+ "pique".chars().collect(),
+ matched_tokens[0].span.get_content(source),
+ )],
+ message: "Did you mean `pique` instead of `peak`?".to_owned(),
+ priority: 31,
+ }
+ }
+
+ fn description(&self) -> &'static str {
+ "Ensures `pique interest` is used correctly instead of `peak interest`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::PiqueInterest;
+ use crate::linting::tests::assert_suggestion_result;
+
+ #[test]
+ fn corrects_peak_interest() {
+ assert_suggestion_result(
+ "The story managed to peak his interest.",
+ PiqueInterest::default(),
+ "The story managed to pique his interest.",
+ );
+ }
+
+ #[test]
+ fn does_not_correct_unrelated_peak() {
+ assert_suggestion_result(
+ "He reached the peak of the mountain.",
+ PiqueInterest::default(),
+ "He reached the peak of the mountain.",
+ );
+ }
+}
diff --git a/harper-core/src/linting/was_aloud.rs b/harper-core/src/linting/was_aloud.rs
new file mode 100644
index 000000000..6bdb4076f
--- /dev/null
+++ b/harper-core/src/linting/was_aloud.rs
@@ -0,0 +1,89 @@
+use super::{Lint, LintKind, PatternLinter};
+use crate::linting::Suggestion;
+use crate::patterns::{Pattern, SequencePattern, WordSet};
+use crate::Token;
+use crate::TokenStringExt;
+
+pub struct WasAloud {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for WasAloud {
+ fn default() -> Self {
+ let pattern = SequencePattern::default()
+ .then_word_set(WordSet::all(&["was", "were"]))
+ .then_whitespace()
+ .then_exact_word("aloud");
+
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+}
+
+impl PatternLinter for WasAloud {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {
+ let verb = matched_tokens[0].span.get_content_string(source);
+
+ Lint {
+ span: matched_tokens.span().unwrap(),
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::replace_with_match_case(
+ format!("{} allowed", verb).chars().collect(),
+ matched_tokens[0].span.get_content(source),
+ )],
+ message: format!("Did you mean `{verb} allowed`?"),
+ priority: 31,
+ }
+ }
+
+ fn description(&self) -> &'static str {
+ "Ensures `was aloud` and `were aloud` are corrected to `was allowed` or `were allowed` when referring to permission."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::WasAloud;
+ use crate::linting::tests::assert_suggestion_result;
+
+ #[test]
+ fn corrects_was_aloud() {
+ assert_suggestion_result(
+ "He was aloud to enter the room.",
+ WasAloud::default(),
+ "He was allowed to enter the room.",
+ );
+ }
+
+ #[test]
+ fn corrects_were_aloud() {
+ assert_suggestion_result(
+ "They were aloud to participate.",
+ WasAloud::default(),
+ "They were allowed to participate.",
+ );
+ }
+
+ #[test]
+ fn does_not_correct_proper_use_of_aloud() {
+ assert_suggestion_result(
+ "She read the passage aloud to the class.",
+ WasAloud::default(),
+ "She read the passage aloud to the class.",
+ );
+ }
+
+ #[test]
+ fn does_not_flag_unrelated_text() {
+ assert_suggestion_result(
+ "The concert was loud and exciting.",
+ WasAloud::default(),
+ "The concert was loud and exciting.",
+ );
+ }
+}