diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs index d0b54ae31..4e859a6e1 100644 --- a/harper-core/src/linting/lint_group.rs +++ b/harper-core/src/linting/lint_group.rs @@ -95,7 +95,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; @@ -116,7 +116,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; @@ -479,7 +478,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. @@ -584,7 +582,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); @@ -689,8 +686,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.rs similarity index 100% rename from harper-core/src/linting/mass_plurals.rs rename to harper-core/src/linting/mass_nouns/mass_plurals.rs diff --git a/harper-core/src/linting/mass_nouns/mod.rs b/harper-core/src/linting/mass_nouns/mod.rs new file mode 100644 index 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 { + mass_plurals: MassPlurals, + noun_countability: NounCountability, +} + +impl MassNouns +where + D: Dictionary + Clone, +{ + pub fn new(dict: D) -> Self { + Self { + mass_plurals: MassPlurals::new(dict.clone()), + noun_countability: NounCountability::default(), + } + } +} + +impl Linter for MassNouns +where + D: Dictionary, +{ + fn lint(&mut self, document: &Document) -> Vec { + 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.rs similarity index 100% rename from harper-core/src/linting/noun_countability.rs rename to harper-core/src/linting/mass_nouns/noun_countability.rs diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs index 20639a87f..984757c51 100644 --- a/harper-core/src/linting/mod.rs +++ b/harper-core/src/linting/mod.rs @@ -101,7 +101,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; @@ -124,7 +124,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;