Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(core): issues in last commit
Elijah Potter2c1da890e494
diff --git a/harper-core/src/linting/map_phrase_linter.rs b/harper-core/src/linting/map_phrase_linter.rsindex e8cf2120f..4bb541513 100644--- a/harper-core/src/linting/map_phrase_linter.rs+++ b/harper-core/src/linting/map_phrase_linter.rs@@ -1,6 +1,6 @@use super::{Lint, LintKind, PatternLinter};use crate::linting::Suggestion;-use crate::patterns::{ExactPhrase, Pattern, SimilarToPhrase};+use crate::patterns::{EitherPattern, ExactPhrase, Pattern, SimilarToPhrase};use crate::{Token, TokenStringExt};pub struct MapPhraseLinter {@@ -34,6 +34,25 @@ impl MapPhraseLinter {)}+ pub fn new_exact_phrases(+ phrase: impl IntoIterator<Item = impl AsRef<str>>,+ correct_forms: impl IntoIterator<Item = impl ToString>,+ message: impl ToString,+ description: impl ToString,+ ) -> Self {+ let patterns = EitherPattern::new(+ phrase+ .into_iter()+ .map(|p| {+ let pattern: Box<dyn Pattern> = Box::new(ExactPhrase::from_phrase(p.as_ref()));+ pattern+ })+ .collect(),+ );++ Self::new(Box::new(patterns), correct_forms, message, description)+ }+pub fn new_exact_phrase(phrase: impl AsRef<str>,correct_forms: impl IntoIterator<Item = impl ToString>,diff --git a/harper-core/src/linting/phrase_corrections.rs b/harper-core/src/linting/phrase_corrections.rsindex dc6359913..124cd021c 100644--- a/harper-core/src/linting/phrase_corrections.rs+++ b/harper-core/src/linting/phrase_corrections.rs@@ -1,5 +1,3 @@-use crate::patterns::{ExactPhrase, OwnedPatternExt};-use super::{LintGroup, MapPhraseLinter};/// Produce a [`LintGroup`] that looks for errors in common phrases.@@ -14,7 +12,7 @@ pub fn lint_group() -> LintGroup {$($group.add($name,- Box::new(MapPhraseLinter::new_exact_phrase(+ Box::new(MapPhraseLinter::new_exact_phrases($input,$corrections,$hint,@@ -29,7 +27,7 @@ pub fn lint_group() -> LintGroup {// The name of the rule"ChangeTack" => (// The exact phrase to look for.- "change tact",+ ["change tact"],// The corrections to provide.["change tack"],// The message to be shown with the error.@@ -38,301 +36,306 @@ pub fn lint_group() -> LintGroup {"Locates minor errors in the sailing idiom `change tack`."),"WantBe" => (- "want be",+ ["want be"],["won't be", "want to be"],"Did you mean `won't be` or `want to be`?","Detects incorrect usage of `want be` and suggests `won't be` or `want to be` based on context."),"StateOfTheArt" => (- "state of art",+ ["state of art"],["state of the art"],"Did you mean `state of the art`?","Detects incorrect usage of `state of art` and suggests `state of the art` as the correct phrase."),"FaceFirst" => (- "face first into",+ ["face first into"],["face-first into"],"Should this be `face-first`?","Ensures `face first` is correctly hyphenated as `face-first` when used before `into`."),"EludedTo" => (- "eluded to",+ ["eluded to"],["alluded to"],"Did you mean `alluded to`?","Corrects `eluded to` to `alluded to` in contexts referring to indirect references."),"BaitedBreath" => (- "baited breath",+ ["baited breath"],["bated breath"],"Did you mean `bated breath`?","Ensures `bated breath` is written correctly, as `baited breath` is incorrect."),"BareInMind" => (- "bare in mind",+ ["bare in mind"],["bear in mind"],"Did you mean `bear in mind`?","Ensures the phrase `bear in mind` is used correctly instead of `bare in mind`."),"MutePoint" => (- "mute point",+ ["mute point"],["moot point"],"Did you mean `moot point`?","Ensures `moot point` is used instead of `mute point`, as `moot` means debatable or irrelevant."),"RoadMap" => (- "roadmap",+ ["roadmap"],["road map"],"Did you mean `road map`?","Detects when `roadmap` is used instead of `road map`, prompting the correct spacing."),"SameAs" => (- "same then",+ ["same then"],["same as"],"Did you mean `same as`?","Corrects the incorrect phrase `same then` to the standard `same as`."),"SoonerOrLater" => (- "sooner than later",+ ["sooner than later"],["sooner rather than later", "sooner or later"],"Did you mean `sooner rather than later` or `sooner or later`?","Fixes the improper phrase `sooner than later` by suggesting standard alternatives."),"HadOf" => (- "had of",+ ["had of"],["had have", "had've"],"Did you mean `had have` or `had've`?","Flags the unnecessary use of `of` after `had` and suggests the correct forms."),"FatalOutcome" => (- "fatal outcome",+ ["fatal outcome"],["death"],"Consider using `death` for clarity.","Replaces `fatal outcome` with the more direct term `death` for conciseness."),"NotTo" => (- "no to",+ ["no to"],["not to"],"Did you mean `not to`?","Corrects `no to` to `not to`, ensuring proper negation."),"ThatThis" => (- "the this",+ ["the this"],["that this"],"Did you mean `that this`?","Fixes `the this` to the correct phrase `that this`."),"CondenseAllThe" => (- "all of the",+ ["all of the"],["all the"],"Consider simplifying to `all the`.","Suggests removing `of` in `all of the` for a more concise phrase."),"AvoidAndAlso" => (- "and also",+ ["and also"],["and"],"Consider using just `and`.","Reduces redundancy by replacing `and also` with `and`."),"AndIn" => (- "an in",+ ["an in"],["and in"],"Did you mean `and in`?","Fixes the incorrect phrase `an in` to `and in` for proper conjunction usage."),"BeenThere" => (- "bee there",+ ["bee there"],["been there"],"Did you mean `been there`?","Corrects the misspelling `bee there` to the proper phrase `been there`."),"CanBeSeen" => (- "can be seem",+ ["can be seem"],["can be seen"],"Did you mean `can be seen`?","Corrects `can be seem` to the proper phrase `can be seen`."),"GoingTo" => (- "gong to",+ ["gong to"],["going to"],"Did you mean `going to`?","Corrects `gong to` to the intended phrase `going to`."),"IAm" => (- "I a m",+ ["I a m"],["I am"],"Did you mean `I am`?","Fixes the incorrect spacing in `I a m` to properly form `I am`."),"ItCan" => (- "It cam",+ ["It cam"],["It can"],"Did you mean `It can`?","Corrects the misspelling `It cam` to the proper phrase `It can`."),"MyHouse" => (- "mu house",+ ["mu house"],["my house"],"Did you mean `my house`?","Fixes the typo `mu house` to `my house`."),"OperativeSystem" => (- "operative system",+ ["operative system"],["operating system"],"Did you mean `operating system`?","Ensures `operating system` is used correctly instead of `operative system`."),"OperativeSystems" => (- "operative systems",+ ["operative systems"],["operating systems"],"Did you mean `operating systems`?","Ensures `operating systems` is used correctly instead of `operative systems`."),"BanTogether" => (- "ban together",+ ["ban together"],["band together"],- "Did you mean 'band together'?",+ "Did you mean `band together`?","Detects and corrects the common error of using `ban together` instead of the idiom `band together`, which means to unite or join forces."),"WaveFunction" => (- "wavefunction",+ ["wavefunction"],["wave function"],- "Did you mean 'wave function'?",- "Identifies the mistake of merging 'wave' and 'function' into one word. In quantum mechanics, a 'wave function' (written as two words) describes the mathematical function that represents the quantum state of a particle or system. Correct usage is crucial for clear and accurate scientific communication."+ "Did you mean `wave function`?",+ "Identifies the mistake of merging `wave` and `function` into one word. In quantum mechanics, a `wave function` (written as two words) describes the mathematical function that represents the quantum state of a particle or system. Correct usage is crucial for clear and accurate scientific communication."),"InThe" => (- "int he",+ ["int he"],["in the"],- "Did you mean 'in the'?",- "Detects and corrects a spacing error where 'in the' is mistakenly written as `int he`. Proper spacing is essential for readability and grammatical correctness in common phrases."+ "Did you mean `in the`?",+ "Detects and corrects a spacing error where `in the` is mistakenly written as `int he`. Proper spacing is essential for readability and grammatical correctness in common phrases."),"WillContain" => (- "will contains",+ ["will contains"],["will contain"],- "Did you mean 'will contain'?",- "Incorrect verb form: 'will' should be followed by the base form 'contain'."+ "Did you mean `will contain`?",+ "Incorrect verb form: `will` should be followed by the base form `contain`."),"IsKnownFor" => (- "is know for",+ ["is know for"],["is known for"],- "Did you mean 'is known for'?",- "Typo: 'known' is the correct past participle."+ "Did you mean `is known for`?",+ "Typo: `known` is the correct past participle."),"PointIsMoot" => (- "your point is mute",+ ["your point is mute"],["your point is moot"],- "Did you mean 'your point is moot'?",- "Typo: 'moot' (meaning debatable) is correct rather than 'mute'."+ "Did you mean `your point is moot`?",+ "Typo: `moot` (meaning debatable) is correct rather than `mute`."),"ByAccident" => (- "on accident",+ ["on accident"],["by accident"],- "Did you mean 'by accident'?",- "Incorrect preposition: 'by accident' is the idiomatic expression."- ),- "OfCourse" => (- "off course",- ["of course"],- "Did you mean 'of course'?",- "Detects the non‐idiomatic phrase 'off course' and suggests the correct form 'of course'."+ "Did you mean `by accident`?",+ "Incorrect preposition: `by accident` is the idiomatic expression."),"ThatChallenged" => (- "the challenged",+ ["the challenged"],["that challenged"],"Did you mean `that challenged`?",- "Intelligently detects the common error where `the challenged` is mistakenly used instead of the correct `that challenged`, thereby rectifying the misspelling of `challenged`."+ "Changes `the challenged` to `that challenged` to fix the misspelling."),"TurnItOff" => (- "turn it of",+ ["turn it of", "turn i of"],["turn it off"],"Did you mean `turn it off`?",- "Recognizes a subtle deviation from the idiomatic expression `turn it off` and prompts a correction to the proper base form."+ "Fixes the mistake in the phrase `turn it off`."),"HumanLife" => (- "human live",+ ["human live"],["human life"],"Did you mean `human life`?",- "Ensures that the existential term `human life` is accurately rendered, correcting the inadvertent error `human live`."+ "Changes `human live` to `human life`."),"NeedHelp" => (- "ned help",+ ["ned help"],["need help"],"Did you mean `need help`?",- "Identifies the omission in `ned help` and recommends the grammatically complete `need help`."+ "Changes `ned help` to the correct `need help`."),"AndTheLike" => (- "an the like",+ ["an the like"],["and the like"],"Did you mean `and the like`?",- "Detects a minor error in the common phrase `and the like`, where `an` is erroneously used in place of `and`."- ),- "BadRap" => (- "bed rap",- ["bad rap"],- "Did you mean `bad rap`?",- "Corrects the frequent misrendering `bed rap` by reinstating the idiomatically correct `bad rap`."+ "Fixes the typo in `and the like`."),"BatedBreath" => (- "baited breath",+ ["baited breath"],["bated breath"],"Did you mean `bated breath`?",- "Discerns the erroneous spelling `baited breath` and suggests the proper form `bated breath`, respecting its etymological origin."+ "Changes `baited breath` to the correct `bated breath`."),"BeckAndCall" => (- "back and call",+ ["back and call"],["beck and call"],"Did you mean `beck and call`?",- "Identifies the inversion error in `back and call` and promotes the established phrase `beck and call`."- ),- "EnMasse" => (- "on masse",- ["en masse"],- "Did you mean `en masse`?",- "Detects an inadvertent misplacement in `on masse` and corrects it to the precise expression `en masse`."+ "Fixes `back and call` to `beck and call`."),"LetAlone" => (- "let along",+ ["let along"],["let alone"],"Did you mean `let alone`?",- "Pinpoints the error where `let along` is erroneously used in place of the conventional phrase `let alone`."+ "Changes `let along` to `let alone`."),"SneakingSuspicion" => (- "sneaky suspicion",+ ["sneaky suspicion"],["sneaking suspicion"],"Did you mean `sneaking suspicion`?",- "Discerns the colloquial misstep `sneaky suspicion` and advises the refined, idiomatic `sneaking suspicion`."+ "Changes `sneaky suspicion` to `sneaking suspicion`."),"SpecialAttention" => (- "spacial attention",+ ["spacial attention"],["special attention"],"Did you mean `special attention`?",- "Detects the orthographic error `spacial attention` and recommends the standard form `special attention` for precise usage."+ "Changes `spacial attention` to `special attention`."),"SupposedTo" => (- "suppose to",+ ["suppose to"],["supposed to"],"Did you mean `supposed to`?",- "Corrects the erroneous `suppose to` by suggesting the grammatically accurate `supposed to`, thereby restoring proper modal construction."+ "Fixes `suppose to` to the correct `supposed to`."),"KindRegards" => (- "kid regards",+ ["kid regards"],["kind regards"],"Did you mean `kind regards`?",- "Recognizes the common misspelling `kid regards` and rectifies it to the courteous closing `kind regards`."+ "Changes `kid regards` to `kind regards`."),"ThoughtProcess" => (- "though process",+ ["though process"],["thought process"],"Did you mean `thought process`?",- "Detects the inadvertent omission in `though process` and recommends the well-established term `thought process`, ensuring clarity and precision."+ "Changes `though process` to `thought process`."),- });-- group.add("FastPaste", Box::new(MapPhraseLinter::new(- Box::new(ExactPhrase::from_phrase("fast paste").or(Box::new(ExactPhrase::from_phrase("fast-paste")))),+ "BadRap" => (+ ["bed rap", "bad rep"],+ ["bad rap"],+ "Did you mean `bad rap`?",+ "Changes `bed rap` to the proper idiom `bad rap`."+ ),+ "OfCourse" => (+ ["off course", "o course"],+ ["Of course"],+ "Did you mean `of course`?",+ "Detects the non‐idiomatic phrase `off course` and suggests the correct form `of course`."+ ),+ "FastPaste" => (+ ["fast paste", "fast-paste"],["fast-paced"],"Did you mean `fast-paced`?","Detects incorrect usage of `fast paste` or `fast-paste` and suggests `fast-paced` as the correct phrase."- )));+ ),+ "EnMasse" => (+ ["on mass", "on masse", "in mass"],+ ["en masse"],+ "Did you mean `en masse`?",+ "Detects variants like `on mass` or `in mass` and suggests `en masse`."+ ),+ "HungerPang" => (+ ["hunger pain"],+ ["hunger pang"],+ "Did you mean `hunger pang`?",+ "Corrects `hunger pain` to `hunger pang`."+ )+ });group.set_all_rules_to(Some(true));