-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): detect improper contraction usage before verbs
- Loading branch information
1 parent
a605aec
commit 663f717
Showing
8 changed files
with
88 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47557,6 +47557,7 @@ usurp/4SDRZG | |
usurpation/1M | ||
usurper/1M | ||
usury/1M | ||
us/8 | ||
utensil/1SM | ||
uteri/1 | ||
uterine/51 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
mod let_us_redundancy; | ||
mod no_contraction_with_verb; | ||
|
||
use super::merge_linters::merge_linters; | ||
use let_us_redundancy::LetUsRedundancy; | ||
use no_contraction_with_verb::NoContractionWithVerb; | ||
|
||
merge_linters!(LetsConfusion => LetUsRedundancy, NoContractionWithVerb => "TODO"); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::linting::tests::assert_suggestion_result; | ||
|
||
use super::LetsConfusion; | ||
|
||
#[test] | ||
fn issue_426_us() { | ||
assert_suggestion_result("let's us do", LetsConfusion::default(), "let's do"); | ||
} | ||
|
||
#[test] | ||
fn issue_426_me() { | ||
assert_suggestion_result("let's me do", LetsConfusion::default(), "let's do"); | ||
} | ||
|
||
#[test] | ||
fn from_harper_docs() { | ||
assert_suggestion_result("Often the longest and the shortest words are the most helpful, so lets push them first.", LetsConfusion::default(), "Often the longest and the shortest words are the most helpful, so let's push them first."); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
harper-core/src/linting/lets_confusion/no_contraction_with_verb.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{ | ||
linting::{Lint, LintKind, Suggestion}, | ||
patterns::{Pattern, SequencePattern}, | ||
Token, | ||
}; | ||
|
||
use crate::linting::PatternLinter; | ||
|
||
pub struct NoContractionWithVerb { | ||
pattern: Box<dyn Pattern>, | ||
} | ||
|
||
impl Default for NoContractionWithVerb { | ||
fn default() -> Self { | ||
let pattern = SequencePattern::aco("lets").then_whitespace().then_verb(); | ||
|
||
Self { | ||
pattern: Box::new(pattern), | ||
} | ||
} | ||
} | ||
|
||
impl PatternLinter for NoContractionWithVerb { | ||
fn pattern(&self) -> &dyn Pattern { | ||
self.pattern.as_ref() | ||
} | ||
|
||
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint { | ||
let problem_span = matched_tokens.first().unwrap().span; | ||
let template = problem_span.get_content(source); | ||
|
||
Lint { | ||
span: problem_span, | ||
lint_kind: LintKind::WordChoice, | ||
suggestions: vec![ | ||
Suggestion::replace_with_match_case_str("let's", template), | ||
Suggestion::replace_with_match_case_str("let us", template), | ||
], | ||
message: "It seems you forgot to include a subject here.".to_owned(), | ||
priority: 31, | ||
} | ||
} | ||
|
||
fn description(&self) -> &'static str { | ||
"Make sure you include a subject." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lets go and check if this lint let's us catch this class of errors. |