Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: neither fish nor foul/bird → fowl (#3767)
Andrew Dunbaref054e8a410e
diff --git a/harper-core/default_config.json b/harper-core/default_config.jsonindex 8272a8f3f..a357698e5 100644--- a/harper-core/default_config.json+++ b/harper-core/default_config.json@@ -5411,6 +5411,13 @@"label": "For The Nth Time"}},+ {+ "Bool": {+ "name": "FishNorFowl",+ "state": true,+ "label": "Fish Nor Fowl"+ }+ },{"Bool": {"name": "InStock",diff --git a/harper-core/src/linting/fish_nor_fowl.rs b/harper-core/src/linting/fish_nor_fowl.rsnew file mode 100644index 000000000..84a88a4a2--- /dev/null+++ b/harper-core/src/linting/fish_nor_fowl.rs@@ -0,0 +1,90 @@+use crate::{+ CharStringExt, Lint, Token,+ expr::{Expr, SequenceExpr},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},+};++pub struct FishNorFowl {+ expr: SequenceExpr,+}++impl Default for FishNorFowl {+ fn default() -> Self {+ Self {+ expr: SequenceExpr::word_set(&["neither", "niether"])+ .t_ws()+ .then_word_seq(&["fish", "nor"])+ .t_ws()+ .t_set(&["foul", "bird"]),+ }+ }+}++impl ExprLinter for FishNorFowl {+ type Unit = Chunk;++ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {+ let last_token = toks.last()?;++ let (lint_kind, message) = if last_token+ .get_ch(src)+ .starts_with_any_ignore_ascii_case_str(&["f"])+ {+ (+ LintKind::Spelling,+ "The correct spelling is `fowl`, meaning `bird`. `Foul` is an adjective meaning `dirty` or `offensive`.",+ )+ } else {+ (+ LintKind::Nonstandard,+ "The standard idiom is `neither fish nor fowl`.",+ )+ };++ let span = last_token.span;++ Some(Lint {+ span,+ lint_kind,+ suggestions: vec![Suggestion::replace_with_match_case_str(+ "fowl",+ span.get_content(src),+ )],+ message: message.to_owned(),+ ..Default::default()+ })+ }++ fn expr(&self) -> &dyn Expr {+ &self.expr+ }++ fn description(&self) -> &str {+ "Corrects `neither fish nor foul` and `neither fish nor bird` to `neither fish nor fowl`."+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::assert_suggestion_result;++ use super::FishNorFowl;++ #[test]+ fn fix_bird() {+ assert_suggestion_result(+ "But there's one bus in Australia that actually tries to be that little bit train and is neither fish nor bird doing so.",+ FishNorFowl::default(),+ "But there's one bus in Australia that actually tries to be that little bit train and is neither fish nor fowl doing so.",+ );+ }++ #[test]+ fn fix_foul() {+ assert_suggestion_result(+ "But I do doubt chromebooks will be big hit, they're neither fish nor foul, since tablets stole netbooks' market.",+ FishNorFowl::default(),+ "But I do doubt chromebooks will be big hit, they're neither fish nor fowl, since tablets stole netbooks' market.",+ );+ }+}diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex fbef90c84..a84f7655a 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -99,6 +99,7 @@ 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::fish_nor_fowl::FishNorFowl;use super::flesh_out_vs_full_fledged::FleshOutVsFullFledged;use super::foot_inch_minute_second_symbols::FootInchMinuteSecondSymbols;use super::for_free_of_charge::ForFreeOfCharge;@@ -676,6 +677,7 @@ impl LintGroup {insert_expr_rule!(FillerWords);insert_struct_rule!(FindFine);insert_expr_rule!(FirstAidKit);+ insert_expr_rule!(FishNorFowl);insert_expr_rule!(FleshOutVsFullFledged);insert_expr_rule!(FootInchMinuteSecondSymbols);insert_expr_rule!(ForFreeOfCharge);diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex c6c78c5f2..f8c4d0d1b 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -95,6 +95,7 @@ mod few_units_of_time_ago;mod filler_words;mod find_fine;mod first_aid_kit;+mod fish_nor_fowl;mod flesh_out_vs_full_fledged;mod foot_inch_minute_second_symbols;mod for_free_of_charge;