Skip to content

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

feat: three simple linters (#4158)

Andrew Dunbar3486414b5756
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 15fc8e98e..ad613ae57 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -404,6 +404,20 @@
"label": "Chalkboard"
}
},
+ {
+ "Bool": {
+ "name": "Codebase",
+ "state": true,
+ "label": "Codebase"
+ }
+ },
+ {
+ "Bool": {
+ "name": "Codebases",
+ "state": true,
+ "label": "Codebases"
+ }
+ },
{
"Bool": {
"name": "Deadlift",
@@ -705,6 +719,13 @@
"label": "Somewhere"
}
},
+ {
+ "Bool": {
+ "name": "Tenfold",
+ "state": true,
+ "label": "Tenfold"
+ }
+ },
{
"Bool": {
"name": "There",
@@ -4165,6 +4186,13 @@
"label": "At The Very Least"
}
},
+ {
+ "Bool": {
+ "name": "Audible",
+ "state": true,
+ "label": "Audible"
+ }
+ },
{
"Bool": {
"name": "AvoidCurses",
diff --git a/harper-core/src/linting/closed_compounds.rs b/harper-core/src/linting/closed_compounds.rs
index 55bccde6d..e9aebedbb 100644
--- a/harper-core/src/linting/closed_compounds.rs
+++ b/harper-core/src/linting/closed_compounds.rs
@@ -27,6 +27,8 @@ pub fn lint_group() -> LintGroup {
"Backplane" => (&["back plane"][..], "backplane"),
"Bypass" => (&["by pass"][..], "bypass"),
"Chalkboard" => (&["chalk board"][..], "chalkboard"),
+ "Codebase" => (&["code base"][..], "codebase"),
+ "Codebases" => (&["code bases"][..], "codebases"),
"Deadlift" => (&["dead lift"][..], "deadlift"),
"Desktop" => (&["desk top"][..], "desktop"),
"Devops" => (&["dev ops"][..], "devops"),
@@ -70,6 +72,7 @@ pub fn lint_group() -> LintGroup {
"Somehow" => (&["some how"][..], "somehow"),
"Someone" => (&["some one"][..], "someone"),
"Somewhere" => (&["some where"][..], "somewhere"),
+ "Tenfold" => (&["ten fold"][..], "tenfold"),
"There" => (&["the re"][..], "there"),
"Therefore" => (&["there fore"][..], "therefore"),
"Thereupon" => (&["there upon"][..], "thereupon"),
@@ -338,4 +341,31 @@ mod tests {
let expected = "I feel that the special case of looping over sequences that follow a standard iterator protocol (i.e. optionals) is important enough to be worthwhile.";
assert_suggestion_result(test_sentence, lint_group(), expected);
}
+
+ #[test]
+ fn tenfold() {
+ assert_suggestion_result(
+ "If Andrew Kelly has done something wrong hasn’t Theo done that ten fold",
+ lint_group(),
+ "If Andrew Kelly has done something wrong hasn’t Theo done that tenfold",
+ )
+ }
+
+ #[test]
+ fn codebase() {
+ assert_suggestion_result(
+ "Having trouble communicating the problems in your code base?",
+ lint_group(),
+ "Having trouble communicating the problems in your codebase?",
+ )
+ }
+
+ #[test]
+ fn codebases() {
+ assert_suggestion_result(
+ "Tools to visualize large code bases in different ways.",
+ lint_group(),
+ "Tools to visualize large codebases in different ways.",
+ )
+ }
}
diff --git a/harper-core/src/linting/for_the_nth_time.rs b/harper-core/src/linting/for_the_nth_time.rs
index 67bd6d4a2..4760a5463 100644
--- a/harper-core/src/linting/for_the_nth_time.rs
+++ b/harper-core/src/linting/for_the_nth_time.rs
@@ -1,7 +1,7 @@
use crate::{
Lint, Token,
expr::{AnchorEnd, Expr, SequenceExpr},
- linting::{ExprLinter, LintKind, Suggestion, debug::format_lint_match, expr_linter::Chunk},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
};
pub struct ForTheNthTime {
@@ -68,14 +68,7 @@ impl Default for ForTheNthTime {
impl ExprLinter for ForTheNthTime {
type Unit = Chunk;
- fn match_to_lint_with_context(
- &self,
- matched_tokens: &[Token],
- source: &[char],
- context: Option<(&[Token], &[Token])>,
- ) -> Option<Lint> {
- eprintln!("🚨 {}", format_lint_match(matched_tokens, context, source));
-
+ fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
Some(Lint {
span: matched_tokens[0].span,
lint_kind: LintKind::Usage,
diff --git a/harper-core/src/linting/weir_rules/Audible.weir b/harper-core/src/linting/weir_rules/Audible.weir
new file mode 100644
index 000000000..2f2d1265f
--- /dev/null
+++ b/harper-core/src/linting/weir_rules/Audible.weir
@@ -0,0 +1,9 @@
+expr main hearable
+
+let message "The standard word for this is `audible`."
+let description "Corrects `hearable` to `audible`."
+let kind "WordChoice"
+let becomes "audible"
+
+test "Alexa devices speak works, but announcements is not hearable" "Alexa devices speak works, but announcements is not audible"
+test "The digital sound may be disturbing, so we can try to use waves outside of hearable range." "The digital sound may be disturbing, so we can try to use waves outside of audible range."