Skip to content

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

fix(core): several false-positives (#1652)

Elijah Pottercee7998caacc
diff --git a/harper-core/src/linting/its_contraction.rs b/harper-core/src/linting/its_contraction.rs
index fbc7838b6..af62138e5 100644
--- a/harper-core/src/linting/its_contraction.rs
+++ b/harper-core/src/linting/its_contraction.rs
@@ -1,5 +1,6 @@
use harper_brill::UPOS;
+use crate::Document;
use crate::TokenStringExt;
use crate::expr::All;
use crate::expr::Expr;
@@ -11,10 +12,12 @@ use crate::patterns::Pattern;
use crate::patterns::UPOSSet;
use crate::patterns::WordSet;
use crate::{
- Document, Token,
- linting::{Lint, LintKind, Linter, Suggestion},
+ Token,
+ linting::{Lint, LintKind, Suggestion},
};
+use super::Linter;
+
pub struct ItsContraction {
expr: Box<dyn Expr>,
}
@@ -24,7 +27,7 @@ impl Default for ItsContraction {
let positive = SequenceExpr::default()
.t_aco("its")
.then_whitespace()
- .then(UPOSSet::new(&[UPOS::VERB, UPOS::AUX, UPOS::DET]));
+ .then(UPOSSet::new(&[UPOS::VERB, UPOS::AUX, UPOS::DET]).or(WordSet::new(&["because"])));
let exceptions = SequenceExpr::default()
.then_anything()
@@ -198,4 +201,13 @@ mod tests {
0,
);
}
+
+ #[test]
+ fn because() {
+ assert_suggestion_result(
+ "Its because they don't want to.",
+ ItsContraction::default(),
+ "It's because they don't want to.",
+ );
+ }
}
diff --git a/harper-core/src/linting/its_possessive.rs b/harper-core/src/linting/its_possessive.rs
index 6f970e7ff..86e6acf68 100644
--- a/harper-core/src/linting/its_possessive.rs
+++ b/harper-core/src/linting/its_possessive.rs
@@ -46,13 +46,18 @@ impl Default for ItsPossessive {
.t_ws()
.then(UPOSSet::new(&[UPOS::ADJ, UPOS::NOUN, UPOS::PROPN]))
.t_ws()
- .then_unless(UPOSSet::new(&[UPOS::PART, UPOS::NOUN, UPOS::PRON]));
+ .then_unless(UPOSSet::new(&[
+ UPOS::PART,
+ UPOS::NOUN,
+ UPOS::PRON,
+ UPOS::SCONJ,
+ ]));
map.insert(start_of_sentence, 0);
let special = SequenceExpr::aco("it's")
.t_ws()
- .then(WordSet::new(&["various", "many"]));
+ .then(WordSet::new(&["various"]));
map.insert(special, 0);
@@ -292,4 +297,20 @@ mod tests {
ItsPossessive::default(),
);
}
+
+ #[test]
+ fn allows_its_possible() {
+ assert_no_lints(
+ "It's possible that a record was improperly handled. ",
+ ItsPossessive::default(),
+ );
+ }
+
+ #[test]
+ fn allows_many_times_harder() {
+ assert_no_lints(
+ "It's many times harder to do this than that.",
+ ItsPossessive::default(),
+ );
+ }
}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 327763434..b926eec7a 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -510,7 +510,7 @@ impl LintGroup {
out.config.set_rule_enabled("SentenceCapitalization", true);
out.add("PossessiveNoun", PossessiveNoun::new(dictionary.clone()));
- out.config.set_rule_enabled("PossessiveNoun", true);
+ out.config.set_rule_enabled("PossessiveNoun", false);
out.add("Regionalisms", Regionalisms::new(dialect));
out.config.set_rule_enabled("Regionalisms", true);
@@ -600,9 +600,27 @@ mod tests {
use std::sync::Arc;
use super::LintGroup;
+ use crate::linting::tests::assert_no_lints;
use crate::spell::{FstDictionary, MutableDictionary};
use crate::{Dialect, Document, linting::Linter};
+ fn test_group() -> LintGroup {
+ LintGroup::new_curated(Arc::new(MutableDictionary::curated()), Dialect::American)
+ }
+
+ #[test]
+ fn clean_interjection() {
+ assert_no_lints(
+ "Although I only saw the need to interject once, I still saw it.",
+ test_group(),
+ );
+ }
+
+ #[test]
+ fn clean_consensus() {
+ assert_no_lints("But there is less consensus on this.", test_group());
+ }
+
#[test]
fn can_get_all_descriptions() {
let group =
diff --git a/harper-core/src/linting/nominal_wants.rs b/harper-core/src/linting/nominal_wants.rs
index 5d15a5d03..300a33866 100644
--- a/harper-core/src/linting/nominal_wants.rs
+++ b/harper-core/src/linting/nominal_wants.rs
@@ -1,3 +1,5 @@
+use harper_brill::UPOS;
+
use crate::expr::Expr;
use crate::expr::SequenceExpr;
use crate::{
@@ -14,7 +16,7 @@ pub struct NominalWants {
impl Default for NominalWants {
fn default() -> Self {
fn is_applicable_pronoun(tok: &Token, src: &[char]) -> bool {
- if tok.kind.is_pronoun() {
+ if tok.kind.is_pronoun() && tok.kind.is_upos(UPOS::PRON) {
let pron = tok.span.get_content_string(src).to_lowercase();
// "That" can act as two kinds of pronoun: demonstrative and relative.
// As a demonstrative pronoun, it's third person singular.
@@ -33,6 +35,7 @@ impl Default for NominalWants {
// "it" is both subject and object. Subject before "wants", object before "want".
&& pron != "it"
&& pron != "them"
+ && pron != "who"
} else {
false
}
@@ -43,6 +46,7 @@ impl Default for NominalWants {
.then(is_applicable_pronoun)
.then_whitespace()
.then(miss);
+
Self {
expr: Box::new(pattern),
}
@@ -56,7 +60,7 @@ impl ExprLinter for NominalWants {
fn match_to_lint(&self, toks: &[Token], source: &[char]) -> Option<Lint> {
let subject = toks.first()?;
- let offender = toks.last()?;
+ let offender = &toks.last()?;
let plural = subject.kind.is_plural_nominal();
@@ -99,7 +103,7 @@ impl ExprLinter for NominalWants {
#[cfg(test)]
mod tests {
use super::NominalWants;
- use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+ use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};
#[test]
fn fixes_he_wonts() {
@@ -297,4 +301,12 @@ mod tests {
fn ignores_correct_usage_help_them() {
assert_lint_count("And help them want to do it.", NominalWants::default(), 0)
}
+
+ #[test]
+ fn allows_want_to() {
+ assert_no_lints(
+ "Harper is a grammar checker for people who want to write fast.",
+ NominalWants::default(),
+ );
+ }
}
diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
index 899d4c0e4..0c931992e 100644
--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
@@ -2698,15 +2698,6 @@ Suggest:
-Lint: Miscellaneous (10 priority)
-Message: |
- 2420 | “How the creatures order one about, and make one repeat lessons!” thought Alice;
- | ^~~~~~~~~ Use an apostrophe and `s` to form a noun’s possessive.
-Suggest:
- - Replace with: “creature's”
-
-
-
Lint: Spelling (63 priority)
Message: |
2425 | > “’Tis the voice of the Lobster; I heard him declare, “You have baked me too
diff --git a/harper-core/tests/text/linters/Computer science.snap.yml b/harper-core/tests/text/linters/Computer science.snap.yml
index 94bd936a1..59b32c7bb 100644
--- a/harper-core/tests/text/linters/Computer science.snap.yml
+++ b/harper-core/tests/text/linters/Computer science.snap.yml
@@ -1173,16 +1173,6 @@ Suggest:
-Lint: Miscellaneous (10 priority)
-Message: |
- 489 | feature of objects is that an object's procedures can access and often modify
- 490 | the data fields of the object with which they are associated. Thus
- | ^~~~ Use an apostrophe and `s` to form a noun’s possessive.
-Suggest:
- - Replace with: “data's”
-
-
-
Lint: Punctuation (31 priority)
Message: |
490 | the data fields of the object with which they are associated. Thus
diff --git a/harper-core/tests/text/linters/Part-of-speech tagging.snap.yml b/harper-core/tests/text/linters/Part-of-speech tagging.snap.yml
index 417875818..c2f5249c9 100644
--- a/harper-core/tests/text/linters/Part-of-speech tagging.snap.yml
+++ b/harper-core/tests/text/linters/Part-of-speech tagging.snap.yml
@@ -165,16 +165,6 @@ Suggest:
-Lint: Miscellaneous (10 priority)
-Message: |
- 65 | the earlier Brown Corpus and LOB Corpus tag sets, though much smaller. In
- 66 | Europe, tag sets from the Eagles Guidelines see wide use and include versions
- | ^~~~~~ Use an apostrophe and `s` to form a noun’s possessive.
-Suggest:
- - Replace with: “Eagle's”
-
-
-
Lint: WordChoice (63 priority)
Message: |
73 | cross-language differences. The tag sets for heavily inflected languages such as
diff --git a/harper-core/tests/text/linters/The Great Gatsby.snap.yml b/harper-core/tests/text/linters/The Great Gatsby.snap.yml
index 96cc40a7e..f5d0dd7b1 100644
--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml
+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml
@@ -1839,16 +1839,6 @@ Message: |
-Lint: Miscellaneous (10 priority)
-Message: |
- 1407 | celebrated tenor had sung in Italian, and a notorious contralto had sung in
- 1408 | jazz, and between the numbers people were doing ‘‘stunts” all over the garden,
- | ^~~~~~~ Use an apostrophe and `s` to form a noun’s possessive.
-Suggest:
- - Replace with: “number's”
-
-
-
Lint: Spelling (63 priority)
Message: |
1413 | trembling a little to the stiff, tinny drip of the banjoes on the lawn.