Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

refactor(core): remove bad lints and make `Nobody` more specific.

Elijah Potter1d264361595a
diff --git a/harper-core/affixes.json b/harper-core/affixes.json
index 2c72dce7b..46475bbfd 100644
--- a/harper-core/affixes.json
+++ b/harper-core/affixes.json
@@ -596,6 +596,15 @@
"gifts_metadata": {
"article": true
}
+ },
+ "j": {
+ "suffix": true,
+ "cross_product": true,
+ "replacements": [],
+ "adds_metadata": {},
+ "gifts_metadata": {
+ "adverb": {}
+ }
}
}
}
diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dict
index 675c495ea..f49c3c8ee 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -34720,7 +34720,7 @@ our/4S~
ourselves/8
oust/4ZGDRS
ouster/14M
-out/+145SJGMDR~
+out/+145SJGMDR~j
outage/1SM
outargue/4GDS
outback/154MS
@@ -34799,7 +34799,8 @@ outlying/51
outmaneuver/4GDS
outmatch/4GDS
outmoded/54
-outnumber/4DSG
+outnumber/4DG
+outnumbers/5
outpace/4GDS
outpatient/15MS
outperform/4GSD
diff --git a/harper-core/src/linting/closed_compounds.rs b/harper-core/src/linting/closed_compounds.rs
index 11c72e30e..507f8a8d7 100644
--- a/harper-core/src/linting/closed_compounds.rs
+++ b/harper-core/src/linting/closed_compounds.rs
@@ -72,7 +72,6 @@ create_closed_compound_linter!(Upset, "up set", "upset");
create_closed_compound_linter!(Intact, "in tact", "intact");
create_closed_compound_linter!(Somehow, "some how", "somehow");
create_closed_compound_linter!(Proofread, "proof read", "proofread");
-create_closed_compound_linter!(Nobody, "no body", "nobody");
create_closed_compound_linter!(Somebody, "some body", "somebody");
create_closed_compound_linter!(Anybody, "any body", "anybody");
create_closed_compound_linter!(Nothing, "no thing", "nothing");
diff --git a/harper-core/src/linting/compound_nouns.rs b/harper-core/src/linting/compound_nouns.rs
index f516c8f56..7c7f6df9b 100644
--- a/harper-core/src/linting/compound_nouns.rs
+++ b/harper-core/src/linting/compound_nouns.rs
@@ -75,6 +75,7 @@ impl Linter for CompoundNouns {
|| matches!(b_chars.as_slice(), &['i', 's'])
|| a_meta.article
|| b_meta.article
+ || (a_meta.is_verb() && b_meta.is_adverb())
{
continue;
}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 6010c7b3c..2a15a6f4a 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -6,13 +6,11 @@ use super::avoid_curses::AvoidCurses;
use super::boring_words::BoringWords;
use super::capitalize_personal_pronouns::CapitalizePersonalPronouns;
use super::closed_compounds::{
- Altogether, Anybody, Anyhow, Anywhere, Asleep, Backplane, Devops, Downright, Ecommerce,
- Everywhere, Forthwith, Henceforth, Hereafter, Hereby, Hereunder, However, Insofar, Instead,
- Intact, Into, Itself, Likewise, Middleware, Misunderstand, Misunderstood, Misuse, Misused,
- Multicore, Multimedia, Multithreading, Myself, Nobody, Nonetheless, Nothing, Notwithstanding,
- Otherwise, Overall, Overclocking, Overload, Postpone, Proofread, Regardless, Somebody, Somehow,
- Somewhere, Thereafter, Therefore, Therein, Thereupon, Tonight, Underclock, Upset, Upward,
- Whereupon, Widespread, Worldwide,
+ Anybody, Anyhow, Anywhere, Backplane, Devops, Everywhere, Henceforth, Hereafter, However,
+ Insofar, Instead, Intact, Into, Itself, Middleware, Misunderstand, Misunderstood, Misuse,
+ Misused, Multicore, Multimedia, Multithreading, Myself, Nonetheless, Nothing, Notwithstanding,
+ Overall, Overclocking, Overload, Postpone, Proofread, Regardless, Somebody, Somehow, Somewhere,
+ Therefore, Thereupon, Underclock, Upset, Upward, Whereupon, Widespread, Worldwide,
};
use super::compound_nouns::CompoundNouns;
use super::correct_number_suffix::CorrectNumberSuffix;
@@ -25,6 +23,7 @@ use super::long_sentences::LongSentences;
use super::matcher::Matcher;
use super::merge_words::MergeWords;
use super::multiple_sequential_pronouns::MultipleSequentialPronouns;
+use super::nobody::Nobody;
use super::number_suffix_capitalization::NumberSuffixCapitalization;
use super::phrase_corrections::{
AndAlike, BadRap, BatedBreath, BeckAndCall, ChangeTack, EnMasse, HumanLife, HungerPang,
@@ -175,22 +174,14 @@ create_lint_group_config!(
Regardless => true,
Henceforth => true,
Upward => true,
- Downright => true,
- Thereafter => true,
Whereupon => true,
Insofar => true,
- Forthwith => true,
- Hereunder => true,
- Hereby => true,
Thereupon => true,
- Therein => true,
- Otherwise => true,
Hereafter => true,
Nonetheless => true,
Anyhow => true,
Notwithstanding => true,
Widespread => true,
- Ecommerce => true,
Multimedia => true,
Multicore => true,
Multithreading => true,
@@ -213,10 +204,7 @@ create_lint_group_config!(
Intact => true,
Upset => true,
Misunderstood => true,
- Asleep => true,
- Altogether => true,
However => true,
- Likewise => true,
Overall => true,
Worldwide => true,
Postpone => true,
@@ -225,7 +213,6 @@ create_lint_group_config!(
Misunderstand => true,
Therefore => true,
Myself => true,
- Tonight => true,
Itself => true,
Whereas => true,
SpelledNumbers => false,
@@ -322,7 +309,11 @@ mod tests {
for (key, value) in pairs {
let doc = Document::new_markdown_default_curated(&value);
eprintln!("{key}: {value}");
- assert!(group.lint(&doc).is_empty())
+
+ if !group.lint(&doc).is_empty() {
+ dbg!(&group.lint(&doc));
+ panic!();
+ }
}
}
}
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index a2ed90cb9..323e08cc0 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -25,6 +25,7 @@ mod merge_linters;
mod merge_words;
mod multiple_sequential_pronouns;
mod no_oxford_comma;
+mod nobody;
mod number_suffix_capitalization;
mod oxford_comma;
mod pattern_linter;
@@ -51,13 +52,11 @@ pub use avoid_curses::AvoidCurses;
pub use boring_words::BoringWords;
pub use capitalize_personal_pronouns::CapitalizePersonalPronouns;
pub use closed_compounds::{
- Altogether, Anybody, Anyhow, Anywhere, Asleep, Backplane, Devops, Downright, Ecommerce,
- Everywhere, Forthwith, Henceforth, Hereafter, Hereby, Hereunder, However, Insofar, Instead,
- Intact, Into, Itself, Likewise, Middleware, Misunderstand, Misunderstood, Misuse, Misused,
- Multicore, Multimedia, Multithreading, Myself, Nobody, Nonetheless, Nothing, Notwithstanding,
- Otherwise, Overall, Overclocking, Overload, Postpone, Proofread, Regardless, Somebody, Somehow,
- Somewhere, Thereafter, Therefore, Therein, Thereupon, Tonight, Underclock, Upset, Upward,
- Whereupon, Widespread, Worldwide,
+ Anybody, Anyhow, Anywhere, Backplane, Devops, Everywhere, Henceforth, Hereafter, However,
+ Insofar, Instead, Intact, Into, Itself, Middleware, Misunderstand, Misunderstood, Misuse,
+ Misused, Multicore, Multimedia, Multithreading, Myself, Nonetheless, Nothing, Notwithstanding,
+ Overall, Overclocking, Overload, Postpone, Proofread, Regardless, Somebody, Somehow, Somewhere,
+ Therefore, Thereupon, Underclock, Upset, Upward, Whereupon, Widespread, Worldwide,
};
pub use compound_nouns::CompoundNouns;
pub use correct_number_suffix::CorrectNumberSuffix;
@@ -75,6 +74,7 @@ pub use matcher::Matcher;
pub use merge_words::MergeWords;
pub use multiple_sequential_pronouns::MultipleSequentialPronouns;
pub use no_oxford_comma::NoOxfordComma;
+pub use nobody::Nobody;
pub use number_suffix_capitalization::NumberSuffixCapitalization;
pub use oxford_comma::OxfordComma;
pub use pattern_linter::PatternLinter;
diff --git a/harper-core/src/linting/nobody.rs b/harper-core/src/linting/nobody.rs
new file mode 100644
index 000000000..945ba02e5
--- /dev/null
+++ b/harper-core/src/linting/nobody.rs
@@ -0,0 +1,64 @@
+use crate::{
+ patterns::{Pattern, SequencePattern},
+ Token, TokenStringExt,
+};
+
+use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+pub struct Nobody {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for Nobody {
+ fn default() -> Self {
+ let pattern = SequencePattern::aco("no")
+ .then_whitespace()
+ .t_aco("body")
+ .then_whitespace()
+ .then_verb();
+ Self {
+ pattern: Box::new(pattern),
+ }
+ }
+}
+
+impl PatternLinter for Nobody {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Lint {
+ let span = matched_tokens[0..3].span().unwrap();
+ let orig_chars = span.get_content(source);
+ Lint {
+ span,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::replace_with_match_case(
+ "nobody".chars().collect(),
+ orig_chars,
+ )],
+ message: format!("Did you mean the closed compound `{}`?", "nobody"),
+ ..Default::default()
+ }
+ }
+
+ fn description(&self) -> &'static str {
+ "Looks for incorrect spacing inside the closed compound `nobody`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::assert_suggestion_result;
+
+ use super::Nobody;
+
+ #[test]
+ fn both_valid_and_invalid() {
+ assert_suggestion_result(
+ "No body told me. I have a head but no body.",
+ Nobody::default(),
+ "Nobody told me. I have a head but no body.",
+ );
+ }
+}