Skip to content

Commit

Permalink
feat(core): added more suggestion possibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 22, 2025
1 parent f7a9858 commit eec0123
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
22 changes: 19 additions & 3 deletions harper-core/src/linting/lets_confusion/let_us_redundancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,27 @@ impl PatternLinter for LetUsRedundancy {
self.pattern.as_ref()
}

fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Lint {
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {
let template = matched_tokens.span().unwrap().get_content(source);
let pronoun = matched_tokens
.last()
.unwrap()
.span
.get_content_string(source);

Lint {
span: matched_tokens[1..3].span().unwrap(),
span: matched_tokens.span().unwrap(),
lint_kind: LintKind::Repetition,
suggestions: vec![Suggestion::Remove],
suggestions: vec![
Suggestion::replace_with_match_case(
format!("lets {pronoun}").chars().collect(),
template,
),
Suggestion::replace_with_match_case(
"let's".to_string().chars().collect(),
template,
),
],
message: "`let's` stands for `let us`, so including another pronoun is redundant."
.to_owned(),
priority: 31,
Expand Down
13 changes: 11 additions & 2 deletions harper-core/src/linting/lets_confusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ mod tests {

use super::LetsConfusion;

#[test]
fn walking() {
assert_suggestion_result(
"The crutch let's him walk.",
LetsConfusion::default(),
"The crutch lets him walk.",
);
}

#[test]
fn issue_426_us() {
assert_suggestion_result("let's us do", LetsConfusion::default(), "let's do");
assert_suggestion_result("let's us do", LetsConfusion::default(), "lets us do");
}

#[test]
fn issue_426_me() {
assert_suggestion_result("let's me do", LetsConfusion::default(), "let's do");
assert_suggestion_result("let's me do", LetsConfusion::default(), "lets me do");
}

#[test]
Expand Down

0 comments on commit eec0123

Please sign in to comment.