Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
refactor: made a new `lint_group` from two mass noun linters (#2290)
Andrew Dunbar233045631186
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex 45b959108..d107b5cfe 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -96,7 +96,7 @@ use super::lets_confusion::LetsConfusion;use super::likewise::Likewise;use super::long_sentences::LongSentences;use super::looking_forward_to::LookingForwardTo;-use super::mass_plurals::MassPlurals;+use super::mass_nouns::MassNouns;use super::merge_words::MergeWords;use super::missing_preposition::MissingPreposition;use super::missing_to::MissingTo;@@ -117,7 +117,6 @@ use super::no_match_for::NoMatchFor;use super::no_oxford_comma::NoOxfordComma;use super::nobody::Nobody;use super::nominal_wants::NominalWants;-use super::noun_countability::NounCountability;use super::noun_verb_confusion::NounVerbConfusion;use super::number_suffix_capitalization::NumberSuffixCapitalization;use super::of_course::OfCourse;@@ -480,7 +479,6 @@ impl LintGroup {));out.merge_from(&mut closed_compounds::lint_group());out.merge_from(&mut initialisms::lint_group());- // out.merge_from(&mut update_place_names::lint_group());// Add all the more complex rules to the group.// Please maintain alphabetical order.@@ -586,7 +584,6 @@ impl LintGroup {insert_struct_rule!(NoOxfordComma, false);insert_expr_rule!(Nobody, true);insert_expr_rule!(NominalWants, true);- insert_expr_rule!(NounCountability, true);insert_struct_rule!(NounVerbConfusion, true);insert_struct_rule!(NumberSuffixCapitalization, true);insert_expr_rule!(OfCourse, true);@@ -691,8 +688,8 @@ impl LintGroup {out.add("HaveTakeALook", HaveTakeALook::new(dialect));out.config.set_rule_enabled("HaveTakeALook", true);- out.add("MassPlurals", MassPlurals::new(dictionary.clone()));- out.config.set_rule_enabled("MassPlurals", true);+ out.add("MassNouns", MassNouns::new(dictionary.clone()));+ out.config.set_rule_enabled("MassNouns", true);out.add("UseTitleCase", UseTitleCase::new(dictionary.clone()));out.config.set_rule_enabled("UseTitleCase", true);diff --git a/harper-core/src/linting/mass_plurals.rs b/harper-core/src/linting/mass_nouns/mass_plurals.rssimilarity index 100%rename from harper-core/src/linting/mass_plurals.rsrename to harper-core/src/linting/mass_nouns/mass_plurals.rsdiff --git a/harper-core/src/linting/mass_nouns/mod.rs b/harper-core/src/linting/mass_nouns/mod.rsnew file mode 100644index 000000000..15ee951e9--- /dev/null+++ b/harper-core/src/linting/mass_nouns/mod.rs@@ -0,0 +1,86 @@+mod mass_plurals;+mod noun_countability;++use mass_plurals::MassPlurals;+use noun_countability::NounCountability;++use crate::{+ Document,+ linting::{Lint, Linter},+ remove_overlaps,+ spell::Dictionary,+};++pub struct MassNouns<D> {+ mass_plurals: MassPlurals<D>,+ noun_countability: NounCountability,+}++impl<D> MassNouns<D>+where+ D: Dictionary + Clone,+{+ pub fn new(dict: D) -> Self {+ Self {+ mass_plurals: MassPlurals::new(dict.clone()),+ noun_countability: NounCountability::default(),+ }+ }+}++impl<D> Linter for MassNouns<D>+where+ D: Dictionary,+{+ fn lint(&mut self, document: &Document) -> Vec<Lint> {+ let mut lints = Vec::new();++ lints.extend(self.mass_plurals.lint(document));+ lints.extend(self.noun_countability.lint(document));++ remove_overlaps(&mut lints);++ lints+ }++ fn description(&self) -> &'static str {+ "Detects mass nouns used as countable nouns."+ }+}++#[cfg(test)]+mod tests {+ use crate::{+ linting::tests::{assert_lint_count, assert_suggestion_result},+ spell::FstDictionary,+ };++ use super::MassNouns;++ #[test]+ fn flag_advices_and_an_advice() {+ assert_lint_count(+ "I asked for an advice and he gave me two advices!",+ MassNouns::new(FstDictionary::curated()),+ 2,+ );+ }++ #[test]+ fn correct_a_luggage() {+ assert_suggestion_result(+ "I managed to pack all my clothing into one luggage.",+ MassNouns::new(FstDictionary::curated()),+ "I managed to pack all my clothing into one suitcase.",+ );+ }++ #[test]+ fn correct_clothings() {+ assert_suggestion_result(+ "I managed to pack all my clothings into one suitcase.",+ MassNouns::new(FstDictionary::curated()),+ "I managed to pack all my clothing into one suitcase.",+ );+ }+}diff --git a/harper-core/src/linting/noun_countability.rs b/harper-core/src/linting/mass_nouns/noun_countability.rssimilarity index 100%rename from harper-core/src/linting/noun_countability.rsrename to harper-core/src/linting/mass_nouns/noun_countability.rsdiff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex f7bca37a2..5b7da2726 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -102,7 +102,7 @@ mod long_sentences;mod looking_forward_to;mod map_phrase_linter;mod map_phrase_set_linter;-mod mass_plurals;+mod mass_nouns;mod merge_linters;mod merge_words;mod missing_preposition;@@ -125,7 +125,6 @@ mod no_match_for;mod no_oxford_comma;mod nobody;mod nominal_wants;-mod noun_countability;mod noun_verb_confusion;mod number_suffix_capitalization;mod of_course;