Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(core): create special rule for `hereby`
Elijah Potterf2640e4de894
diff --git a/harper-core/src/linting/hereby.rs b/harper-core/src/linting/hereby.rsnew file mode 100644index 000000000..2eceee279--- /dev/null+++ b/harper-core/src/linting/hereby.rs@@ -0,0 +1,65 @@+use crate::{+ patterns::{Pattern, SequencePattern},+ Token, TokenStringExt,+};++use super::{Lint, LintKind, PatternLinter, Suggestion};++pub struct Hereby {+ pattern: Box<dyn Pattern>,+}++impl Default for Hereby {+ fn default() -> Self {+ let pattern = SequencePattern::aco("here")+ .then_whitespace()+ .t_aco("by")+ .then_whitespace()+ .then_verb();++ Self {+ pattern: Box::new(pattern),+ }+ }+}++impl PatternLinter for Hereby {+ 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..3].span().unwrap();+ let orig_chars = span.get_content(source);+ Lint {+ span,+ lint_kind: LintKind::WordChoice,+ suggestions: vec![Suggestion::replace_with_match_case(+ "hereby".chars().collect(),+ orig_chars,+ )],+ message: "Did you mean the closed compound `hereby`?".to_owned(),+ ..Default::default()+ }+ }++ fn description(&self) -> &'static str {+ "`Here by` in some contexts should be `hereby`"+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::assert_suggestion_result;++ use super::Hereby;++ #[test]+ fn declare() {+ assert_suggestion_result(+ "I here by declare this state to be free.",+ Hereby::default(),+ "I hereby declare this state to be free.",+ );+ }+}diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex e7e8c0462..3a56567e7 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -17,6 +17,7 @@ use super::correct_number_suffix::CorrectNumberSuffix;use super::despite_of::DespiteOf;use super::dot_initialisms::DotInitialisms;use super::ellipsis_length::EllipsisLength;+use super::hereby::Hereby;use super::lets_confusion::LetsConfusion;use super::likewise::Likewise;use super::linking_verbs::LinkingVerbs;@@ -171,6 +172,7 @@ macro_rules! create_lint_group_config {}create_lint_group_config!(+ Hereby => true,Likewise => true,CompoundNouns => true,Regardless => true,diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 131e6d09e..463faad26 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -14,6 +14,7 @@ mod dashes;mod despite_of;mod dot_initialisms;mod ellipsis_length;+mod hereby;mod lets_confusion;mod likewise;mod linking_verbs;@@ -65,6 +66,7 @@ pub use currency_placement::CurrencyPlacement;pub use despite_of::DespiteOf;pub use dot_initialisms::DotInitialisms;pub use ellipsis_length::EllipsisLength;+pub use hereby::Hereby;pub use lets_confusion::LetsConfusion;pub use likewise::Likewise;pub use linking_verbs::LinkingVerbs;