Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: expand `BestOfAllTime` linter (#2381)
Andrew Dunbardc016dc60b28
diff --git a/harper-core/src/linting/best_of_all_time.rs b/harper-core/src/linting/best_of_all_time.rsindex 76ef31caa..d845c65a1 100644--- a/harper-core/src/linting/best_of_all_time.rs+++ b/harper-core/src/linting/best_of_all_time.rs@@ -1,9 +1,6 @@use crate::Token;-use crate::expr::{Expr, SequenceExpr};-use crate::patterns::WhitespacePattern;--use super::{ExprLinter, Lint, LintKind, Suggestion};-use crate::linting::expr_linter::Chunk;+use crate::expr::{Expr, Repeating, SequenceExpr};+use crate::linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Sentence};pub struct BestOfAllTime {expr: Box<dyn Expr>,@@ -18,17 +15,32 @@ impl Default for BestOfAllTime {.t_aco("most").t_ws().then_positive_adjective();- // Some resources call this an 'absolute adjective', some consider it a superlative.- let fave = SequenceExpr::word_set(&["favorite", "favourite"]);+ // Some resources call 'favourite' an 'absolute adjective', some consider it a superlative.+ let fave_or_top = SequenceExpr::word_set(&["favorite", "favourite", "top"]);// We can't use the noun phrase Expr because it allows determiners before the nouns and "best the thing" wouldn't be rightlet expr = SequenceExpr::default().then_any_of(vec![Box::new(inflection_superlative),Box::new(most_superlative),- Box::new(fave),+ Box::new(fave_or_top),])- .then_one_or_more(SequenceExpr::default().then(WhitespacePattern).then_noun())+ // There is no non-greedy `Repeating` in Harper, so we have to do match non-noun-oov tokens+ // rather than matching arbitrary tokens.+ // We include OOV because novel words not in the dictionary tend to be nouns.+ .then(Repeating::new(+ Box::new(|tok: &Token, _: &[char]| !tok.kind.is_noun() && !tok.kind.is_oov()),+ 0,+ ))+ .then_kind_where(|kind| kind.is_noun() || kind.is_oov())+ .then(Repeating::new(+ Box::new(+ SequenceExpr::default()+ .t_ws()+ .then_kind_where(|kind| kind.is_noun() || kind.is_oov()),+ ),+ 0,+ )).then_fixed_phrase(" of all times");Self {@@ -38,7 +50,7 @@ impl Default for BestOfAllTime {}impl ExprLinter for BestOfAllTime {- type Unit = Chunk;+ type Unit = Sentence;fn expr(&self) -> &dyn Expr {self.expr.as_ref()@@ -151,4 +163,31 @@ mod tests {"Just made this website to show you my favourite movies of all time.",);}++ #[test]+ fn fix_top_out_of_vocabulary() {+ assert_suggestion_result(+ "Can I Play the Top 10 Basslines of All Times?",+ BestOfAllTime::default(),+ "Can I Play the Top 10 Basslines of All Time?",+ );+ }++ #[test]+ fn fix_compound_noun() {+ assert_suggestion_result(+ "Is he the best bass guitarist of all times?",+ BestOfAllTime::default(),+ "Is he the best bass guitarist of all time?",+ );+ }++ #[test]+ fn fix_containing_commas() {+ assert_suggestion_result(+ "I am the biggest, best, and most humble of all times",+ BestOfAllTime::default(),+ "I am the biggest, best, and most humble of all time",+ );+ }}diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 5f9949048..34e40276c 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -509,7 +509,7 @@ impl LintGroup {insert_expr_rule!(AvoidCurses, true);insert_expr_rule!(BackInTheDay, true);insert_expr_rule!(BeAllowed, true);- insert_expr_rule!(BestOfAllTime, true);+ insert_struct_rule!(BestOfAllTime, true);insert_expr_rule!(BoringWords, false);insert_expr_rule!(Bought, true);insert_expr_rule!(BrandBrandish, true);