Skip to content

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

feat: expand coord, vuln, notif, algo (#3291)

Andrew Dunbar0a71b1366b39
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 951b7fb3e..92eb898e2 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -1281,6 +1281,34 @@
"state": true,
"label": "Formative Years"
}
+ },
+ {
+ "Bool": {
+ "name": "ExpandAlgorithm",
+ "state": true,
+ "label": "Expand Algorithm"
+ }
+ },
+ {
+ "Bool": {
+ "name": "ExpandCoordinate",
+ "state": true,
+ "label": "Expand Coordinate"
+ }
+ },
+ {
+ "Bool": {
+ "name": "ExpandNotification",
+ "state": true,
+ "label": "Expand Notification"
+ }
+ },
+ {
+ "Bool": {
+ "name": "ExpandVulnerability",
+ "state": true,
+ "label": "Expand Vulnerability"
+ }
}
]
}
diff --git a/harper-core/src/linting/phrase_set_corrections/mod.rs b/harper-core/src/linting/phrase_set_corrections/mod.rs
index c6d174ed2..ba7c5b5f1 100644
--- a/harper-core/src/linting/phrase_set_corrections/mod.rs
+++ b/harper-core/src/linting/phrase_set_corrections/mod.rs
@@ -176,6 +176,15 @@ pub fn lint_group() -> LintGroup {
"Tries to correct typos of `dose` to `does`.",
LintKind::Typo
),
+ "ExpandAlgorithm" => (
+ &[
+ ("algo", "algorithm"),
+ ("algos", "algorithms"),
+ ],
+ "Use `algorithm` instead of `algo`",
+ "Expands the abbreviation `algo` to the full word `algorithm` for clarity.",
+ LintKind::Style
+ ),
"ExpandArgument" => (
&[
("arg", "argument"),
@@ -203,6 +212,15 @@ pub fn lint_group() -> LintGroup {
"Expands the abbreviation `deref` to the full word `dereference` for clarity.",
LintKind::Style
),
+ "ExpandNotification" => (
+ &[
+ ("notif", "notification"),
+ ("notifs", "notifications"),
+ ],
+ "Use `notification` instead of `notif`",
+ "Expands the abbreviation `notif` to the full word `notification` for clarity.",
+ LintKind::Style
+ ),
"ExpandParameter" => (
&[
("param", "parameter"),
@@ -231,6 +249,15 @@ pub fn lint_group() -> LintGroup {
"Expands the abbreviations `stdin`, `stdout`, and `stderr` to the full words `standard input`, etc. for clarity.",
LintKind::Style
),
+ "ExpandVulnerability" => (
+ &[
+ ("vuln", "vulnerability"),
+ ("vulns", "vulnerabilities"),
+ ],
+ "Use `vulnerability` instead of `vuln`",
+ "Expands the abbreviation `vuln` to the full word `vulnerability` for clarity.",
+ LintKind::Style
+ ),
"ExplanationMark" => (
&[
("explanation mark", "exclamation mark"),
@@ -730,6 +757,15 @@ pub fn lint_group() -> LintGroup {
"Expands the abbreviation `alloc` to the full word `allocate` or `allocation` for clarity.",
LintKind::Style
),
+ "ExpandCoordinate" => (
+ &[
+ (&["coord"], &["coordinate"]),
+ (&["coords"], &["coordinates"]),
+ ],
+ "Use `coordinate` instead of `coord`",
+ "Expands the abbreviation `coord` to the full word `coordinate` for clarity.",
+ LintKind::Style
+ ),
"ExpandDecl" => (
&[
(&["decl"], &["declaration", "declarator"]),
diff --git a/harper-core/src/linting/phrase_set_corrections/tests.rs b/harper-core/src/linting/phrase_set_corrections/tests.rs
index 83990b7b8..cb2f44875 100644
--- a/harper-core/src/linting/phrase_set_corrections/tests.rs
+++ b/harper-core/src/linting/phrase_set_corrections/tests.rs
@@ -565,6 +565,26 @@ fn corrects_why_dose() {
// Note: no false positive detected for 'why does'. Only true positives.
+// ExpandAlgorithm
+
+#[test]
+fn corrects_algo() {
+ assert_suggestion_result(
+ "Always glad when the algo feeds me a new dissident.",
+ lint_group(),
+ "Always glad when the algorithm feeds me a new dissident.",
+ );
+}
+
+#[test]
+fn corrects_algos() {
+ assert_suggestion_result(
+ "I moved algos development to a private repository.",
+ lint_group(),
+ "I moved algorithms development to a private repository.",
+ );
+}
+
// ExpandArgument
#[test]
@@ -585,6 +605,26 @@ fn corrects_args() {
);
}
+// ExpandCoordinate
+
+#[test]
+fn corrects_coord() {
+ assert_suggestion_result(
+ "Prompted by #5684, we should probably emit more meaningful messages when position guides are specified in coord systems that do not support them",
+ lint_group(),
+ "Prompted by #5684, we should probably emit more meaningful messages when position guides are specified in coordinate systems that do not support them",
+ );
+}
+
+#[test]
+fn corrects_coords() {
+ assert_suggestion_result(
+ "Here is how you can extract the list of coords from any geometry:",
+ lint_group(),
+ "Here is how you can extract the list of coordinates from any geometry:",
+ );
+}
+
// ExpandDecl
#[test]
@@ -628,6 +668,26 @@ fn corrects_derefs() {
);
}
+// ExpandNotification
+
+#[test]
+fn corrects_notif() {
+ assert_suggestion_result(
+ "Amazing to see the notif of this on my phone!",
+ lint_group(),
+ "Amazing to see the notification of this on my phone!",
+ );
+}
+
+#[test]
+fn corrects_notifs() {
+ assert_suggestion_result(
+ "I don't encourage you spending all your time on social media or keeping the notifs on if you're working on something serious.",
+ lint_group(),
+ "I don't encourage you spending all your time on social media or keeping the notifications on if you're working on something serious.",
+ );
+}
+
// ExpandParam
#[test]
@@ -674,6 +734,39 @@ fn correct_ptrs() {
// ExpandStandardOutput
// -none-
+// ExpandVulnerability
+
+#[test]
+fn corrects_vuln() {
+ assert_suggestion_result(
+ "I did not understand this vuln in first place now I do not understand in 2nd place as well😢",
+ lint_group(),
+ "I did not understand this vulnerability in first place now I do not understand in 2nd place as well😢",
+ );
+}
+
+#[test]
+fn corrects_vulns() {
+ // Fix just this lint
+ let mut only_expand_vuln = lint_group();
+ only_expand_vuln.set_all_rules_to(None); // Disable all linters
+ only_expand_vuln
+ .config
+ .set_rule_enabled("ExpandVulnerability", true); // Enable only ExpandVuln
+
+ assert_suggestion_result(
+ "... when persisted, containing endpoints, vulns, WAF bypasses, sensitive params, and auth endpoints.",
+ only_expand_vuln,
+ "... when persisted, containing endpoints, vulnerabilities, WAF bypasses, sensitive params, and auth endpoints.",
+ );
+ // Fix all lints in the `LintGroup`
+ assert_suggestion_result(
+ "... when persisted, containing endpoints, vulns, WAF bypasses, sensitive params, and auth endpoints.",
+ lint_group(),
+ "... when persisted, containing endpoints, vulnerabilities, WAF bypasses, sensitive parameters, and auth endpoints.",
+ );
+}
+
// ExplanationMark
#[test]
fn detect_explanation_mark_atomic() {