Skip to content

Commit

Permalink
feat(core): created linter for #426
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 21, 2025
1 parent 1717342 commit 0fff589
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
55 changes: 55 additions & 0 deletions harper-core/src/linting/let_us_redundancy.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
4 changes: 3 additions & 1 deletion harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 2 additions & 0 deletions harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 0fff589

Please sign in to comment.