mirror of
https://github.com/Automattic/harper.git
synced 2025-12-05 19:26:55 -06:00
feat(core): FindFine (#2248)
This commit is contained in:
74
harper-core/src/linting/find_fine.rs
Normal file
74
harper-core/src/linting/find_fine.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use crate::Token;
|
||||
use crate::expr::Expr;
|
||||
use crate::expr::SequenceExpr;
|
||||
use crate::patterns::InflectionOfBe;
|
||||
|
||||
use super::{ExprLinter, Lint, LintKind, Suggestion};
|
||||
|
||||
pub struct FindFine {
|
||||
expr: Box<dyn Expr>,
|
||||
}
|
||||
|
||||
impl Default for FindFine {
|
||||
fn default() -> Self {
|
||||
let expr = SequenceExpr::default()
|
||||
.then(InflectionOfBe::default())
|
||||
.t_ws()
|
||||
.t_aco("find");
|
||||
|
||||
Self {
|
||||
expr: Box::new(expr),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprLinter for FindFine {
|
||||
fn expr(&self) -> &dyn Expr {
|
||||
self.expr.as_ref()
|
||||
}
|
||||
|
||||
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
|
||||
let offending_word = matched_tokens.get(2)?;
|
||||
|
||||
Some(Lint {
|
||||
span: offending_word.span,
|
||||
lint_kind: LintKind::Typo,
|
||||
suggestions: vec![Suggestion::replace_with_match_case_str(
|
||||
"fine",
|
||||
offending_word.span.get_content(source),
|
||||
)],
|
||||
message: "Did you mean `fine`?".to_owned(),
|
||||
priority: 63,
|
||||
})
|
||||
}
|
||||
|
||||
fn description(&self) -> &'static str {
|
||||
"Fixes the common typo where writers write `find` when they mean `fine`."
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::linting::tests::assert_suggestion_result;
|
||||
|
||||
use super::FindFine;
|
||||
|
||||
#[test]
|
||||
fn issue_2115() {
|
||||
assert_suggestion_result(
|
||||
"I was using oil.nvim from an year and everything was find for me but I was missing a very key feature",
|
||||
FindFine::default(),
|
||||
"I was using oil.nvim from an year and everything was fine for me but I was missing a very key feature",
|
||||
);
|
||||
assert_suggestion_result(
|
||||
"I made several observations throughout the evening and everything was find.",
|
||||
FindFine::default(),
|
||||
"I made several observations throughout the evening and everything was fine.",
|
||||
);
|
||||
assert_suggestion_result(
|
||||
"I am find not using GPU at all for open3d.",
|
||||
FindFine::default(),
|
||||
"I am fine not using GPU at all for open3d.",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ use super::far_be_it::FarBeIt;
|
||||
use super::feel_fell::FeelFell;
|
||||
use super::few_units_of_time_ago::FewUnitsOfTimeAgo;
|
||||
use super::filler_words::FillerWords;
|
||||
use super::find_fine::FindFine;
|
||||
use super::first_aid_kit::FirstAidKit;
|
||||
use super::for_noun::ForNoun;
|
||||
use super::free_predicate::FreePredicate;
|
||||
@@ -490,6 +491,7 @@ impl LintGroup {
|
||||
insert_expr_rule!(CautionaryTale, true);
|
||||
insert_expr_rule!(ChangeTack, true);
|
||||
insert_expr_rule!(ChockFull, true);
|
||||
insert_struct_rule!(FindFine, true);
|
||||
insert_struct_rule!(CommaFixes, true);
|
||||
insert_struct_rule!(CompoundNouns, true);
|
||||
insert_expr_rule!(CompoundSubjectI, true);
|
||||
|
||||
@@ -55,6 +55,7 @@ mod far_be_it;
|
||||
mod feel_fell;
|
||||
mod few_units_of_time_ago;
|
||||
mod filler_words;
|
||||
mod find_fine;
|
||||
mod first_aid_kit;
|
||||
mod for_noun;
|
||||
mod free_predicate;
|
||||
@@ -245,6 +246,7 @@ pub use far_be_it::FarBeIt;
|
||||
pub use feel_fell::FeelFell;
|
||||
pub use few_units_of_time_ago::FewUnitsOfTimeAgo;
|
||||
pub use filler_words::FillerWords;
|
||||
pub use find_fine::FindFine;
|
||||
pub use for_noun::ForNoun;
|
||||
pub use free_predicate::FreePredicate;
|
||||
pub use friend_of_me::FriendOfMe;
|
||||
|
||||
Reference in New Issue
Block a user