Skip to content

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

feat: bare-bone → bare-bones (#4372)

Andrew Dunbar9748a1a0639a
diff --git a/harper-core/default_config.json b/harper-core/default_config.json
index 04ac4d11a..7899d7d33 100644
--- a/harper-core/default_config.json
+++ b/harper-core/default_config.json
@@ -4360,6 +4360,13 @@
"label": "Ban Together"
}
},
+ {
+ "Bool": {
+ "name": "BareBones",
+ "state": true,
+ "label": "BareBones"
+ }
+ },
{
"Bool": {
"name": "BareInMind",
diff --git a/harper-core/src/linting/bare_bones.rs b/harper-core/src/linting/bare_bones.rs
new file mode 100644
index 000000000..0799d7a8f
--- /dev/null
+++ b/harper-core/src/linting/bare_bones.rs
@@ -0,0 +1,126 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct BareBones {
+ expr: SequenceExpr,
+}
+
+impl Default for BareBones {
+ fn default() -> Self {
+ Self {
+ expr: SequenceExpr::aco("bare").t_ws_h().t_aco("bone"),
+ }
+ }
+}
+
+impl ExprLinter for BareBones {
+ type Unit = Chunk;
+
+ fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
+ let span = toks.last()?.span;
+
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Usage,
+ suggestions: vec![Suggestion::replace_with_match_case_str(
+ "bones",
+ span.get_content(src),
+ )],
+ message: format!(
+ "If this is the idiom meaning `minimal`, it should be plural `bare{}bones`",
+ if toks.get(1)?.kind.is_hyphen() {
+ '-'
+ } else {
+ ' '
+ }
+ ),
+ ..Default::default()
+ })
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ &self.expr
+ }
+
+ fn description(&self) -> &str {
+ "Corrects `bare-bone` to `bare-bones`."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
+
+ use super::BareBones;
+
+ #[test]
+ fn singular_attributive_space() {
+ assert_suggestion_result(
+ "bare bone csv-parse won't parse anything",
+ BareBones::default(),
+ "bare bones csv-parse won't parse anything",
+ );
+ }
+
+ #[test]
+ fn singular_attributive_hyphen() {
+ assert_suggestion_result(
+ "This is a simple bare-bone module which allows background playing from a HTTP stream, using ExoPlayer.",
+ BareBones::default(),
+ "This is a simple bare-bones module which allows background playing from a HTTP stream, using ExoPlayer.",
+ )
+ }
+
+ #[test]
+ fn dont_flag_plural_attributive_hyphen() {
+ assert_no_lints(
+ "For the bare-bones version, just display all tags, expanded.",
+ BareBones::default(),
+ )
+ }
+
+ #[test]
+ fn dont_flag_plural_attributive_space() {
+ assert_no_lints(
+ "Support for when JS disabled + a text-only bare bones version",
+ BareBones::default(),
+ )
+ }
+
+ #[test]
+ fn dont_flag_plural_predicative_space() {
+ assert_no_lints(
+ "Even though they are bare bones, they still require some design knowledge to be very successful.",
+ BareBones::default(),
+ )
+ }
+
+ #[test]
+ fn dont_flag_plural_predicative_hyphen() {
+ assert_no_lints(
+ "The core is bare-bones, there are numerous standard protocols since, and many other are in standardization.",
+ BareBones::default(),
+ )
+ }
+
+ #[test]
+ fn singular_predicative_space() {
+ assert_suggestion_result(
+ "It is bare bone because all my views are dinamically created",
+ BareBones::default(),
+ "It is bare bones because all my views are dinamically created",
+ )
+ }
+
+ #[test]
+ fn singular_predicative_hyphen() {
+ assert_suggestion_result(
+ "This repo has been created, but it is bare-bone.",
+ BareBones::default(),
+ "This repo has been created, but it is bare-bone.",
+ )
+ }
+}
diff --git a/harper-core/src/linting/lint_group/mod.rs b/harper-core/src/linting/lint_group/mod.rs
index e5310ce5d..e139b4c6b 100644
--- a/harper-core/src/linting/lint_group/mod.rs
+++ b/harper-core/src/linting/lint_group/mod.rs
@@ -36,6 +36,7 @@ use super::aspire_to::AspireTo;
use super::avoid_contractions::AvoidContractions;
use super::avoid_curses::AvoidCurses;
use super::back_in_the_day::BackInTheDay;
+use super::bare_bones::BareBones;
use super::barely_un::BarelyUn;
use super::be_allowed::BeAllowed;
use super::behind_the_scenes::BehindTheScenes;
@@ -654,6 +655,7 @@ impl LintGroup {
insert_expr_rule!(AvoidContractions);
insert_expr_rule!(AvoidCurses);
insert_expr_rule!(BackInTheDay);
+ insert_expr_rule!(BareBones);
insert_expr_rule_with_dict!(BarelyUn);
insert_expr_rule!(BeAllowed);
insert_expr_rule!(BehindTheScenes);
@@ -835,11 +837,11 @@ impl LintGroup {
insert_expr_rule!(PayForPrice);
insert_struct_rule!(PhrasalVerbAsCompoundNoun);
insert_expr_rule!(PiqueInterest);
- insert_struct_rule!(PreferPleaded);
- insert_struct_rule!(PreferPled);
insert_expr_rule!(PluralWrongWordOfPhrase);
insert_struct_rule_with_dict!(PossessiveNoun);
insert_expr_rule!(PossessiveYour);
+ insert_struct_rule!(PreferPleaded);
+ insert_struct_rule!(PreferPled);
insert_struct_rule!(PreferSneaked);
insert_struct_rule!(PreferSnuck);
insert_expr_rule!(ProgressiveNeedsBe);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 8c907f3bd..15f7a06a5 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -32,6 +32,7 @@ mod aspire_to;
mod avoid_contractions;
mod avoid_curses;
mod back_in_the_day;
+mod bare_bones;
mod barely_un;
mod be_adjective_confusions;
mod be_allowed;