Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
Merge branch 'master' of https://github.com/Automattic/harper into noun-to-nominal
hippietrail5fe3c7bc0dc2
diff --cc harper-core/src/linting/compound_nominals/implied_action_compound_nominals.rsindex 000000000,de3207e38..6cbed1860mode 000000,100644..100644--- a/harper-core/src/linting/compound_nominals/implied_action_compound_nominals.rs+++ b/harper-core/src/linting/compound_nominals/implied_action_compound_nominals.rs@@@ -1,0 -1,64 +1,64 @@@+ use crate::{+ CharStringExt, Lrc, TokenStringExt, linting::PatternLinter, patterns::SplitCompoundWord,+ };++ use super::{Lint, LintKind, Suggestion};++ use crate::{+ Token,+ patterns::{Pattern, SequencePattern},+ };+-/// Looks for closed compound nouns which can be condensed due to their position after a-/// possessive noun (which implies ownership).-pub struct ImpliedActionCompoundNouns {++/// Looks for closed compound nominals which can be condensed due to their position after a++/// possessive nominal (which implies ownership).++pub struct ImpliedActionCompoundNominals {+ pattern: Box<dyn Pattern>,+ split_pattern: Lrc<SplitCompoundWord>,+ }+-impl Default for ImpliedActionCompoundNouns {++impl Default for ImpliedActionCompoundNominals {+ fn default() -> Self {- let split_pattern = Lrc::new(SplitCompoundWord::new(|meta| meta.is_noun()));++ let split_pattern = Lrc::new(SplitCompoundWord::new(|meta| meta.is_nominal()));+ let pattern = SequencePattern::default()+ .then(split_pattern.clone())+ .then_whitespace()+ .then(|tok: &Token, _source: &[char]| {+ tok.kind.is_verb() && !tok.kind.is_likely_homograph()+ });++ Self {+ pattern: Box::new(pattern),+ split_pattern,+ }+ }+ }+-impl PatternLinter for ImpliedActionCompoundNouns {++impl PatternLinter for ImpliedActionCompoundNominals {+ fn pattern(&self) -> &dyn Pattern {+ self.pattern.as_ref()+ }++ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {+ let span = matched_tokens[0..3].span()?;+ let orig = span.get_content(source);+ // If the pattern matched, this will not return `None`.+ let word =+ self.split_pattern+ .get_merged_word(matched_tokens[0], matched_tokens[2], source)?;++ Some(Lint {+ span,+ lint_kind: LintKind::WordChoice,+ suggestions: vec![Suggestion::replace_with_match_case(word.to_vec(), orig)],+ message: format!(- "The verb here implies the existence of the closed compound noun “{}”.",++ "The verb here implies the existence of the closed compound nominal “{}”.",+ word.to_string()+ ),+ priority: 63,+ })+ }++ fn description(&self) -> &str {- "Detects split compound nouns preceding an action and suggests merging them."++ "Detects split compound nominals preceding an action and suggests merging them."+ }+ }diff --cc harper-core/src/linting/compound_nominals/mod.rsindex 14fa72704,9cf3033d6..03b3a2761--- a/harper-core/src/linting/compound_nominals/mod.rs+++ b/harper-core/src/linting/compound_nominals/mod.rs@@@ -1,12 -1,14 +1,14 @@@-mod general_compound_nouns;-mod implied_action_compound_nouns;-mod implied_ownership_compound_nouns;+mod general_compound_nominals;++mod implied_action_compound_nominals;+mod implied_ownership_compound_nominals;use super::{Lint, LintKind, Suggestion, merge_linters::merge_linters};-use general_compound_nouns::GeneralCompoundNouns;-use implied_action_compound_nouns::ImpliedActionCompoundNouns;-use implied_ownership_compound_nouns::ImpliedOwnershipCompoundNouns;+use general_compound_nominals::GeneralCompoundNominals;++use implied_action_compound_nominals::ImpliedActionCompoundNominals;+use implied_ownership_compound_nominals::ImpliedOwnershipCompoundNominals;- merge_linters!(CompoundNominals => GeneralCompoundNominals, ImpliedOwnershipCompoundNominals => "Detects compound nouns split by a space and suggests merging them when both parts form a valid noun." );-merge_linters!(CompoundNouns => GeneralCompoundNouns, ImpliedOwnershipCompoundNouns, ImpliedActionCompoundNouns => "Detects compound nouns split by a space and suggests merging them when both parts form a valid noun." );++merge_linters!(CompoundNominals => GeneralCompoundNominals, ImpliedOwnershipCompoundNominals, ImpliedActionCompoundNominals => "Detects compound nouns split by a space and suggests merging them when both parts form a valid noun." );#[cfg(test)]mod tests {@@@ -264,4 -266,22 +266,22 @@@0,);}++ #[test]+ fn allows_issue_721() {+ assert_lint_count(+ "So if you adjust any one of these adjusters that can have a negative or a positive effect.",- CompoundNouns::default(),++ CompoundNominals::default(),+ 0,+ );+ }++ #[test]+ fn allows_678() {+ assert_lint_count(+ "they can't catch all the bugs.",- CompoundNouns::default(),++ CompoundNominals::default(),+ 0,+ );+ }}diff --cc harper-core/src/linting/possessive_your.rsindex 4cf012548,ed9326c1e..511c6c9c9--- a/harper-core/src/linting/possessive_your.rs+++ b/harper-core/src/linting/possessive_your.rs@@@ -15,7 -15,7 +15,7 @@@ impl Default for PossessiveYourSequencePattern::aco("you").then_whitespace().then(|tok: &Token, _source: &[char]| {- tok.kind.is_nominal() && !tok.kind.is_verb() && !tok.kind.is_adverb()- tok.kind.is_noun() && !tok.kind.is_likely_homograph()++ tok.kind.is_nominal() && !tok.kind.is_likely_homograph()});Self {