Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
refactor(core): centralize linter configuration
Elijah Potterefb3b82cbde2
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rsindex b78199b53..72332eb5b 100644--- a/harper-cli/src/main.rs+++ b/harper-cli/src/main.rs@@ -7,7 +7,7 @@ use anyhow::format_err;use ariadne::{Color, Label, Report, ReportKind, Source};use clap::Parser;use harper_comments::CommentParser;-use harper_core::linting::{LintGroup, LintGroupConfig, Linter};+use harper_core::linting::{LintGroup, Linter};use harper_core::parsers::{Markdown, MarkdownOptions};use harper_core::spell::hunspell::parse_default_attribute_list;use harper_core::spell::hunspell::word_list::parse_word_list;@@ -57,14 +57,13 @@ enum Args {fn main() -> anyhow::Result<()> {let args = Args::parse();let markdown_options = MarkdownOptions::default();- let linting_options = LintGroupConfig::default();let dictionary = FstDictionary::curated();match args {Args::Lint { file, count } => {let (doc, source) = load_file(&file, markdown_options)?;- let mut linter = LintGroup::new_curated(linting_options, dictionary);+ let mut linter = LintGroup::new_curated(dictionary);let mut lints = linter.lint(&doc);if count {@@ -199,8 +198,7 @@ fn main() -> anyhow::Result<()> {description: String,}- let mut linter = LintGroup::new_curated(linting_options, dictionary);- linter.config.fill_with_curated_config();+ let linter = LintGroup::new_curated(dictionary);let default_config: HashMap<String, bool> =serde_json::from_str(&serde_json::to_string(&linter.config).unwrap()).unwrap();diff --git a/harper-comments/tests/language_support.rs b/harper-comments/tests/language_support.rsindex 8602580a9..11546ad29 100644--- a/harper-comments/tests/language_support.rs+++ b/harper-comments/tests/language_support.rs@@ -25,10 +25,7 @@ macro_rules! create_test {let dict = FstDictionary::curated();let document = Document::new(&source, &parser, &dict);- let mut linter = LintGroup::new_curated(- LintGroupConfig::default(),- dict- );+ let mut linter = LintGroup::new_curated(dict);let lints = linter.lint(&document);dbg!(&lints);diff --git a/harper-core/src/ignored_lints/mod.rs b/harper-core/src/ignored_lints/mod.rsindex 15de80f57..79e209280 100644--- a/harper-core/src/ignored_lints/mod.rs+++ b/harper-core/src/ignored_lints/mod.rs@@ -67,9 +67,7 @@ mod tests {fn can_ignore_all(text: String) -> bool {let document = Document::new_markdown_default_curated(&text);- let mut lints =- LintGroup::new_curated(LintGroupConfig::default(), FstDictionary::curated())- .lint(&document);+ let mut lints = LintGroup::new_curated(FstDictionary::curated()).lint(&document);let mut ignored = IgnoredLints::new();@@ -85,9 +83,7 @@ mod tests {fn can_ignore_first(text: String) -> TestResult {let document = Document::new_markdown_default_curated(&text);- let mut lints =- LintGroup::new_curated(LintGroupConfig::default(), FstDictionary::curated())- .lint(&document);+ let mut lints = LintGroup::new_curated(FstDictionary::curated()).lint(&document);let Some(first) = lints.first().cloned() else {return TestResult::discard();@@ -103,11 +99,9 @@ mod tests {// Check that ignoring the nth lint found in source text actually removes it (and no others).fn assert_ignore_lint_reduction(source: &str, nth_lint: usize) {- let document = Document::new_markdown_default_curated(&source);+ let document = Document::new_markdown_default_curated(source);- let mut lints =- LintGroup::new_curated(LintGroupConfig::default(), FstDictionary::curated())- .lint(&document);+ let mut lints = LintGroup::new_curated(FstDictionary::curated()).lint(&document);let nth = lints.get(nth_lint).cloned().unwrap_or_else(|| {panic!("If ignoring the lint at {nth_lint}, make sure there are enough problems.")diff --git a/harper-core/src/lib.rs b/harper-core/src/lib.rsindex e7b13dd8c..6812ce37e 100644--- a/harper-core/src/lib.rs+++ b/harper-core/src/lib.rs@@ -75,7 +75,7 @@ pub fn remove_overlaps(lints: &mut Vec<Lint>) {#[cfg(test)]mod tests {use crate::{- linting::{LintGroup, LintGroupConfig, Linter},+ linting::{LintGroup, Linter},remove_overlaps, Document, FstDictionary,};@@ -83,10 +83,7 @@ mod tests {fn keeps_space_lint() {let doc = Document::new_plain_english_curated("Ths tet");- let mut lint_config = LintGroupConfig::default();- lint_config.fill_with_curated_config();-- let mut linter = LintGroup::new_curated(lint_config, FstDictionary::curated());+ let mut linter = LintGroup::new_curated(FstDictionary::curated());let mut lints = linter.lint(&doc);diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 91147ce21..bb817fa09 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -1,3 +1,5 @@+use std::sync::Arc;+use hashbrown::HashMap;use serde::{Deserialize, Serialize};@@ -40,14 +42,7 @@ use super::pique_interest::PiqueInterest;use super::plural_conjugate::PluralConjugate;use super::possessive_your::PossessiveYour;use super::pronoun_contraction::PronounContraction;-use super::proper_noun_capitalization_linters::DayOneNames;-use super::proper_noun_capitalization_linters::JetpackNames;-use super::proper_noun_capitalization_linters::PocketCastsNames;-use super::proper_noun_capitalization_linters::TumblrNames;-use super::proper_noun_capitalization_linters::{- AmazonNames, Americas, AppleNames, Australia, AzureNames, Canada, ChineseCommunistParty,- GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,-};+use super::proper_noun_capitalization_linters;use super::repeated_words::RepeatedWords;use super::sentence_capitalization::SentenceCapitalization;use super::somewhat_something::SomewhatSomething;@@ -96,6 +91,10 @@ impl LintGroupConfig {self.inner.get(key).cloned().unwrap_or(false)}+ pub fn clear(&mut self) {+ self.inner.clear();+ }+/// Merge the contents of another [`LintGroupConfig`] into this one./// The other config will be left empty after this operation.///@@ -103,120 +102,6 @@ impl LintGroupConfig {pub fn merge_from(&mut self, other: &mut LintGroupConfig) {self.inner.extend(other.inner.drain());}-- pub fn fill_with_curated_config(&mut self) {- self.set_rule_enabled_if_unset(stringify!(WordPressDotcom), true);- self.set_rule_enabled_if_unset(stringify!(DayOneNames), true);- self.set_rule_enabled_if_unset(stringify!(PocketCastsNames), true);- self.set_rule_enabled_if_unset(stringify!(TumblrNames), true);- self.set_rule_enabled_if_unset(stringify!(JetpackNames), true);- self.set_rule_enabled_if_unset(stringify!(OutOfDate), true);- self.set_rule_enabled_if_unset(stringify!(Desktop), true);- self.set_rule_enabled_if_unset(stringify!(Laptop), true);- self.set_rule_enabled_if_unset(stringify!(ThenThan), true);- self.set_rule_enabled_if_unset(stringify!(PiqueInterest), true);- self.set_rule_enabled_if_unset(stringify!(WasAloud), true);- self.set_rule_enabled_if_unset(stringify!(HyphenateNumberDay), true);- self.set_rule_enabled_if_unset(stringify!(LeftRightHand), true);- self.set_rule_enabled_if_unset(stringify!(HopHope), true);- self.set_rule_enabled_if_unset(stringify!(Furthermore), true);- self.set_rule_enabled_if_unset(stringify!(Overnight), true);- self.set_rule_enabled_if_unset(stringify!(Hereby), true);- self.set_rule_enabled_if_unset(stringify!(Likewise), true);- self.set_rule_enabled_if_unset(stringify!(CompoundNouns), true);- self.set_rule_enabled_if_unset(stringify!(Regardless), true);- self.set_rule_enabled_if_unset(stringify!(Henceforth), true);- self.set_rule_enabled_if_unset(stringify!(Upward), true);- self.set_rule_enabled_if_unset(stringify!(Whereupon), true);- self.set_rule_enabled_if_unset(stringify!(Insofar), true);- self.set_rule_enabled_if_unset(stringify!(Thereupon), true);- self.set_rule_enabled_if_unset(stringify!(Nonetheless), true);- self.set_rule_enabled_if_unset(stringify!(Anyhow), true);- self.set_rule_enabled_if_unset(stringify!(Notwithstanding), true);- self.set_rule_enabled_if_unset(stringify!(Widespread), true);- self.set_rule_enabled_if_unset(stringify!(Multimedia), true);- self.set_rule_enabled_if_unset(stringify!(Multicore), true);- self.set_rule_enabled_if_unset(stringify!(Multithreading), true);- self.set_rule_enabled_if_unset(stringify!(Devops), true);- self.set_rule_enabled_if_unset(stringify!(Underclock), true);- self.set_rule_enabled_if_unset(stringify!(Overload), true);- self.set_rule_enabled_if_unset(stringify!(Backplane), true);- self.set_rule_enabled_if_unset(stringify!(Overclocking), true);- self.set_rule_enabled_if_unset(stringify!(Middleware), true);- self.set_rule_enabled_if_unset(stringify!(Somewhere), true);- self.set_rule_enabled_if_unset(stringify!(Instead), true);- self.set_rule_enabled_if_unset(stringify!(Anywhere), true);- self.set_rule_enabled_if_unset(stringify!(Nothing), true);- self.set_rule_enabled_if_unset(stringify!(Anybody), true);- self.set_rule_enabled_if_unset(stringify!(Somebody), true);- self.set_rule_enabled_if_unset(stringify!(Nobody), true);- self.set_rule_enabled_if_unset(stringify!(Into), true);- self.set_rule_enabled_if_unset(stringify!(Proofread), true);- self.set_rule_enabled_if_unset(stringify!(Somehow), true);- self.set_rule_enabled_if_unset(stringify!(Intact), true);- self.set_rule_enabled_if_unset(stringify!(Upset), true);- self.set_rule_enabled_if_unset(stringify!(Misunderstood), true);- self.set_rule_enabled_if_unset(stringify!(However), true);- self.set_rule_enabled_if_unset(stringify!(Overall), true);- self.set_rule_enabled_if_unset(stringify!(Worldwide), true);- self.set_rule_enabled_if_unset(stringify!(Postpone), true);- self.set_rule_enabled_if_unset(stringify!(Misused), true);- self.set_rule_enabled_if_unset(stringify!(Misuse), true);- self.set_rule_enabled_if_unset(stringify!(Misunderstand), true);- self.set_rule_enabled_if_unset(stringify!(Therefore), true);- self.set_rule_enabled_if_unset(stringify!(Myself), true);- self.set_rule_enabled_if_unset(stringify!(Itself), true);- self.set_rule_enabled_if_unset(stringify!(Whereas), true);- self.set_rule_enabled_if_unset(stringify!(PossessiveYour), true);- self.set_rule_enabled_if_unset(stringify!(SpelledNumbers), false);- self.set_rule_enabled_if_unset(stringify!(AnA), true);- self.set_rule_enabled_if_unset(stringify!(SentenceCapitalization), true);- self.set_rule_enabled_if_unset(stringify!(UnclosedQuotes), true);- self.set_rule_enabled_if_unset(stringify!(WrongQuotes), false);- self.set_rule_enabled_if_unset(stringify!(LongSentences), true);- self.set_rule_enabled_if_unset(stringify!(RepeatedWords), true);- self.set_rule_enabled_if_unset(stringify!(Spaces), true);- self.set_rule_enabled_if_unset(stringify!(Matcher), true);- self.set_rule_enabled_if_unset(stringify!(CorrectNumberSuffix), true);- self.set_rule_enabled_if_unset(stringify!(NumberSuffixCapitalization), true);- self.set_rule_enabled_if_unset(stringify!(MultipleSequentialPronouns), true);- self.set_rule_enabled_if_unset(stringify!(LinkingVerbs), false);- self.set_rule_enabled_if_unset(stringify!(AvoidCurses), true);- self.set_rule_enabled_if_unset(stringify!(TerminatingConjunctions), true);- self.set_rule_enabled_if_unset(stringify!(EllipsisLength), true);- self.set_rule_enabled_if_unset(stringify!(DotInitialisms), true);- self.set_rule_enabled_if_unset(stringify!(BoringWords), false);- self.set_rule_enabled_if_unset(stringify!(UseGenitive), false);- self.set_rule_enabled_if_unset(stringify!(ThatWhich), true);- self.set_rule_enabled_if_unset(stringify!(CapitalizePersonalPronouns), true);- self.set_rule_enabled_if_unset(stringify!(Americas), true);- self.set_rule_enabled_if_unset(stringify!(Australia), true);- self.set_rule_enabled_if_unset(stringify!(Canada), true);- self.set_rule_enabled_if_unset(stringify!(Koreas), true);- self.set_rule_enabled_if_unset(stringify!(Malaysia), true);- self.set_rule_enabled_if_unset(stringify!(ChineseCommunistParty), true);- self.set_rule_enabled_if_unset(stringify!(UnitedOrganizations), true);- self.set_rule_enabled_if_unset(stringify!(Holidays), true);- self.set_rule_enabled_if_unset(stringify!(AmazonNames), true);- self.set_rule_enabled_if_unset(stringify!(GoogleNames), true);- self.set_rule_enabled_if_unset(stringify!(MetaNames), true);- self.set_rule_enabled_if_unset(stringify!(MicrosoftNames), true);- self.set_rule_enabled_if_unset(stringify!(AppleNames), true);- self.set_rule_enabled_if_unset(stringify!(AzureNames), true);- self.set_rule_enabled_if_unset(stringify!(MergeWords), true);- self.set_rule_enabled_if_unset(stringify!(PluralConjugate), false);- self.set_rule_enabled_if_unset(stringify!(OxfordComma), true);- self.set_rule_enabled_if_unset(stringify!(NoOxfordComma), false);- self.set_rule_enabled_if_unset(stringify!(PronounContraction), true);- self.set_rule_enabled_if_unset(stringify!(CurrencyPlacement), true);- self.set_rule_enabled_if_unset(stringify!(SomewhatSomething), true);- self.set_rule_enabled_if_unset(stringify!(LetsConfusion), true);- self.set_rule_enabled_if_unset(stringify!(DespiteOf), true);- self.set_rule_enabled_if_unset(stringify!(ChockFull), true);- self.set_rule_enabled_if_unset(stringify!(LoAndBehold), true);- self.set_rule_enabled_if_unset(stringify!(Everywhere), true);- self.set_rule_enabled("SpellCheck", true);- }}#[derive(Default)]@@ -269,130 +154,122 @@ impl LintGroup {.collect()}- pub fn new_curated(config: LintGroupConfig, dictionary: impl Dictionary + 'static) -> Self {+ /// Swap out [`Self::config`] with another [`LintGroupConfig`].+ pub fn with_lint_config(mut self, config: LintGroupConfig) -> Self {+ self.config = config;+ self+ }++ pub fn new_curated(dictionary: Arc<impl Dictionary + 'static>) -> Self {let mut out = Self::empty();macro_rules! insert_struct_rule {- ($rule:ident) => {+ ($rule:ident, $default_config:expr) => {out.add(stringify!($rule), Box::new($rule::default()));+ out.config+ .set_rule_enabled(stringify!($rule), $default_config);};}out.merge_from(&mut phrase_corrections::lint_group());-- insert_struct_rule!(WordPressDotcom);- insert_struct_rule!(DayOneNames);- insert_struct_rule!(PocketCastsNames);- insert_struct_rule!(TumblrNames);- insert_struct_rule!(JetpackNames);- insert_struct_rule!(OutOfDate);- insert_struct_rule!(Desktop);- insert_struct_rule!(Laptop);- insert_struct_rule!(ThenThan);- insert_struct_rule!(PiqueInterest);- insert_struct_rule!(WasAloud);- insert_struct_rule!(HyphenateNumberDay);- insert_struct_rule!(LeftRightHand);- insert_struct_rule!(HopHope);- insert_struct_rule!(Furthermore);- insert_struct_rule!(Overnight);- insert_struct_rule!(Hereby);- insert_struct_rule!(Likewise);- insert_struct_rule!(CompoundNouns);- insert_struct_rule!(Regardless);- insert_struct_rule!(Henceforth);- insert_struct_rule!(Upward);- insert_struct_rule!(Whereupon);- insert_struct_rule!(Insofar);- insert_struct_rule!(Thereupon);- insert_struct_rule!(Nonetheless);- insert_struct_rule!(Anyhow);- insert_struct_rule!(Notwithstanding);- insert_struct_rule!(Widespread);- insert_struct_rule!(Multimedia);- insert_struct_rule!(Multicore);- insert_struct_rule!(Multithreading);- insert_struct_rule!(Devops);- insert_struct_rule!(Underclock);- insert_struct_rule!(Overload);- insert_struct_rule!(Backplane);- insert_struct_rule!(Overclocking);- insert_struct_rule!(Middleware);- insert_struct_rule!(Somewhere);- insert_struct_rule!(Instead);- insert_struct_rule!(Anywhere);- insert_struct_rule!(Nothing);- insert_struct_rule!(Anybody);- insert_struct_rule!(Somebody);- insert_struct_rule!(Nobody);- insert_struct_rule!(Into);- insert_struct_rule!(Proofread);- insert_struct_rule!(Somehow);- insert_struct_rule!(Intact);- insert_struct_rule!(Upset);- insert_struct_rule!(Misunderstood);- insert_struct_rule!(However);- insert_struct_rule!(Overall);- insert_struct_rule!(Worldwide);- insert_struct_rule!(Postpone);- insert_struct_rule!(Misused);- insert_struct_rule!(Misuse);- insert_struct_rule!(Misunderstand);- insert_struct_rule!(Therefore);- insert_struct_rule!(Myself);- insert_struct_rule!(Itself);- insert_struct_rule!(Whereas);- insert_struct_rule!(PossessiveYour);- insert_struct_rule!(SpelledNumbers);- insert_struct_rule!(AnA);- insert_struct_rule!(SentenceCapitalization);- insert_struct_rule!(UnclosedQuotes);- insert_struct_rule!(WrongQuotes);- insert_struct_rule!(LongSentences);- insert_struct_rule!(RepeatedWords);- insert_struct_rule!(Spaces);- insert_struct_rule!(Matcher);- insert_struct_rule!(CorrectNumberSuffix);- insert_struct_rule!(NumberSuffixCapitalization);- insert_struct_rule!(MultipleSequentialPronouns);- insert_struct_rule!(LinkingVerbs);- insert_struct_rule!(AvoidCurses);- insert_struct_rule!(TerminatingConjunctions);- insert_struct_rule!(EllipsisLength);- insert_struct_rule!(DotInitialisms);- insert_struct_rule!(BoringWords);- insert_struct_rule!(UseGenitive);- insert_struct_rule!(ThatWhich);- insert_struct_rule!(CapitalizePersonalPronouns);- insert_struct_rule!(Americas);- insert_struct_rule!(Australia);- insert_struct_rule!(Canada);- insert_struct_rule!(Koreas);- insert_struct_rule!(Malaysia);- insert_struct_rule!(ChineseCommunistParty);- insert_struct_rule!(UnitedOrganizations);- insert_struct_rule!(Holidays);- insert_struct_rule!(AmazonNames);- insert_struct_rule!(GoogleNames);- insert_struct_rule!(MetaNames);- insert_struct_rule!(MicrosoftNames);- insert_struct_rule!(AppleNames);- insert_struct_rule!(AzureNames);- insert_struct_rule!(MergeWords);- insert_struct_rule!(PluralConjugate);- insert_struct_rule!(OxfordComma);- insert_struct_rule!(NoOxfordComma);- insert_struct_rule!(PronounContraction);- insert_struct_rule!(CurrencyPlacement);- insert_struct_rule!(SomewhatSomething);- insert_struct_rule!(LetsConfusion);- insert_struct_rule!(DespiteOf);- insert_struct_rule!(ChockFull);- insert_struct_rule!(Everywhere);+ out.merge_from(&mut proper_noun_capitalization_linters::lint_group(+ dictionary.clone(),+ ));++ insert_struct_rule!(WordPressDotcom, true);+ insert_struct_rule!(OutOfDate, true);+ insert_struct_rule!(Desktop, true);+ insert_struct_rule!(Laptop, true);+ insert_struct_rule!(ThenThan, true);+ insert_struct_rule!(PiqueInterest, true);+ insert_struct_rule!(WasAloud, true);+ insert_struct_rule!(HyphenateNumberDay, true);+ insert_struct_rule!(LeftRightHand, true);+ insert_struct_rule!(HopHope, true);+ insert_struct_rule!(Furthermore, true);+ insert_struct_rule!(Overnight, true);+ insert_struct_rule!(Hereby, true);+ insert_struct_rule!(Likewise, true);+ insert_struct_rule!(CompoundNouns, true);+ insert_struct_rule!(Regardless, true);+ insert_struct_rule!(Henceforth, true);+ insert_struct_rule!(Upward, true);+ insert_struct_rule!(Whereupon, true);+ insert_struct_rule!(Insofar, true);+ insert_struct_rule!(Thereupon, true);+ insert_struct_rule!(Nonetheless, true);+ insert_struct_rule!(Anyhow, true);+ insert_struct_rule!(Notwithstanding, true);+ insert_struct_rule!(Widespread, true);+ insert_struct_rule!(Multimedia, true);+ insert_struct_rule!(Multicore, true);+ insert_struct_rule!(Multithreading, true);+ insert_struct_rule!(Devops, true);+ insert_struct_rule!(Underclock, true);+ insert_struct_rule!(Overload, true);+ insert_struct_rule!(Backplane, true);+ insert_struct_rule!(Overclocking, true);+ insert_struct_rule!(Middleware, true);+ insert_struct_rule!(Somewhere, true);+ insert_struct_rule!(Instead, true);+ insert_struct_rule!(Anywhere, true);+ insert_struct_rule!(Nothing, true);+ insert_struct_rule!(Anybody, true);+ insert_struct_rule!(Somebody, true);+ insert_struct_rule!(Nobody, true);+ insert_struct_rule!(Into, true);+ insert_struct_rule!(Proofread, true);+ insert_struct_rule!(Somehow, true);+ insert_struct_rule!(Intact, true);+ insert_struct_rule!(Upset, true);+ insert_struct_rule!(Misunderstood, true);+ insert_struct_rule!(However, true);+ insert_struct_rule!(Overall, true);+ insert_struct_rule!(Worldwide, true);+ insert_struct_rule!(Postpone, true);+ insert_struct_rule!(Misused, true);+ insert_struct_rule!(Misuse, true);+ insert_struct_rule!(Misunderstand, true);+ insert_struct_rule!(Therefore, true);+ insert_struct_rule!(Myself, true);+ insert_struct_rule!(Itself, true);+ insert_struct_rule!(Whereas, true);+ insert_struct_rule!(PossessiveYour, true);+ insert_struct_rule!(SpelledNumbers, false);+ insert_struct_rule!(AnA, true);+ insert_struct_rule!(SentenceCapitalization, true);+ insert_struct_rule!(UnclosedQuotes, true);+ insert_struct_rule!(WrongQuotes, false);+ insert_struct_rule!(LongSentences, true);+ insert_struct_rule!(RepeatedWords, true);+ insert_struct_rule!(Spaces, true);+ insert_struct_rule!(Matcher, true);+ insert_struct_rule!(CorrectNumberSuffix, true);+ insert_struct_rule!(NumberSuffixCapitalization, true);+ insert_struct_rule!(MultipleSequentialPronouns, true);+ insert_struct_rule!(LinkingVerbs, false);+ insert_struct_rule!(AvoidCurses, true);+ insert_struct_rule!(TerminatingConjunctions, true);+ insert_struct_rule!(EllipsisLength, true);+ insert_struct_rule!(DotInitialisms, true);+ insert_struct_rule!(BoringWords, false);+ insert_struct_rule!(UseGenitive, false);+ insert_struct_rule!(ThatWhich, true);+ insert_struct_rule!(CapitalizePersonalPronouns, true);+ insert_struct_rule!(MergeWords, true);+ insert_struct_rule!(PluralConjugate, false);+ insert_struct_rule!(OxfordComma, true);+ insert_struct_rule!(NoOxfordComma, false);+ insert_struct_rule!(PronounContraction, true);+ insert_struct_rule!(CurrencyPlacement, true);+ insert_struct_rule!(SomewhatSomething, true);+ insert_struct_rule!(LetsConfusion, true);+ insert_struct_rule!(DespiteOf, true);+ insert_struct_rule!(ChockFull, true);+ insert_struct_rule!(Everywhere, true);out.add("SpellCheck", Box::new(SpellCheck::new(dictionary)));-- out.config = config;+ out.config.set_rule_enabled("SpellCheck", true);out}@@ -402,11 +279,8 @@ impl Linter for LintGroup {fn lint(&mut self, document: &Document) -> Vec<Lint> {let mut results = Vec::new();- let mut config = self.config.clone();- config.fill_with_curated_config();-for (key, linter) in &mut self.inner {- if config.is_rule_enabled(key) {+ if self.config.is_rule_enabled(key) {results.extend(linter.lint(document));}}@@ -421,21 +295,19 @@ impl Linter for LintGroup {#[cfg(test)]mod tests {- use crate::{linting::Linter, Document, FstDictionary, MutableDictionary};+ use crate::{linting::Linter, Document, FstDictionary, Lrc, MutableDictionary};use super::{LintGroup, LintGroupConfig};#[test]fn can_get_all_descriptions() {- let group =- LintGroup::new_curated(LintGroupConfig::default(), MutableDictionary::default());+ let group = LintGroup::new_curated(Lrc::new(MutableDictionary::default()));group.all_descriptions();}#[test]fn lint_descriptions_are_clean() {- let mut group =- LintGroup::new_curated(LintGroupConfig::default(), FstDictionary::curated());+ let mut group = LintGroup::new_curated(FstDictionary::curated());let pairs: Vec<_> = group.all_descriptions().into_iter()diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex f4f2f5f7a..3aaad35b4 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -105,14 +105,6 @@ pub use pique_interest::PiqueInterest;pub use plural_conjugate::PluralConjugate;pub use possessive_your::PossessiveYour;pub use pronoun_contraction::PronounContraction;-pub use proper_noun_capitalization_linters::DayOneNames;-pub use proper_noun_capitalization_linters::JetpackNames;-pub use proper_noun_capitalization_linters::PocketCastsNames;-pub use proper_noun_capitalization_linters::TumblrNames;-pub use proper_noun_capitalization_linters::{- AmazonNames, Americas, AppleNames, Australia, AzureNames, Canada, ChineseCommunistParty,- GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,-};pub use repeated_words::RepeatedWords;pub use sentence_capitalization::SentenceCapitalization;pub use somewhat_something::SomewhatSomething;diff --git a/harper-core/src/linting/proper_noun_capitalization_linters.rs b/harper-core/src/linting/proper_noun_capitalization_linters.rsindex 9f540e56b..a2e2edc18 100644--- a/harper-core/src/linting/proper_noun_capitalization_linters.rs+++ b/harper-core/src/linting/proper_noun_capitalization_linters.rs@@ -1,192 +1,200 @@-use super::PatternLinter;use super::{Lint, LintKind, Suggestion};-use crate::make_title_case;+use super::{LintGroup, PatternLinter};use crate::patterns::{EitherPattern, IsNotTitleCase, Pattern, SequencePattern, WordSet};-use crate::FstDictionary;+use crate::{make_title_case, Dictionary};use crate::{Token, TokenStringExt};use std::sync::Arc;-/// A macro that will generate a linter to enforce capitalization of a multi-token proper noun.-macro_rules! create_linter_for {- ($name:ident, $pattern:expr, $message:literal) => {- create_linter_for!($name, $pattern, $message, $message);- };- ($name:ident, $pattern:expr, $message:literal, $description:literal) => {- #[doc = $description]- pub struct $name {- pattern: Box<dyn Pattern>,- dict: Arc<FstDictionary>,+pub struct ProperNounCapitalizationLinter<D: Dictionary + 'static> {+ pattern: Box<dyn Pattern>,+ description: String,+ dictionary: Arc<D>,+}++impl<D: Dictionary + 'static> ProperNounCapitalizationLinter<D> {+ pub fn new(+ search_for: impl Pattern + 'static,+ description: impl ToString,+ dictionary: D,+ ) -> Self {+ let dictionary = Arc::new(dictionary);++ Self {+ pattern: Box::new(IsNotTitleCase::new(+ Box::new(search_for),+ dictionary.clone(),+ )),+ dictionary: dictionary.clone(),+ description: description.to_string(),}+ }+}- impl $name {- pub fn new() -> Self {- let dict = FstDictionary::curated();+impl<D: Dictionary + 'static> PatternLinter for ProperNounCapitalizationLinter<D> {+ fn pattern(&self) -> &dyn Pattern {+ self.pattern.as_ref()+ }- Self {- pattern: Box::new(IsNotTitleCase::new(Box::new($pattern), dict.clone())),- dict,- }- }- }+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {+ let proper = make_title_case(matched_tokens, source, &self.dictionary);- impl Default for $name {- fn default() -> Self {- Self::new()- }+ Lint {+ span: matched_tokens.span().unwrap(),+ lint_kind: LintKind::Capitalization,+ suggestions: vec![Suggestion::ReplaceWith(proper)],+ message: self.description.to_string(),+ priority: 31,}+ }- impl PatternLinter for $name {- fn pattern(&self) -> &dyn Pattern {- self.pattern.as_ref()- }-- fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {- let proper = make_title_case(matched_tokens, source, &self.dict);-- Lint {- span: matched_tokens.span().unwrap(),- lint_kind: LintKind::Capitalization,- suggestions: vec![Suggestion::ReplaceWith(proper)],- message: $message.to_string(),- priority: 31,- }- }-- fn description(&self) -> &'static str {- $description- }- }- };+ fn description(&self) -> &str {+ self.description.as_str()+ }}-create_linter_for!(- Americas,+pub fn lint_group(dictionary: Arc<impl Dictionary + 'static>) -> LintGroup {+ let mut group = LintGroup::empty();++ group.add(+ "Americas",+ Box::new(ProperNounCapitalizationLinter::new(SequencePattern::default().then(Box::new(WordSet::all(&["South", "North", "Central"]))).then_whitespace().t_aco("America"),- "When referring to North, Central, and South America, make sure to treat them as a proper noun."+ "When referring to North, Central, and South America, make sure to treat them as a proper noun.",+ dictionary.clone())));-create_linter_for!(- Australia,- EitherPattern::new(vec![- // the states and territories- Box::new(- SequencePattern::default()- .t_aco("Australian")- .then_whitespace()- .t_aco("Capital")- .then_whitespace()- .t_aco("Territory")- ),- Box::new(- SequencePattern::default()- .t_aco("New")- .then_whitespace()- .t_aco("South")- .then_whitespace()- .t_aco("Wales")- ),- Box::new(- SequencePattern::default()- .t_aco("Northern")- .then_whitespace()- .t_aco("Territory")- ),- Box::new(- SequencePattern::default()- .t_aco("South")- .then_whitespace()- .t_aco("Australia")- ),- Box::new(- SequencePattern::default()- .t_aco("Western")- .then_whitespace()- .t_aco("Australia")- ),- // major cities- Box::new(- SequencePattern::default()- .t_aco("Alice")- .then_whitespace()- .t_aco("Springs")- ),- Box::new(- SequencePattern::default()- .t_aco("Gold")+ group.add(+ "Australia",+ Box::new(ProperNounCapitalizationLinter::new(+ EitherPattern::new(vec![+ // the states and territories+ Box::new(+ SequencePattern::default()+ .t_aco("Australian")+ .then_whitespace()+ .t_aco("Capital")+ .then_whitespace()+ .t_aco("Territory"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("New")+ .then_whitespace()+ .t_aco("South")+ .then_whitespace()+ .t_aco("Wales"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Northern")+ .then_whitespace()+ .t_aco("Territory"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("South")+ .then_whitespace()+ .t_aco("Australia"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Western")+ .then_whitespace()+ .t_aco("Australia"),+ ),+ // major cities+ Box::new(+ SequencePattern::default()+ .t_aco("Alice")+ .then_whitespace()+ .t_aco("Springs"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Gold")+ .then_whitespace()+ .t_aco("Coast"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Sunshine")+ .then_whitespace()+ .t_aco("Coast"),+ ),+ ]),+ "When referring to the states of Australia, make sure to treat them as a proper noun.",+ dictionary.clone(),+ )),+ );++ group.add(+ "Canada",+ Box::new(ProperNounCapitalizationLinter::new(+ EitherPattern::new(vec![+ // the provinces and territories+ Box::new(+ SequencePattern::default()+ .t_aco("British")+ .then_whitespace()+ .t_aco("Columbia"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("New")+ .then_whitespace()+ .t_aco("Brunswick"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Northwest")+ .then_whitespace()+ .t_aco("Territories"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Nova")+ .then_whitespace()+ .t_aco("Scotia"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Prince")+ .then_whitespace()+ .t_aco("Edward")+ .then_whitespace()+ .t_aco("Island"),+ ),+ // major cities+ Box::new(+ SequencePattern::default()+ .t_aco("Quebec")+ .then_whitespace()+ .t_aco("City"),+ ),+ ]),+ "When referring to the provinces of Canada, make sure to treat them as a proper noun.",+ dictionary.clone(),+ )),+ );++ group.add(+ "Koreas",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .then(Box::new(WordSet::all(&["South", "North"]))).then_whitespace()- .t_aco("Coast")- ),- Box::new(- SequencePattern::default()- .t_aco("Sunshine")- .then_whitespace()- .t_aco("Coast")- ),- ]),- "When referring to the states of Australia, make sure to treat them as a proper noun."-);--create_linter_for!(- Canada,- EitherPattern::new(vec![- // the provinces and territories- Box::new(- SequencePattern::default()- .t_aco("British")- .then_whitespace()- .t_aco("Columbia")- ),- Box::new(- SequencePattern::default()- .t_aco("New")- .then_whitespace()- .t_aco("Brunswick")- ),- Box::new(- SequencePattern::default()- .t_aco("Northwest")- .then_whitespace()- .t_aco("Territories")- ),- Box::new(- SequencePattern::default()- .t_aco("Nova")- .then_whitespace()- .t_aco("Scotia")- ),- Box::new(- SequencePattern::default()- .t_aco("Prince")- .then_whitespace()- .t_aco("Edward")- .then_whitespace()- .t_aco("Island")- ),- // major cities- Box::new(- SequencePattern::default()- .t_aco("Quebec")- .then_whitespace()- .t_aco("City")- )- ]),- "When referring to the provinces of Canada, make sure to treat them as a proper noun."-);--create_linter_for!(- Koreas,- SequencePattern::default()- .then(Box::new(WordSet::all(&["South", "North",])))- .then_whitespace()- .t_aco("Korea"),- "When referring to the nations, make sure to treat them as a proper noun."-);--create_linter_for!(- Malaysia,+ .t_aco("Korea"),+ "When referring to the nations, make sure to treat them as a proper noun.",+ dictionary.clone(),+ )),+ );++ group.add(+ "Malaysia",+ Box::new(ProperNounCapitalizationLinter::new(EitherPattern::new(vec![// multi-word statesBox::new(SequencePattern::default()@@ -236,21 +244,26 @@ create_linter_for!(.t_aco("Alam"))]),- "When referring to the states of Malaysia and their capitals, make sure to treat them as a proper noun."-);--create_linter_for!(- ChineseCommunistParty,- SequencePattern::aco("Chinese")- .then_whitespace()- .t_aco("Communist")- .then_whitespace()- .t_aco("Party"),- "When referring to the political party, make sure to treat them as a proper noun."+ "When referring to the states of Malaysia and their capitals, make sure to treat them as a proper noun.",+ dictionary.clone())));-create_linter_for!(- UnitedOrganizations,+ group.add(+ "ChineseCommunistParty",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::aco("Chinese")+ .then_whitespace()+ .t_aco("Communist")+ .then_whitespace()+ .t_aco("Party"),+ "When referring to the political party, make sure to treat them as a proper noun.",+ dictionary.clone(),+ )),+ );++ group.add(+ "UnitedOrganizations",+ Box::new(ProperNounCapitalizationLinter::new(SequencePattern::default().t_aco("United").then_whitespace()@@ -266,158 +279,163 @@ create_linter_for!(.t_aco("Emirates"))]))),- "When referring to national or international organizations, make sure to treat them as a proper noun."-);--create_linter_for!(- Holidays,- EitherPattern::new(vec![- Box::new(- SequencePattern::default()- .then(Box::new(EitherPattern::new(vec![- Box::new(WordSet::all(&[- "Absolution",- "Admission",- "Alaska",- "Anzac",- "ANZAC",- "Arbor",- "Armistice",- "Ascension",- "Australia",- "Ayurveda",- "Bastille",- "Bonifacio",- "Boxing",- "Canada",- "Career",- "Chewidden",- "Christmas",- "Class",- "Columbus",- "Commonwealth",- "D",- "Darwin",- "Discovery",- "Distaff",- "Dominion",- "Earth",- "Easter",- "Election",- "Emancipation",- "Empire",- "Evolution",- "Family",- "Father's",- "Fathers'",- "Flag",- "Forefathers'",- "Foundation",- "Freedom",- "Galentine's",- "Groundhog",- "Gypsy",- "Halloween",- "Independence",- "Invasion",- "Ivy",- "Jamhuri",- "Jubilee",- "Kamehameha",- "Kenyatta",- "Labor",- "Labour",- "Lady",- "Land",- "Lei",- "Madaraka",- "Mashujaa",- "May",- "Memorial",- "Merdeka",- "Midsummer",- "Midsummer's",- "Mother's",- "Mothers'",- "Nakba",- "Nevada",- "Occupation",- "Parents",- "Patrick's",- "Patriots'",- "Pi",- "Picrous",- "Pioneer",- "Presidents'",- "Remembrance",- "Republic",- "Restoration",- "Rizal",- "Roc",- "Rock",- "Seward's",- "Singles'",- "Statehood",- "Tax",- "Thanksgiving",- "Treason",- "Ulster",- "Valentine's",- "VE",- "VJ",- "VP",- "Veterans",- "Victoria",- "Victory",- "Waffle",- "Waitangi",- "Wattle",- "White",- "Wren",- "Years",- "Year's",- "Youth",- ])),- Box::new(- SequencePattern::default()- .t_aco("National")- .then_whitespace()- .t_aco("Freedom")- ),- Box::new(- SequencePattern::default()- .t_aco("All")- .then_whitespace()- .t_aco("Saints")- ),- Box::new(- SequencePattern::default()- .t_aco("All")- .then_whitespace()- .t_aco("Souls")- )- ])))- .then_whitespace()- .t_aco("Day")- ),- Box::new(- SequencePattern::default()- .t_aco("Black")- .then_whitespace()- .t_aco("Friday")- ),- Box::new(- SequencePattern::default()- .t_aco("Cyber")- .then_whitespace()- .t_aco("Monday")- )- ]),- "When referring to holidays, make sure to treat them as a proper noun."+ "When referring to national or international organizations, make sure to treat them as a proper noun.",+ dictionary.clone())));-create_linter_for!(- AmazonNames,+ group.add(+ "Holidays",+ Box::new(ProperNounCapitalizationLinter::new(+ EitherPattern::new(vec![+ Box::new(+ SequencePattern::default()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(WordSet::all(&[+ "Absolution",+ "Admission",+ "Alaska",+ "Anzac",+ "ANZAC",+ "Arbor",+ "Armistice",+ "Ascension",+ "Australia",+ "Ayurveda",+ "Bastille",+ "Bonifacio",+ "Boxing",+ "Canada",+ "Career",+ "Chewidden",+ "Christmas",+ "Class",+ "Columbus",+ "Commonwealth",+ "D",+ "Darwin",+ "Discovery",+ "Distaff",+ "Dominion",+ "Earth",+ "Easter",+ "Election",+ "Emancipation",+ "Empire",+ "Evolution",+ "Family",+ "Father's",+ "Fathers'",+ "Flag",+ "Forefathers'",+ "Foundation",+ "Freedom",+ "Galentine's",+ "Groundhog",+ "Gypsy",+ "Halloween",+ "Independence",+ "Invasion",+ "Ivy",+ "Jamhuri",+ "Jubilee",+ "Kamehameha",+ "Kenyatta",+ "Labor",+ "Labour",+ "Lady",+ "Land",+ "Lei",+ "Madaraka",+ "Mashujaa",+ "May",+ "Memorial",+ "Merdeka",+ "Midsummer",+ "Midsummer's",+ "Mother's",+ "Mothers'",+ "Nakba",+ "Nevada",+ "Occupation",+ "Parents",+ "Patrick's",+ "Patriots'",+ "Pi",+ "Picrous",+ "Pioneer",+ "Presidents'",+ "Remembrance",+ "Republic",+ "Restoration",+ "Rizal",+ "Roc",+ "Rock",+ "Seward's",+ "Singles'",+ "Statehood",+ "Tax",+ "Thanksgiving",+ "Treason",+ "Ulster",+ "Valentine's",+ "VE",+ "VJ",+ "VP",+ "Veterans",+ "Victoria",+ "Victory",+ "Waffle",+ "Waitangi",+ "Wattle",+ "White",+ "Wren",+ "Years",+ "Year's",+ "Youth",+ ])),+ Box::new(+ SequencePattern::default()+ .t_aco("National")+ .then_whitespace()+ .t_aco("Freedom"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("All")+ .then_whitespace()+ .t_aco("Saints"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("All")+ .then_whitespace()+ .t_aco("Souls"),+ ),+ ])))+ .then_whitespace()+ .t_aco("Day"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Black")+ .then_whitespace()+ .t_aco("Friday"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Cyber")+ .then_whitespace()+ .t_aco("Monday"),+ ),+ ]),+ "When referring to holidays, make sure to treat them as a proper noun.",+ dictionary.clone(),+ )),+ );++ group.add(+ "AmazonNames",+ Box::new(ProperNounCapitalizationLinter::new(SequencePattern::default().t_aco("Amazon").then_whitespace()@@ -481,118 +499,125 @@ create_linter_for!(.t_aco("Kindle"))]))),- "When referring to the various products of Amazon.com, make sure to treat them as a proper noun."-);--create_linter_for!(- GoogleNames,- SequencePattern::default()- .t_aco("Google")- .then_whitespace()- .then(Box::new(WordSet::all(&[- "Search",- "Cloud",- "Maps",- "Docs",- "Sheets",- "Slides",- "Drive",- "Meet",- "Gmail",- "Calendar",- "Chrome",- "ChromeOS",- "Android",- "Play",- "Bard",- "Gemini",- "YouTube",- "Photos",- "Analytics",- "AdSense",- "Pixel",- "Nest",- "Workspace",- ]))),- "When referring to Google products and services, make sure to treat them as proper nouns."+ "When referring to the various products of Amazon.com, make sure to treat them as a proper noun.",+ dictionary.clone())));-create_linter_for!(- AzureNames,- SequencePattern::default()- .t_aco("Azure")- .then_whitespace()- .then(Box::new(EitherPattern::new(vec![- Box::new(SequencePattern::aco("DevOps")),- Box::new(SequencePattern::aco("Functions")),- Box::new(- SequencePattern::default()- .t_aco("Cosmos")- .then_whitespace()- .t_aco("DB")- ),- Box::new(- SequencePattern::default()- .t_aco("SQL")- .then_whitespace()- .t_aco("Database")- ),- Box::new(- SequencePattern::default()- .t_aco("Kubernetes")- .then_whitespace()- .t_aco("Service")- ),- Box::new(- SequencePattern::default()- .t_aco("Virtual")- .then_whitespace()- .t_aco("Machines")- ),- Box::new(SequencePattern::aco("Monitor")),- Box::new(SequencePattern::aco("Storage")),- Box::new(- SequencePattern::default()- .t_aco("Active")- .then_whitespace()- .t_aco("Directory")- ),- Box::new(- SequencePattern::default()- .t_aco("App")- .then_whitespace()- .t_aco("Service")- ),- Box::new(- SequencePattern::default()- .t_aco("Key")- .then_whitespace()- .t_aco("Vault")- ),- Box::new(- SequencePattern::default()- .t_aco("Cognitive")- .then_whitespace()- .t_aco("Services")- ),- Box::new(- SequencePattern::default()- .t_aco("Service")- .then_whitespace()- .t_aco("Bus")- ),- Box::new(- SequencePattern::default()- .t_aco("Event")- .then_whitespace()- .t_aco("Hub")- )- ]))),- "When referring to Azure cloud services, make sure to treat them as proper nouns."-);--create_linter_for!(- MicrosoftNames,+ group.add(+ "GoogleNames",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .t_aco("Google")+ .then_whitespace()+ .then(Box::new(WordSet::all(&[+ "Search",+ "Cloud",+ "Maps",+ "Docs",+ "Sheets",+ "Slides",+ "Drive",+ "Meet",+ "Gmail",+ "Calendar",+ "Chrome",+ "ChromeOS",+ "Android",+ "Play",+ "Bard",+ "Gemini",+ "YouTube",+ "Photos",+ "Analytics",+ "AdSense",+ "Pixel",+ "Nest",+ "Workspace",+ ]))),+ "When referring to Google products and services, make sure to treat them as proper nouns."+ ,dictionary.clone()))+ );++ group.add(+ "AzureNames",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .t_aco("Azure")+ .then_whitespace()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(SequencePattern::aco("DevOps")),+ Box::new(SequencePattern::aco("Functions")),+ Box::new(+ SequencePattern::default()+ .t_aco("Cosmos")+ .then_whitespace()+ .t_aco("DB"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("SQL")+ .then_whitespace()+ .t_aco("Database"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Kubernetes")+ .then_whitespace()+ .t_aco("Service"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Virtual")+ .then_whitespace()+ .t_aco("Machines"),+ ),+ Box::new(SequencePattern::aco("Monitor")),+ Box::new(SequencePattern::aco("Storage")),+ Box::new(+ SequencePattern::default()+ .t_aco("Active")+ .then_whitespace()+ .t_aco("Directory"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("App")+ .then_whitespace()+ .t_aco("Service"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Key")+ .then_whitespace()+ .t_aco("Vault"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Cognitive")+ .then_whitespace()+ .t_aco("Services"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Service")+ .then_whitespace()+ .t_aco("Bus"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Event")+ .then_whitespace()+ .t_aco("Hub"),+ ),+ ]))),+ "When referring to Azure cloud services, make sure to treat them as proper nouns.",+ dictionary.clone(),+ )),+ );++ group.add(+ "MicrosoftNames",+ Box::new(ProperNounCapitalizationLinter::new(SequencePattern::default().t_aco("Microsoft").then_whitespace()@@ -620,206 +645,248 @@ create_linter_for!(.t_aco("Studio"))]))),- "When referring to Microsoft products and services, make sure to treat them as proper nouns."-);--create_linter_for!(- AppleNames,- SequencePattern::default()- .t_aco("Apple")- .then_whitespace()- .then(Box::new(EitherPattern::new(vec![- Box::new(WordSet::all(&[- "iPhone", "iPad", "iMac", "MacBook", "Watch", "TV", "Music", "Arcade", "iCloud",- "Safari", "HomeKit", "CarPlay",- ])),- Box::new(- SequencePattern::aco("MacBook")- .then_whitespace()- .t_aco("Pro")- ),- Box::new(- SequencePattern::aco("MacBook")- .then_whitespace()- .t_aco("Air")- ),- Box::new(SequencePattern::aco("Mac").then_whitespace().t_aco("Pro")),- Box::new(SequencePattern::aco("Mac").then_whitespace().t_aco("Mini")),- Box::new(SequencePattern::aco("AirPods")),- Box::new(- SequencePattern::aco("AirPods")- .then_whitespace()- .t_aco("Pro")- ),- Box::new(- SequencePattern::aco("AirPods")- .then_whitespace()- .t_aco("Max")- ),- Box::new(- SequencePattern::default()- .t_aco("Vision")- .then_whitespace()- .t_aco("Pro")- )- ]))),- "When referring to Apple products and services, make sure to treat them as proper nouns."-);--create_linter_for!(- MetaNames,- SequencePattern::aco("Meta")- .then_whitespace()- .then(Box::new(EitherPattern::new(vec![- Box::new(WordSet::all(&[- "Oculus", "Portals", "Quest", "Gaming", "Horizon",- ])),- Box::new(- SequencePattern::default()- .t_aco("Reality")- .then_whitespace()- .t_aco("Labs")- ),- ]))),- "When referring to Meta products and services, make sure to treat them as proper nouns."-);--create_linter_for!(- JetpackNames,- SequencePattern::default()- .t_aco("Jetpack")- .then_whitespace()- .then(Box::new(EitherPattern::new(vec![- Box::new(- SequencePattern::default()- .t_aco("VaultPress")- .then_whitespace()- .t_aco("Backup")- ),- Box::new(SequencePattern::default().t_aco("VaultPress")),- Box::new(SequencePattern::default().t_aco("Scan")),- Box::new(- SequencePattern::default()- .t_aco("Akismet")- .then_whitespace()- .t_aco("Anti-spam")- ),- Box::new(SequencePattern::default().t_aco("Stats")),- Box::new(SequencePattern::default().t_aco("Social")),- Box::new(SequencePattern::default().t_aco("Blaze")),- Box::new(- SequencePattern::default()- .t_aco("AI")- .then_whitespace()- .t_aco("Assistant")- ),- Box::new(- SequencePattern::default()- .t_aco("Site")- .then_whitespace()- .t_aco("Search")- ),- Box::new(SequencePattern::default().t_aco("Boost")),- Box::new(SequencePattern::default().t_aco("VideoPress")),- Box::new(- SequencePattern::default()- .t_aco("For")- .then_whitespace()- .t_aco("Agencies")- ),- Box::new(SequencePattern::default().t_aco("CRM")),- ]))),- "Ensure proper capitalization of Jetpack-related terms."-);--create_linter_for!(- TumblrNames,- SequencePattern::default()- .t_aco("Tumblr")- .then_whitespace()- .then(Box::new(EitherPattern::new(vec![- Box::new(SequencePattern::default().t_aco("Blaze")),- Box::new(SequencePattern::default().t_aco("Pro")),- Box::new(SequencePattern::default().t_aco("Live")),- Box::new(SequencePattern::default().t_aco("Ads")),- Box::new(SequencePattern::default().t_aco("Communities")),- Box::new(SequencePattern::default().t_aco("Shop")),- Box::new(SequencePattern::default().t_aco("Dashboard"))- ]))),- "Ensure proper capitalization of Tumblr-related terms."-);--create_linter_for!(- PocketCastsNames,- EitherPattern::new(vec![- Box::new(- SequencePattern::default()- .t_aco("Pocket")- .then_whitespace()- .t_aco("Casts")- ),- Box::new(- SequencePattern::default()- .t_aco("Pocket")- .then_whitespace()- .t_aco("Casts")- .then_whitespace()- .t_aco("Plus")- )- ]),- "Ensure proper capitalization of Pocket Casts and Pocket Casts Plus as brand names."+ "When referring to Microsoft products and services, make sure to treat them as proper nouns.",+ dictionary.clone())));-create_linter_for!(- DayOneNames,- EitherPattern::new(vec![- Box::new(- SequencePattern::default()- .t_aco("Day")- .then_whitespace()- .t_aco("One")- ),- Box::new(- SequencePattern::default()- .t_aco("Day")+ group.add(+ "AppleNames",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .t_aco("Apple")+ .then_whitespace()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(WordSet::all(&[+ "iPhone", "iPad", "iMac", "MacBook", "Watch", "TV", "Music", "Arcade",+ "iCloud", "Safari", "HomeKit", "CarPlay",+ ])),+ Box::new(+ SequencePattern::aco("MacBook")+ .then_whitespace()+ .t_aco("Pro")+ ),+ Box::new(+ SequencePattern::aco("MacBook")+ .then_whitespace()+ .t_aco("Air")+ ),+ Box::new(SequencePattern::aco("Mac").then_whitespace().t_aco("Pro")),+ Box::new(SequencePattern::aco("Mac").then_whitespace().t_aco("Mini")),+ Box::new(SequencePattern::aco("AirPods")),+ Box::new(+ SequencePattern::aco("AirPods")+ .then_whitespace()+ .t_aco("Pro")+ ),+ Box::new(+ SequencePattern::aco("AirPods")+ .then_whitespace()+ .t_aco("Max")+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Vision")+ .then_whitespace()+ .t_aco("Pro")+ )+ ]))),+ "When referring to Apple products and services, make sure to treat them as proper nouns.",+ dictionary.clone()))++ );++ group.add(+ "MetaNames",+ Box::new(ProperNounCapitalizationLinter::new(SequencePattern::aco("Meta")+ .then_whitespace()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(WordSet::all(&[+ "Oculus", "Portals", "Quest", "Gaming", "Horizon",+ ])),+ Box::new(+ SequencePattern::default()+ .t_aco("Reality")+ .then_whitespace()+ .t_aco("Labs")+ ),+ ]))),+ "When referring to Meta products and services, make sure to treat them as proper nouns."+ , dictionary.clone()+ ))+ );++ group.add(+ "JetpackNames",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .t_aco("Jetpack").then_whitespace()- .t_aco("One")+ .then(Box::new(EitherPattern::new(vec![+ Box::new(+ SequencePattern::default()+ .t_aco("VaultPress")+ .then_whitespace()+ .t_aco("Backup"),+ ),+ Box::new(SequencePattern::default().t_aco("VaultPress")),+ Box::new(SequencePattern::default().t_aco("Scan")),+ Box::new(+ SequencePattern::default()+ .t_aco("Akismet")+ .then_whitespace()+ .t_aco("Anti-spam"),+ ),+ Box::new(SequencePattern::default().t_aco("Stats")),+ Box::new(SequencePattern::default().t_aco("Social")),+ Box::new(SequencePattern::default().t_aco("Blaze")),+ Box::new(+ SequencePattern::default()+ .t_aco("AI")+ .then_whitespace()+ .t_aco("Assistant"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Site")+ .then_whitespace()+ .t_aco("Search"),+ ),+ Box::new(SequencePattern::default().t_aco("Boost")),+ Box::new(SequencePattern::default().t_aco("VideoPress")),+ Box::new(+ SequencePattern::default()+ .t_aco("For")+ .then_whitespace()+ .t_aco("Agencies"),+ ),+ Box::new(SequencePattern::default().t_aco("CRM")),+ ]))),+ "Ensure proper capitalization of Jetpack-related terms.",+ dictionary.clone(),+ )),+ );++ group.add(+ "TumblrNames",+ Box::new(ProperNounCapitalizationLinter::new(+ SequencePattern::default()+ .t_aco("Tumblr").then_whitespace()- .t_aco("Premium")- )- ]),- "Ensure proper capitalization of Day One and Day One Premium as brand names."-);+ .then(Box::new(EitherPattern::new(vec![+ Box::new(SequencePattern::default().t_aco("Blaze")),+ Box::new(SequencePattern::default().t_aco("Pro")),+ Box::new(SequencePattern::default().t_aco("Live")),+ Box::new(SequencePattern::default().t_aco("Ads")),+ Box::new(SequencePattern::default().t_aco("Communities")),+ Box::new(SequencePattern::default().t_aco("Shop")),+ Box::new(SequencePattern::default().t_aco("Dashboard")),+ ]))),+ "Ensure proper capitalization of Tumblr-related terms.",+ dictionary.clone(),+ )),+ );++ group.add(+ "PocketCastsNames",+ Box::new(ProperNounCapitalizationLinter::new(+ EitherPattern::new(vec![+ Box::new(+ SequencePattern::default()+ .t_aco("Pocket")+ .then_whitespace()+ .t_aco("Casts"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Pocket")+ .then_whitespace()+ .t_aco("Casts")+ .then_whitespace()+ .t_aco("Plus"),+ ),+ ]),+ "Ensure proper capitalization of Pocket Casts and Pocket Casts Plus as brand names.",+ dictionary.clone(),+ )),+ );++ group.add(+ "DayOneNames",+ Box::new(ProperNounCapitalizationLinter::new(+ EitherPattern::new(vec![+ Box::new(+ SequencePattern::default()+ .t_aco("Day")+ .then_whitespace()+ .t_aco("One"),+ ),+ Box::new(+ SequencePattern::default()+ .t_aco("Day")+ .then_whitespace()+ .t_aco("One")+ .then_whitespace()+ .t_aco("Premium"),+ ),+ ]),+ "Ensure proper capitalization of Day One and Day One Premium as brand names.",+ dictionary.clone(),+ )),+ );++ group.set_all_rules_to(Some(true));++ group+}#[cfg(test)]mod tests {- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};+ use crate::{+ linting::tests::{assert_lint_count, assert_suggestion_result},+ FstDictionary,+ };- use super::{Americas, MetaNames, MicrosoftNames, UnitedOrganizations};+ use super::lint_group;#[test]fn americas_lowercase() {- assert_suggestion_result("south america", Americas::default(), "South America");- assert_suggestion_result("north america", Americas::default(), "North America");+ assert_suggestion_result(+ "south america",+ lint_group(FstDictionary::curated()),+ "South America",+ );+ assert_suggestion_result(+ "north america",+ lint_group(FstDictionary::curated()),+ "North America",+ );}#[test]fn americas_uppercase() {- assert_suggestion_result("SOUTH AMERICA", Americas::default(), "South America");- assert_suggestion_result("NORTH AMERICA", Americas::default(), "North America");+ assert_suggestion_result(+ "SOUTH AMERICA",+ lint_group(FstDictionary::curated()),+ "South America",+ );+ assert_suggestion_result(+ "NORTH AMERICA",+ lint_group(FstDictionary::curated()),+ "North America",+ );}#[test]fn americas_allow_correct() {- assert_lint_count("South America", Americas::default(), 0);- assert_lint_count("North America", Americas::default(), 0);+ assert_lint_count("South America", lint_group(FstDictionary::curated()), 0);+ assert_lint_count("North America", lint_group(FstDictionary::curated()), 0);}#[test]fn united_nations_uppercase() {assert_suggestion_result("UNITED NATIONS",- UnitedOrganizations::default(),+ lint_group(FstDictionary::curated()),"United Nations",);}@@ -828,26 +895,26 @@ mod tests {fn united_arab_emirates_lowercase() {assert_suggestion_result("UNITED ARAB EMIRATES",- UnitedOrganizations::default(),+ lint_group(FstDictionary::curated()),"United Arab Emirates",);}#[test]fn united_nations_allow_correct() {- assert_lint_count("United Nations", UnitedOrganizations::default(), 0);+ assert_lint_count("United Nations", lint_group(FstDictionary::curated()), 0);}#[test]fn meta_allow_correct() {- assert_lint_count("Meta Quest", MetaNames::default(), 0);+ assert_lint_count("Meta Quest", lint_group(FstDictionary::curated()), 0);}#[test]fn microsoft_lowercase() {assert_suggestion_result("microsoft visual studio",- MicrosoftNames::default(),+ lint_group(FstDictionary::curated()),"Microsoft Visual Studio",);}@@ -856,7 +923,7 @@ mod tests {fn microsoft_first_word_is_correct() {assert_suggestion_result("Microsoft visual studio",- MicrosoftNames::default(),+ lint_group(FstDictionary::curated()),"Microsoft Visual Studio",);}diff --git a/harper-core/tests/run_tests.rs b/harper-core/tests/run_tests.rsindex d230b7c4f..4ded14799 100644--- a/harper-core/tests/run_tests.rs+++ b/harper-core/tests/run_tests.rs@@ -18,10 +18,7 @@ macro_rules! create_test {let dict = FstDictionary::curated();let document = Document::new_markdown_default(&source, &dict);- let mut linter = LintGroup::new_curated(- LintGroupConfig::default(),- dict- );+ let mut linter = LintGroup::new_curated(dict);let lints = linter.lint(&document);dbg!(&lints);diff --git a/harper-html/tests/run_tests.rs b/harper-html/tests/run_tests.rsindex 495b9e906..d7b53fcab 100644--- a/harper-html/tests/run_tests.rs+++ b/harper-html/tests/run_tests.rs@@ -18,10 +18,7 @@ macro_rules! create_test {let dict = FstDictionary::curated();let document = Document::new_markdown_default(&source, &dict);- let mut linter = LintGroup::new_curated(- LintGroupConfig::default(),- dict- );+ let mut linter = LintGroup::new_curated(dict);let lints = linter.lint(&document);dbg!(&lints);diff --git a/harper-literate-haskell/tests/run_tests.rs b/harper-literate-haskell/tests/run_tests.rsindex f0ca14d3d..bf8c734cd 100644--- a/harper-literate-haskell/tests/run_tests.rs+++ b/harper-literate-haskell/tests/run_tests.rs@@ -20,10 +20,7 @@ macro_rules! create_test {let dict = FstDictionary::curated();let document = Document::new_curated(&source, &LiterateHaskellParser::new_markdown(MarkdownOptions::default()));- let mut linter = LintGroup::new_curated(- LintGroupConfig::default(),- dict- );+ let mut linter = LintGroup::new_curated(dict);let lints = linter.lint(&document);dbg!(&lints);diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rsindex 098ae211f..b75d30b72 100644--- a/harper-ls/src/backend.rs+++ b/harper-ls/src/backend.rs@@ -158,7 +158,7 @@ impl Backend {let mut doc_lock = self.doc_state.lock().await;let doc_state = doc_lock.entry(url.clone()).or_insert(DocumentState {- linter: LintGroup::new_curated(lint_config.clone(), dict.clone()),+ linter: LintGroup::new_curated(dict.clone()).with_lint_config(lint_config.clone()),language_id: language_id.map(|v| v.to_string()),dict: dict.clone(),url: url.clone(),@@ -167,7 +167,8 @@ impl Backend {if doc_state.dict != dict {doc_state.dict = dict.clone();- doc_state.linter = LintGroup::new_curated(lint_config.clone(), dict.clone());+ doc_state.linter =+ LintGroup::new_curated(dict.clone()).with_lint_config(lint_config.clone());}let Some(language_id) = &doc_state.language_id else {@@ -190,7 +191,8 @@ impl Backend {merged.add_dictionary(new_dict);let merged = Arc::new(merged);- doc_state.linter = LintGroup::new_curated(lint_config.clone(), merged.clone());+ doc_state.linter =+ LintGroup::new_curated(merged.clone()).with_lint_config(lint_config.clone());doc_state.dict = merged.clone();}@@ -588,8 +590,8 @@ impl LanguageServer for Backend {let config_lock = self.config.read().await;for doc in doc_lock.values_mut() {- doc.linter =- LintGroup::new_curated(config_lock.lint_config.clone(), doc.dict.clone());+ doc.linter = LintGroup::new_curated(doc.dict.clone())+ .with_lint_config(config_lock.lint_config.clone());}doc_lock.keys().cloned().collect()diff --git a/harper-typst/tests/run_tests.rs b/harper-typst/tests/run_tests.rsindex 5f1fd8149..84ba9eddb 100644--- a/harper-typst/tests/run_tests.rs+++ b/harper-typst/tests/run_tests.rs@@ -19,10 +19,7 @@ macro_rules! create_test {let dict = FstDictionary::curated();let document = Document::new(&source, &Typst, &dict);- let mut linter = LintGroup::new_curated(- LintGroupConfig::default(),- dict- );+ let mut linter = LintGroup::new_curated(dict);let lints = linter.lint(&document);dbg!(&lints);diff --git a/harper-wasm/src/lib.rs b/harper-wasm/src/lib.rsindex 59ba89c14..13645bbd7 100644--- a/harper-wasm/src/lib.rs+++ b/harper-wasm/src/lib.rs@@ -4,7 +4,7 @@ use std::convert::Into;use std::sync::Arc;use harper_core::language_detection::is_doc_likely_english;-use harper_core::linting::{LintGroup, LintGroupConfig, Linter as _};+use harper_core::linting::{LintGroup, Linter as _};use harper_core::parsers::{IsolateEnglish, Markdown, Parser, PlainEnglish};use harper_core::{remove_overlaps, CharString, Dictionary, Document, FstDictionary, IgnoredLints, Lrc,@@ -82,7 +82,7 @@ impl Linter {let dictionary = Self::construct_merged_dict(MutableDictionary::default());Self {- lint_group: LintGroup::new_curated(LintGroupConfig::default(), dictionary.clone()),+ lint_group: LintGroup::new_curated(dictionary.clone()),user_dictionary: MutableDictionary::new(),dictionary,ignored_lints: IgnoredLints::default(),@@ -94,7 +94,8 @@ impl Linter {fn synchronize_lint_dict(&mut self) {let lint_config = self.lint_group.config.clone();self.dictionary = Self::construct_merged_dict(self.user_dictionary.clone());- self.lint_group = LintGroup::new_curated(lint_config, self.dictionary.clone());+ self.lint_group =+ LintGroup::new_curated(self.dictionary.clone()).with_lint_config(lint_config);}/// Construct the actual dictionary to be used for linting and parsing from the curated dictionary@@ -372,16 +373,14 @@ impl Lint {#[wasm_bindgen]pub fn get_default_lint_config_as_json() -> String {- let mut config = LintGroupConfig::default();- config.fill_with_curated_config();+ let config = LintGroup::new_curated(MutableDictionary::new().into()).config;serde_json::to_string(&config).unwrap()}#[wasm_bindgen]pub fn get_default_lint_config() -> JsValue {- let mut config = LintGroupConfig::default();- config.fill_with_curated_config();+ let config = LintGroup::new_curated(MutableDictionary::new().into()).config;// Important for downstream JSON serializationlet serializer = serde_wasm_bindgen::Serializer::json_compatible();