Skip to content

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

feat(core): add rule for unnecessary double-negatives (#1943)

Elijah Potter85437097948d
diff --git a/harper-core/src/linting/phrase_corrections/mod.rs b/harper-core/src/linting/phrase_corrections/mod.rs
index 2fdd261d4..bb3cbca0e 100644
--- a/harper-core/src/linting/phrase_corrections/mod.rs
+++ b/harper-core/src/linting/phrase_corrections/mod.rs
@@ -759,13 +759,6 @@ pub fn lint_group() -> LintGroup {
"Advises using `momentous` or `monumental` instead of `monumentous` for serious usage.",
LintKind::Nonstandard
),
- "MorePreferable" => (
- ["more preferable"],
- ["preferable"],
- "Use just `preferable` instead of `more preferable`.",
- "Corrects `more preferable` to `preferable`.",
- LintKind::Redundancy
- ),
"MyHouse" => (
["mu house"],
["my house"],
diff --git a/harper-core/src/linting/phrase_corrections/tests.rs b/harper-core/src/linting/phrase_corrections/tests.rs
index dcc4595b2..430478ac8 100644
--- a/harper-core/src/linting/phrase_corrections/tests.rs
+++ b/harper-core/src/linting/phrase_corrections/tests.rs
@@ -900,16 +900,6 @@ fn detect_monumentous_real_world() {
);
}
-// MorePreferable
-#[test]
-fn correct_more_preferable() {
- assert_suggestion_result(
- "Is it more preferable to use process.env.variable or env.parsed.variable?",
- lint_group(),
- "Is it preferable to use process.env.variable or env.parsed.variable?",
- );
-}
-
// MyHouse
// -none-
@@ -968,6 +958,9 @@ fn detect_nerve_racking_no_hyphen() {
// NotTo
// -none-
+// NotUncommon moved to phrase_set_corrections as part of the
+// generalized double negative mapping.
+
// OfCourse
// See also: tests in `of_course.rs` for "of curse/corse" → "of course" corrections
#[test]
diff --git a/harper-core/src/linting/phrase_set_corrections/mod.rs b/harper-core/src/linting/phrase_set_corrections/mod.rs
index ad9079095..0513c8de8 100644
--- a/harper-core/src/linting/phrase_set_corrections/mod.rs
+++ b/harper-core/src/linting/phrase_set_corrections/mod.rs
@@ -279,6 +279,43 @@ pub fn lint_group() -> LintGroup {
"Corrects the eggcorn `piggy bag` to `piggyback`, which is the proper term for riding on someone’s back or using an existing system.",
LintKind::Eggcorn
),
+
+ // General litotes (double negatives) → direct positive suggestions
+ "LitotesDirectPositive" => (
+ &[
+ ("not uncommon", "common"),
+ ("not unusual", "common"),
+ ("not insignificant", "significant"),
+ ("not unimportant", "important"),
+ ("not unlikely", "likely"),
+ ("not infrequent", "frequent"),
+ ("not inaccurate", "accurate"),
+ ("not unclear", "clear"),
+ ("not irrelevant", "relevant"),
+ ("not unpredictable", "predictable"),
+ ("not inadequate", "adequate"),
+ ("not unpleasant", "pleasant"),
+ ("not unreasonable", "reasonable"),
+ ("not impossible", "possible"),
+ ("more preferable", "preferable"),
+ ],
+ "Consider a direct form instead of litotes like `not uncommon`.",
+ "Offers direct-positive alternatives when double negatives might feel heavy.",
+ LintKind::Style
+ ),
+
+ // Redundant degree modifiers on positives (double positives) → base form
+ "RedundantSuperlatives" => (
+ &[
+ ("more optimal", "optimal"),
+ ("most optimal", "optimal"),
+ ("more ideal", "ideal"),
+ ("most ideal", "ideal"),
+ ],
+ "Avoid redundant degree modifiers; prefer the base adjective.",
+ "Simplifies redundant double positives like `most optimal` to the base form.",
+ LintKind::Redundancy
+ ),
});
add_many_to_many_mappings!(group, {
diff --git a/harper-core/src/linting/phrase_set_corrections/tests.rs b/harper-core/src/linting/phrase_set_corrections/tests.rs
index dcc8949c1..7e49f7cd6 100644
--- a/harper-core/src/linting/phrase_set_corrections/tests.rs
+++ b/harper-core/src/linting/phrase_set_corrections/tests.rs
@@ -198,6 +198,65 @@ fn corrects_dose_not() {
);
}
+// LitotesDirectPositive
+
+#[test]
+fn litotes_not_uncommon_atomic() {
+ assert_suggestion_result("not uncommon", lint_group(), "common");
+}
+
+#[test]
+fn litotes_not_uncommon_sentence() {
+ assert_suggestion_result(
+ "It is not uncommon to see outages during storms.",
+ lint_group(),
+ "It is common to see outages during storms.",
+ );
+}
+
+#[test]
+fn litotes_not_unlikely() {
+ assert_suggestion_result(
+ "This outcome is not unlikely given the data.",
+ lint_group(),
+ "This outcome is likely given the data.",
+ );
+}
+
+#[test]
+fn litotes_not_insignificant() {
+ assert_suggestion_result(
+ "That is not insignificant progress.",
+ lint_group(),
+ "That is significant progress.",
+ );
+}
+
+#[test]
+fn litotes_more_preferable() {
+ assert_suggestion_result(
+ "Is it more preferable to use process.env.variable or env.parsed.variable?",
+ lint_group(),
+ "Is it preferable to use process.env.variable or env.parsed.variable?",
+ );
+}
+
+// RedundantSuperlatives
+
+#[test]
+fn redundant_more_optimal() {
+ assert_suggestion_result("Is this more optimal?", lint_group(), "Is this optimal?");
+}
+
+#[test]
+fn redundant_most_ideal() {
+ assert_suggestion_result(
+ "This is the most ideal scenario.",
+ lint_group(),
+ "This is the ideal scenario.",
+ );
+}
+
// -dose it true positive-
#[test]
#[ignore = "due to false positives this can't be fixed yet"]
diff --git a/packages/vscode-plugin/package.json b/packages/vscode-plugin/package.json
index 537356dfe..033b20244 100644
--- a/packages/vscode-plugin/package.json
+++ b/packages/vscode-plugin/package.json
@@ -1555,12 +1555,6 @@
"default": true,
"description": "Corrects `mute` to `moot` in the phrase `moot point`."
},
- "harper.linters.MorePreferable": {
- "scope": "resource",
- "type": "boolean",
- "default": true,
- "description": "Corrects `more preferable` to `preferable`."
- },
"harper.linters.MostNumber": {
"scope": "resource",
"type": "boolean",