Skip to content

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

fix(core): avoid to-too false positives outside adjective contexts (#3883)

Nathan6438c2cc8e20
diff --git a/harper-core/src/linting/to_two_too/mod.rs b/harper-core/src/linting/to_two_too/mod.rs
index c321aac16..1b0896827 100644
--- a/harper-core/src/linting/to_two_too/mod.rs
+++ b/harper-core/src/linting/to_two_too/mod.rs
@@ -100,6 +100,11 @@ mod tests {
assert_no_lints("Distance from the center to any face", test_linter());
}
+ #[test]
+ fn no_lint_to_audio() {
+ assert_no_lints("Convert a book to audio.", ToTwoToo::default());
+ }
+
#[test]
fn fixes_too_go() {
assert_suggestion_result(
diff --git a/harper-core/src/linting/to_two_too/to_too_adjective_end.rs b/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
index c5234deec..913e54cf8 100644
--- a/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adjective_end.rs
@@ -1,3 +1,5 @@
+use harper_brill::UPOS;
+
use crate::{
Token, TokenKind,
char_string::CharStringExt,
@@ -54,6 +56,7 @@ impl ExprLinter for ToTooAdjectiveEnd {
if idx >= tokens.len()
|| !tokens[idx].kind.is_adjective()
|| !tokens[idx].kind.is_positive_adjective()
+ || !tokens[idx].kind.is_upos(UPOS::ADJ)
{
return None;
}
diff --git a/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs b/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
index 4a0353b83..3c3adb6e5 100644
--- a/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
+++ b/harper-core/src/linting/to_two_too/to_too_adjective_punct.rs
@@ -1,3 +1,5 @@
+use harper_brill::UPOS;
+
use crate::{
Token, TokenKind,
char_string::CharStringExt,
@@ -51,7 +53,10 @@ impl ExprLinter for ToTooAdjectivePunct {
return None;
}
let adjective = &tokens[idx];
- if !adjective.kind.is_adjective() || !adjective.kind.is_positive_adjective() {
+ if !adjective.kind.is_adjective()
+ || !adjective.kind.is_positive_adjective()
+ || !adjective.kind.is_upos(UPOS::ADJ)
+ {
return None;
}
if adjective.kind.is_preposition() {
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 672fc0dad..1647fc2c2 100644
--- a/harper-core/tests/text/linters/The Great Gatsby.snap.yml
+++ b/harper-core/tests/text/linters/The Great Gatsby.snap.yml
@@ -1862,16 +1862,6 @@ Suggest:
-Lint: WordChoice (127 priority)
-Message: |
- 1667 | “Don’t ask me,” said Owl Eyes, washing his hands of the whole matter. “I know
- 1668 | very little about driving—next to nothing. It happened, and that’s all I know.”
- | ^~ Use `too` here to mean ‘also’ or an excessive degree.
-Suggest:
- - Replace with: “too”
-
-
-
Lint: Spelling (63 priority)
Message: |
1683 | The shock that followed this declaration found voice in a sustained “Ah-h-h!” as
@@ -4580,15 +4570,6 @@ Message: |
-Lint: WordChoice (127 priority)
-Message: |
- 3353 | inhabitants along a short-cut from nothing to nothing. She saw something awful
- | ^~ Use `too` here to mean ‘also’ or an excessive degree.
-Suggest:
- - Replace with: “too”
-
-
-
Lint: Spelling (63 priority)
Message: |
3389 | Daisy began to sing with the music in a husky, rythmic whisper, bringing out a