Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: out of curiosities → curiosity / curosity's (#4685)
Andrew Dunbar566bc3717129
diff --git a/harper-core/default_config.json b/harper-core/default_config.jsonindex b732f0a7b..e6003bf9c 100644--- a/harper-core/default_config.json+++ b/harper-core/default_config.json@@ -5721,21 +5721,28 @@"Bool": {"name": "OnTopOf","state": true,- "label": "On Top Of"+ "label": "On Top of"+ }+ },+ {+ "Bool": {+ "name": "OutOfCuriosity",+ "state": true,+ "label": "Out of Curiosity"}},{"Bool": {"name": "OutOfDate","state": true,- "label": "Out Of Date"+ "label": "Out of Date"}},{"Bool": {"name": "OutOfOutsideTheBox","state": true,- "label": "OutOfOutsideTheBox"+ "label": "Out of Outside the Box"}},{diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex 336b64f03..c0ea9ddd2 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -219,6 +219,7 @@ use super::open_compounds::OpenCompounds;use super::open_the_light::OpenTheLight;use super::orthographic_consistency::OrthographicConsistency;use super::ought_to_be::OughtToBe;+use super::out_of_curiosity::OutOfCuriosity;use super::out_of_date::OutOfDate;use super::out_of_outside_the_box::OutOfOutsideTheBox;use super::out_of_the_window::OutOfTheWindow;@@ -999,6 +1000,9 @@ impl LintGroup {// Uses Sentence rather than Chunkout.add("NoHarmNoFoul", NoHarmNoFoul::default());+ // Uses Sentence rather than Chunk+ out.add("OutOfCuriosity", OutOfCuriosity::default());+// Uses Sentence rather than Chunkout.add("PluralDecades", PluralDecades::default());diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex eea604c1d..1f8496b43 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -234,6 +234,7 @@ mod open_compounds;mod open_the_light;mod orthographic_consistency;mod ought_to_be;+mod out_of_curiosity;mod out_of_date;mod out_of_outside_the_box;mod out_of_the_window;diff --git a/harper-core/src/linting/out_of_curiosity.rs b/harper-core/src/linting/out_of_curiosity.rsnew file mode 100644index 000000000..b9e118a70--- /dev/null+++ b/harper-core/src/linting/out_of_curiosity.rs@@ -0,0 +1,101 @@+use crate::{+ Lint, Token,+ char_string::CharStringExt,+ expr::{Expr, SequenceExpr},+ linting::{+ ExprLinter, LintKind, Suggestion,+ expr_linter::{Sentence, followed_by_token, followed_by_word},+ },+};++pub struct OutOfCuriosity {+ expr: SequenceExpr,+}++impl Default for OutOfCuriosity {+ fn default() -> Self {+ Self {+ expr: SequenceExpr::word_seq(&["out", "of", "curiosities"]),+ }+ }+}++impl ExprLinter for OutOfCuriosity {+ type Unit = Sentence;++ fn match_to_lint_with_context(+ &self,+ toks: &[Token],+ src: &[char],+ ctx: Option<(&[Token], &[Token])>,+ ) -> Option<Lint> {+ enum To {+ Singular,+ Possessive,+ }++ let to: To = if followed_by_token(ctx, |t| t.kind.is_comma()) {+ To::Singular+ } else if followed_by_word(ctx, |wt| wt.get_ch(src).eq_str("sake")) {+ To::Possessive+ } else {+ return None;+ };++ let (sugg, msg): (&str, &str) = match to {+ To::Singular => ("curiosity", "This idiom uses the singular `curiosity`."),+ To::Possessive => (+ "curiosity's",+ "It looks like you mean the possessive `curiosity's`.",+ ),+ };++ let span = toks.get(4)?.span;++ let suggestions = vec![Suggestion::replace_with_match_case_str(+ sugg,+ span.get_content(src),+ )];++ Some(Lint {+ span,+ lint_kind: LintKind::Miscellaneous,+ suggestions,+ message: msg.to_string(),+ ..Default::default()+ })+ }++ fn expr(&self) -> &dyn Expr {+ &self.expr+ }++ fn description(&self) -> &str {+ "A linter skeleton for contributors to copy into `harper_core/src/linting/` and rename."+ }+}++#[cfg(test)]+mod tests {+ use crate::linting::tests::assert_suggestion_result;++ use super::OutOfCuriosity;++ #[test]+ fn fix_to_singular() {+ assert_suggestion_result(+ "Just out of curiosities, do you know why it has a combo of super high and super low reviews?",+ OutOfCuriosity::default(),+ "Just out of curiosity, do you know why it has a combo of super high and super low reviews?",+ );+ }++ #[test]+ fn fix_to_possessive() {+ assert_suggestion_result(+ "Out of curiosities sake, I also tested on my Win10 machine with the WSL.",+ OutOfCuriosity::default(),+ "Out of curiosity's sake, I also tested on my Win10 machine with the WSL.",+ );+ }+}