Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions harper-core/src/linting/lint_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
86 changes: 86 additions & 0 deletions harper-core/src/linting/mass_nouns/mod.rs
Original file line number Diff line number Diff line change
@@ -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.",
);
}
}
3 changes: 1 addition & 2 deletions harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading