Skip to content

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

feat: behind the scene → behind the scenes (#2382)

Andrew Dunbar2724b3709c92
diff --git a/harper-core/src/linting/behind_the_scenes.rs b/harper-core/src/linting/behind_the_scenes.rs
new file mode 100644
index 000000000..c58334c2d
--- /dev/null
+++ b/harper-core/src/linting/behind_the_scenes.rs
@@ -0,0 +1,105 @@
+use crate::{
+ Lint, Token,
+ expr::{Expr, SequenceExpr},
+ linting::{ExprLinter, LintKind, Suggestion, expr_linter::Chunk},
+};
+
+pub struct BehindTheScenes {
+ expr: Box<dyn Expr>,
+}
+
+impl Default for BehindTheScenes {
+ fn default() -> Self {
+ Self {
+ expr: Box::new(
+ SequenceExpr::aco("behind")
+ .t_ws_h()
+ .t_aco("the")
+ .t_ws_h()
+ .t_aco("scene"),
+ ),
+ }
+ }
+}
+
+impl ExprLinter for BehindTheScenes {
+ type Unit = Chunk;
+
+ fn description(&self) -> &str {
+ "Corrects `behind the scene` to `behind the scenes`."
+ }
+
+ fn expr(&self) -> &dyn Expr {
+ self.expr.as_ref()
+ }
+
+ fn match_to_lint_with_context(
+ &self,
+ toks: &[Token],
+ src: &[char],
+ ctx: Option<(&[Token], &[Token])>,
+ ) -> Option<Lint> {
+ if let Some((before, _)) = ctx
+ && before.last().is_some_and(|t| t.kind.is_hyphen())
+ {
+ return None;
+ }
+
+ let span = toks.last()?.span;
+ Some(Lint {
+ span,
+ lint_kind: LintKind::Usage,
+ suggestions: [Suggestion::replace_with_match_case_str(
+ "scenes",
+ span.get_content(src),
+ )]
+ .to_vec(),
+ message: "This idiom uses the plural `scenes`.".to_string(),
+ ..Default::default()
+ })
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::linting::{
+ behind_the_scenes::BehindTheScenes,
+ tests::{assert_no_lints, assert_suggestion_result},
+ };
+
+ #[test]
+ fn pluralize_work_bts() {
+ assert_suggestion_result(
+ "How does this tool work behind the scene.",
+ BehindTheScenes::default(),
+ "How does this tool work behind the scenes.",
+ );
+ }
+
+ #[test]
+ #[ignore = "Correcting hyphenation is not yet implemented."]
+ fn pluralize_and_hyphenate() {
+ assert_suggestion_result(
+ "So, to open the 'real' behind the scene menu i need to do these steps:",
+ BehindTheScenes::default(),
+ "So, to open the 'real' behind-the-scenes menu i need to do these steps:",
+ );
+ }
+
+ #[test]
+ fn dont_flag_when_hyphenated_to_previous_word() {
+ assert_no_lints(
+ "Contribute to techking11/react-behind-the-scene development by creating an account on GitHub.",
+ BehindTheScenes::default(),
+ );
+ }
+
+ #[test]
+ fn pluralize_bts_processing() {
+ assert_suggestion_result(
+ "Behind-the-scene processing details are printed in the Log window.",
+ BehindTheScenes::default(),
+ "Behind-the-scenes processing details are printed in the Log window.",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 34e40276c..8cec69569 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -31,6 +31,7 @@ use super::ask_no_preposition::AskNoPreposition;
use super::avoid_curses::AvoidCurses;
use super::back_in_the_day::BackInTheDay;
use super::be_allowed::BeAllowed;
+use super::behind_the_scenes::BehindTheScenes;
use super::best_of_all_time::BestOfAllTime;
use super::boring_words::BoringWords;
use super::bought::Bought;
@@ -509,6 +510,7 @@ impl LintGroup {
insert_expr_rule!(AvoidCurses, true);
insert_expr_rule!(BackInTheDay, true);
insert_expr_rule!(BeAllowed, true);
+ insert_expr_rule!(BehindTheScenes, true);
insert_struct_rule!(BestOfAllTime, true);
insert_expr_rule!(BoringWords, false);
insert_expr_rule!(Bought, true);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index 673f3c5ba..d9c4b3791 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -22,6 +22,7 @@ mod ask_no_preposition;
mod avoid_curses;
mod back_in_the_day;
mod be_allowed;
+mod behind_the_scenes;
mod best_of_all_time;
mod boring_words;
mod bought;