Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: give `MassPlurals` higher priority than `SplitWords` (#4347)
Andrew Dunbar2064305b7169
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rsindex 757c459f7..426b4e142 100644--- a/harper-core/src/linting/lint_group/mod.rs+++ b/harper-core/src/linting/lint_group/mod.rs@@ -1378,4 +1378,13 @@ mod tests {}}}++ #[test]+ fn spellcheck_beats_split_words_for_advices_4346() {+ assert_suggestion_result(+ "IMO these kind of advices never matters.",+ test_linter(),+ "IMO these kind of advice never matters.",+ );+ }}diff --git a/harper-core/src/linting/mass_nouns/mass_plurals.rs b/harper-core/src/linting/mass_nouns/mass_plurals.rsindex 041cd2568..6dcb78f64 100644--- a/harper-core/src/linting/mass_nouns/mass_plurals.rs+++ b/harper-core/src/linting/mass_nouns/mass_plurals.rs@@ -132,7 +132,8 @@ impl<D: Dictionary> ExprLinter for MassPlurals<D> {lint_kind: LintKind::Grammar,suggestions,message,- ..Default::default()+ // higher priority (lower number) than split words+ priority: 30,})}@@ -144,18 +145,31 @@ impl<D: Dictionary> ExprLinter for MassPlurals<D> {#[cfg(test)]mod tests {use crate::{- linting::tests::{assert_lint_count, assert_suggestion_result},+ Dialect,+ linting::{+ LintGroup,+ tests::{assert_lint_count, assert_suggestion_result},+ },spell::FstDictionary,};use super::MassPlurals;#[test]- fn flag_advicess() {- assert_lint_count(+ fn fix_bad_advices() {+ assert_suggestion_result("You gave me bad advices.",MassPlurals::new(FstDictionary::curated()),- 1,+ "You gave me bad advice.",+ );+ }++ #[test]+ fn fix_kind_of_advices() {+ assert_suggestion_result(+ "IMO these kind of advices never matters.",+ LintGroup::new_curated(FstDictionary::curated(), Dialect::American),+ "IMO these kind of advice never matters.",);}diff --git a/harper-core/src/linting/regionalisms.rs b/harper-core/src/linting/regionalisms.rsindex 3a99434f9..0b6e918fd 100644--- a/harper-core/src/linting/regionalisms.rs+++ b/harper-core/src/linting/regionalisms.rs@@ -2,7 +2,7 @@ use crate::{Dialect::{self, American, Australian, British, Canadian, Indian},Token, TokenStringExt,expr::{Expr, FirstMatchOf, FixedPhrase},- linting::{Lint, LintKind, Suggestion, spell_check},+ linting::{Lint, LintKind, Suggestion},};use super::ExprLinter;@@ -747,8 +747,9 @@ impl ExprLinter for Regionalisms {suggestions,message,// TODO is the priority below confusing the higher priority and higher number?- // TODO was 64 here vs 63 in spellcheck- priority: spell_check::SPELL_CHECK_PRIORITY + 1, // higher priority = lower number+ // TODO spellcheck is 63+ // higher priority = lower number+ priority: 64,})}diff --git a/harper-core/src/linting/repeated_words.rs b/harper-core/src/linting/repeated_words.rsindex 4943bf06f..eb7a13628 100644--- a/harper-core/src/linting/repeated_words.rs+++ b/harper-core/src/linting/repeated_words.rs@@ -4,8 +4,6 @@ use crate::char_string::char_string;use crate::linting::informal_laughter::is_informal_laughter;use crate::{CharString, CharStringExt, Document, Span};-pub const REPEATED_WORDS_PRIORITY: u8 = 128;-#[derive(Debug, Clone)]pub struct RepeatedWords {/// Words that we need to make sure are detected.@@ -79,7 +77,8 @@ impl Linter for RepeatedWords {document.get_span_content(&tok_a.span).to_vec(),)],message: "Did you mean to repeat this word?".to_owned(),- priority: REPEATED_WORDS_PRIORITY, // Lower priority (higher number) than `TheTheToThatThe`+ // Lower priority (higher number) than `TheTheToThatThe`+ priority: 128,})}}diff --git a/harper-core/src/linting/spell_check.rs b/harper-core/src/linting/spell_check.rsindex 1d6ec70ec..7999d37d2 100644--- a/harper-core/src/linting/spell_check.rs+++ b/harper-core/src/linting/spell_check.rs@@ -10,8 +10,6 @@ use crate::expr::{Filter, SequenceExpr};use crate::spell::{Dictionary, suggest_correct_spelling};use crate::{CharString, CharStringExt, Dialect, TokenStringExt, remove_lints_overlapping_expr};-pub const SPELL_CHECK_PRIORITY: u8 = 63;-pub struct SpellCheck<T>whereT: Dictionary,@@ -149,7 +147,7 @@ impl<T: Dictionary> Linter for SpellCheck<T> {lint_kind: LintKind::Spelling,suggestions,message,- priority: SPELL_CHECK_PRIORITY,+ priority: 63,})}diff --git a/harper-core/src/linting/split_words.rs b/harper-core/src/linting/split_words.rsindex 185bbedd5..e1facf359 100644--- a/harper-core/src/linting/split_words.rs+++ b/harper-core/src/linting/split_words.rs@@ -2,14 +2,16 @@ use std::sync::Arc;use hashbrown::HashSet;-use crate::expr::Expr;-use crate::linting::{- ExprLinter, LintKind, Suggestion,- expr_linter::{Chunk, at_start_of_sentence, preceded_by_word},- informal_laughter::is_informal_laughter,+use crate::{+ Lint, Token,+ expr::Expr,+ linting::{+ ExprLinter, LintKind, Suggestion,+ expr_linter::{Chunk, at_start_of_sentence, preceded_by_word},+ informal_laughter::is_informal_laughter,+ },+ spell::{Dictionary, FstDictionary, TrieDictionary},};-use crate::spell::{Dictionary, FstDictionary, TrieDictionary};-use crate::{Lint, Token};pub struct SplitWords {dict: Arc<TrieDictionary<Arc<FstDictionary>>>,diff --git a/harper-core/src/linting/the_the_to_that_the.rs b/harper-core/src/linting/the_the_to_that_the.rsindex c84730dba..41bf30c28 100644--- a/harper-core/src/linting/the_the_to_that_the.rs+++ b/harper-core/src/linting/the_the_to_that_the.rs@@ -1,7 +1,7 @@use crate::{CharStringExt, Lint, Token, TokenStringExt,expr::{Expr, SequenceExpr},- linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk, repeated_words},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},};pub struct TheTheToThatThe {@@ -40,7 +40,8 @@ impl ExprLinter for TheTheToThatThe {.map(|s| Suggestion::replace_with_match_case_str(s, ch)).collect(),message: "Did you mean `that the` or just `the`?".to_owned(),- priority: repeated_words::REPEATED_WORDS_PRIORITY - 2, // Higher priority (lower number) than `RepeatedWords`+ // Higher priority (lower number) than `RepeatedWords`+ priority: 126,})}diff --git a/harper-core/src/linting/wrong_negative.rs b/harper-core/src/linting/wrong_negative.rsindex 35b1a8fa2..e38167049 100644--- a/harper-core/src/linting/wrong_negative.rs+++ b/harper-core/src/linting/wrong_negative.rs@@ -1,7 +1,7 @@use crate::{CharStringExt, Lint, Token,expr::Expr,- linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk, spell_check},+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},spell::Dictionary,};@@ -78,7 +78,8 @@ impl<D: Dictionary + 'static> ExprLinter for WrongNegative<D> {}.to_string(),suggestions,- priority: spell_check::SPELL_CHECK_PRIORITY - 1, // higher priority (lower number) than spell check+ // higher priority (lower number) than spell check+ priority: 62,})}