Skip to content

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

feat(core): created linter for #426

Elijah Potter0fff589a41c8
diff --git a/harper-core/src/linting/let_us_redundancy.rs b/harper-core/src/linting/let_us_redundancy.rs
new file mode 100644
index 000000000..ef85b0fe1
--- /dev/null
+++ b/harper-core/src/linting/let_us_redundancy.rs
@@ -0,0 +1,55 @@
+use crate::{
+ patterns::{Pattern, SequencePattern, WordSet},
+ Token, TokenStringExt,
+};
+
+use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+pub struct LetUsRedundancy {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for LetUsRedundancy {
+ fn default() -> Self {
+ let pattern = SequencePattern::aco("let's")
+ .then_whitespace()
+ .then_word_set(WordSet::all(&["us", "me"]));
+
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+}
+
+impl PatternLinter for LetUsRedundancy {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Lint {
+ Lint {
+ span: matched_tokens[1..3].span().unwrap(),
+ lint_kind: LintKind::Repetition,
+ suggestions: vec![Suggestion::Remove],
+ message: "`let's` stands for `let us`, so including another pronoun is redundant."
+ .to_owned(),
+ priority: 31,
+ }
+ }
+
+ fn description(&self) -> &'static str {
+ "Many are not aware that the contraction `let's` is short for `let us`. As a result, many will incorrectly use it before a pronoun, such as in the phrase `let's us do`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::assert_suggestion_result;
+
+ use super::LetUsRedundancy;
+
+ #[test]
+ fn issue_426() {
+ assert_suggestion_result("let's us do", LetUsRedundancy::default(), "let's do");
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index fdbaa5c2f..578dc5a5e 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -8,6 +8,7 @@ use super::capitalize_personal_pronouns::CapitalizePersonalPronouns;
use super::correct_number_suffix::CorrectNumberSuffix;
use super::dot_initialisms::DotInitialisms;
use super::ellipsis_length::EllipsisLength;
+use super::let_us_redundancy::LetUsRedundancy;
use super::linking_verbs::LinkingVerbs;
use super::long_sentences::LongSentences;
use super::matcher::Matcher;
@@ -187,7 +188,8 @@ create_lint_group_config!(
PluralConjugate => false,
OxfordComma => true,
PronounContraction => true,
- CurrencyPlacement => true
+ CurrencyPlacement => true,
+ LetUsRedundancy => true
);
impl<T: Dictionary + Default> Default for LintGroup<T> {
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 6eae137e3..4a50b09b3 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -7,6 +7,7 @@ mod currency_placement;
mod dashes;
mod dot_initialisms;
mod ellipsis_length;
+mod let_us_redundancy;
mod linking_verbs;
mod lint;
mod lint_group;
@@ -40,6 +41,7 @@ pub use correct_number_suffix::CorrectNumberSuffix;
pub use currency_placement::CurrencyPlacement;
pub use dot_initialisms::DotInitialisms;
pub use ellipsis_length::EllipsisLength;
+pub use let_us_redundancy::LetUsRedundancy;
pub use linking_verbs::LinkingVerbs;
pub use lint::{Lint, LintKind, Suggestion};
pub use lint_group::{LintGroup, LintGroupConfig};