Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: not longer→no longer (#2691)
Andrew Dunbar42f4f2b77633
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 778203055..7e08bf70b 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -124,6 +124,7 @@ use super::multiple_sequential_pronouns::MultipleSequentialPronouns;use super::nail_on_the_head::NailOnTheHead;use super::need_to_noun::NeedToNoun;use super::no_french_spaces::NoFrenchSpaces;+use super::no_longer::NoLonger;use super::no_match_for::NoMatchFor;use super::no_oxford_comma::NoOxfordComma;use super::nobody::Nobody;@@ -523,6 +524,7 @@ impl LintGroup {insert_expr_rule!(NailOnTheHead, true);insert_expr_rule!(NeedToNoun, true);insert_struct_rule!(NoFrenchSpaces, true);+ insert_expr_rule!(NoLonger, true);insert_expr_rule!(NoMatchFor, true);insert_struct_rule!(NoOxfordComma, false);insert_expr_rule!(Nobody, true);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex 93865fc81..42d929241 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -131,6 +131,7 @@ mod multiple_sequential_pronouns;mod nail_on_the_head;mod need_to_noun;mod no_french_spaces;+mod no_longer;mod no_match_for;mod no_oxford_comma;mod nobody;diff --git a/harper-core/src/linting/no_longer.rs b/harper-core/src/linting/no_longer.rsnew file mode 100644index 000000000..4178cbf70--- /dev/null+++ b/harper-core/src/linting/no_longer.rs@@ -0,0 +1,145 @@+use crate::{+ Lint, Token, TokenKind,+ expr::{Expr, OwnedExprExt, SequenceExpr},+ linting::{Chunk, ExprLinter, LintKind, Suggestion},+};++pub struct NoLonger {+ expr: Box<dyn Expr>,+}++impl Default for NoLonger {+ fn default() -> Self {+ Self {+ expr: Box::new(+ SequenceExpr::aco("not")+ .t_ws()+ .t_aco("longer")+ .then_optional(SequenceExpr::default().t_ws().then_kind_any(+ &[+ TokenKind::is_verb_lemma,+ TokenKind::is_verb_third_person_singular_present_form,+ TokenKind::is_verb_past_participle_form,+ TokenKind::is_verb_progressive_form,+ ][..],+ ))+ .and_not(+ SequenceExpr::anything()+ .t_any()+ .t_any()+ .t_any()+ .t_aco("than"),+ ),+ ),+ }+ }+}++impl ExprLinter for NoLonger {+ type Unit = Chunk;++ fn expr(&self) -> &dyn Expr {+ self.expr.as_ref()+ }++ fn description(&self) -> &str {+ "Corrects `not longer` when it should be `no longer`."+ }++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ Some(Lint {+ span: toks[0].span,+ lint_kind: LintKind::Usage,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "no",+ toks[0].span.get_content(src),+ )],+ message: "The correct expression is `no longer`.".to_string(),+ ..Default::default()+ })+ }+}++#[cfg(test)]+mod tests {+ use super::NoLonger;+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};++ #[test]+ fn ignore_than() {+ assert_no_lints("My arm is not longer than my leg.", NoLonger::default())+ }++ #[test]+ fn fix_can_modal() {+ // TODO: would an improvement always be? - no longer can -> can no longer+ assert_suggestion_result(+ "and I've found out that I not longer can launch Kitty from the menus",+ NoLonger::default(),+ "and I've found out that I no longer can launch Kitty from the menus",+ );+ }++ #[test]+ fn fix_done_past_participle() {+ assert_suggestion_result(+ "I've noticed that the ML stuff is not longer done on the more recent photos.",+ NoLonger::default(),+ "I've noticed that the ML stuff is no longer done on the more recent photos.",+ );+ }++ #[test]+ fn fix_exist() {+ assert_suggestion_result(+ "Vendoring means that the transitive dependencies do not longer exist from the point of view of the consumer.",+ NoLonger::default(),+ "Vendoring means that the transitive dependencies do no longer exist from the point of view of the consumer.",+ );+ }++ #[test]+ fn fix_exists_3rd_person_singular_present() {+ assert_suggestion_result(+ "this script is mentioned in the RF3 Readme but the script not longer exists",+ NoLonger::default(),+ "this script is mentioned in the RF3 Readme but the script no longer exists",+ );+ }++ #[test]+ fn fix_render() {+ assert_suggestion_result(+ "auto comments will not longer render annotations in such a way as to make them valid annotation links",+ NoLonger::default(),+ "auto comments will no longer render annotations in such a way as to make them valid annotation links",+ );+ }++ #[test]+ fn fix_saved_regular_past() {+ assert_suggestion_result(+ "edit notes are not longer saved on mobile",+ NoLonger::default(),+ "edit notes are no longer saved on mobile",+ );+ }++ #[test]+ fn fix_saving_present_participle() {+ assert_suggestion_result(+ "After Updating to 4.3.2 from 4.2.1 the JSON Editor is not longer saving the metadata.",+ NoLonger::default(),+ "After Updating to 4.3.2 from 4.2.1 the JSON Editor is no longer saving the metadata.",+ );+ }++ #[test]+ fn fix_written_past_participle() {+ assert_suggestion_result(+ "I get this error and the fasta file is not longer written",+ NoLonger::default(),+ "I get this error and the fasta file is no longer written",+ );+ }+}