Skip to content

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

feat: more abbreviation expansions (#2310)

Andrew Dunbar01e900b83a76
diff --git a/harper-comments/src/comment_parsers/solidity.rs b/harper-comments/src/comment_parsers/solidity.rs
index feea3d6d6..1a45ae4a7 100644
--- a/harper-comments/src/comment_parsers/solidity.rs
+++ b/harper-comments/src/comment_parsers/solidity.rs
@@ -1,8 +1,9 @@
use harper_core::Lrc;
use harper_core::Span;
use harper_core::Token;
-use harper_core::parsers::{Markdown, MarkdownOptions, Parser};
+use harper_core::parsers::{MarkdownOptions, Parser};
+use super::jsdoc::JsDoc;
use super::without_initiators;
#[derive(Clone)]
@@ -16,7 +17,7 @@ impl Solidity {
}
pub fn new_markdown(markdown_options: MarkdownOptions) -> Self {
- Self::new(Lrc::new(Markdown::new(markdown_options)))
+ Self::new(Lrc::new(JsDoc::new_markdown(markdown_options)))
}
}
diff --git a/harper-core/src/linting/phrase_corrections/mod.rs b/harper-core/src/linting/phrase_corrections/mod.rs
index 5743fe0d7..e8a40e64b 100644
--- a/harper-core/src/linting/phrase_corrections/mod.rs
+++ b/harper-core/src/linting/phrase_corrections/mod.rs
@@ -419,6 +419,13 @@ pub fn lint_group() -> LintGroup {
"Expands the informal abbreviation `cuz` to the full word `because` for formality.",
LintKind::Style
),
+ "ExpandForward" => (
+ ["fwd"],
+ ["forward"],
+ "Use `forward` instead of `fwd`",
+ "Expands the abbreviation `fwd` to the full word `forward` for clarity.",
+ LintKind::Style
+ ),
"ExpandMinimum" => (
["min"],
["minimum"],
diff --git a/harper-core/src/linting/phrase_corrections/tests.rs b/harper-core/src/linting/phrase_corrections/tests.rs
index 9202470aa..a1a1923d9 100644
--- a/harper-core/src/linting/phrase_corrections/tests.rs
+++ b/harper-core/src/linting/phrase_corrections/tests.rs
@@ -789,6 +789,16 @@ fn expand_cuz() {
);
}
+// ExpandForward
+#[test]
+fn expand_fwd() {
+ assert_suggestion_result(
+ "Now I look fwd to the interior, the color, etc.",
+ lint_group(),
+ "Now I look forward to the interior, the color, etc.",
+ );
+}
+
// ExpandMinimum
// -none
diff --git a/harper-core/src/linting/phrase_set_corrections/mod.rs b/harper-core/src/linting/phrase_set_corrections/mod.rs
index a1811fbd5..1db533799 100644
--- a/harper-core/src/linting/phrase_set_corrections/mod.rs
+++ b/harper-core/src/linting/phrase_set_corrections/mod.rs
@@ -155,13 +155,22 @@ pub fn lint_group() -> LintGroup {
),
"ExpandDependencies" => (
&[
- ("deps", "dependencies"),
("dep", "dependency"),
+ ("deps", "dependencies"),
],
"Use `dependencies` instead of `deps`",
"Expands the abbreviation `deps` to the full word `dependencies` for clarity.",
LintKind::Style
),
+ "ExpandParameter" => (
+ &[
+ ("param", "parameter"),
+ ("params", "parameters"),
+ ],
+ "Use `parameter` instead of `param`",
+ "Expands the abbreviation `param` to the full word `parameter` for clarity.",
+ LintKind::Style
+ ),
"ExpandStandardInputAndOutput" => (
&[
("stdin", "standard input"),
@@ -385,6 +394,15 @@ pub fn lint_group() -> LintGroup {
"Corrects `copywrite` to `copyright`. `Copywrite` refers to writing copy, while `copyright` is the legal right to creative works.",
LintKind::WordChoice
),
+ "ExpandDecl" => (
+ &[
+ (&["decl"], &["declaration", "declarator"]),
+ (&["decls"], &["declarations", "declarators"])
+ ],
+ "Use `declaration` or `declarator` instead of `decl`",
+ "Expands the abbreviation `decl` to the full word `declaration` or `declarator` for clarity.",
+ LintKind::Style
+ ),
"Expat" => (
&[
(&["ex-pat", "ex pat"], &["expat"]),
diff --git a/harper-core/src/linting/phrase_set_corrections/tests.rs b/harper-core/src/linting/phrase_set_corrections/tests.rs
index 5310600a1..62953c100 100644
--- a/harper-core/src/linting/phrase_set_corrections/tests.rs
+++ b/harper-core/src/linting/phrase_set_corrections/tests.rs
@@ -462,9 +462,71 @@ fn corrects_why_dose() {
// Note: no false positive detected for 'why does'. Only true positives.
+// ExpandArgument
+
+#[test]
+fn corrects_arg() {
+ assert_suggestion_result(
+ "but I cannot figure out how to flag an arg as required",
+ lint_group(),
+ "but I cannot figure out how to flag an argument as required",
+ );
+}
+
+#[test]
+fn corrects_args() {
+ assert_suggestion_result(
+ "but every test I've done shows args as being about 65% faster",
+ lint_group(),
+ "but every test I've done shows arguments as being about 65% faster",
+ );
+}
+
+// ExpandDecl
+
+#[test]
+fn corrects_decl() {
+ assert_suggestion_result(
+ "Yeah, I agree a forward decl would be preferable in this case.",
+ lint_group(),
+ "Yeah, I agree a forward declaration would be preferable in this case.",
+ );
+}
+
+#[test]
+fn corrects_decls() {
+ assert_suggestion_result(
+ "Accessing type decls from pointer types",
+ lint_group(),
+ "Accessing type declarations from pointer types",
+ );
+}
+
// ExpandDependency
// -none-
+// ExpandParam
+
+#[test]
+fn corrects_param() {
+ assert_suggestion_result(
+ "If I use the following to set an endDate param with a default value",
+ lint_group(),
+ "If I use the following to set an endDate parameter with a default value",
+ );
+}
+
+#[test]
+fn corrects_params() {
+ assert_suggestion_result(
+ "the params are not loaded in the R environment when using the terminal",
+ lint_group(),
+ "the parameters are not loaded in the R environment when using the terminal",
+ );
+}
+
+// ExpandSpecification
+
// ExpandStandardInput
// -none-