Skip to content

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

feat: lint for chalk-full, choke-full -> chock-full + hyphenation

hippietrailb1eb80a79f8e
diff --git a/harper-core/src/linting/chock_full.rs b/harper-core/src/linting/chock_full.rs
new file mode 100644
index 000000000..06ef8a107
--- /dev/null
+++ b/harper-core/src/linting/chock_full.rs
@@ -0,0 +1,145 @@
+use crate::{
+ patterns::{EitherPattern, Pattern, SequencePattern, WhitespacePattern, WordSet},
+ Token, TokenStringExt,
+};
+
+use super::{Lint, LintKind, PatternLinter, Suggestion};
+
+pub struct ChockFull {
+ pattern: Box<dyn Pattern>,
+}
+
+impl Default for ChockFull {
+ fn default() -> Self {
+ Self {
+ pattern: Box::new(
+ SequencePattern::default()
+ .then(Box::new(WordSet::all(&["chalk", "choke"])))
+ .then(Box::new(EitherPattern::new(vec![
+ Box::new(WhitespacePattern),
+ Box::new(|tok: &Token, _source: &[char]| tok.kind.is_hyphen()),
+ ])))
+ .then_exact_word("full"),
+ ),
+ }
+ }
+}
+
+impl PatternLinter for ChockFull {
+ fn pattern(&self) -> &dyn Pattern {
+ self.pattern.as_ref()
+ }
+
+ fn match_to_lint(&self, matched_toks: &[Token], source: &[char]) -> Lint {
+ let span = matched_toks.span().unwrap();
+
+ Lint {
+ span,
+ lint_kind: LintKind::WordChoice,
+ suggestions: vec![Suggestion::replace_with_match_case_str(
+ "chock-full",
+ span.get_content(source),
+ )],
+ message: format!(
+ "The standard term is \"chock-full\"{}.",
+ if matched_toks[1].kind.is_whitespace() {
+ ", and it should be hyphenated"
+ } else {
+ ""
+ }
+ ),
+ priority: 126,
+ }
+ }
+
+ fn description(&self) -> &'static str {
+ "Flags common soundalikes of \"chock-full\" and makes sure they're hyphenated."
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::ChockFull;
+ use crate::linting::tests::{assert_lint_count, assert_suggestion_result};
+
+ #[test]
+ fn allows_correct_form() {
+ assert_lint_count(
+ "'Chalk full', 'chalk-full', 'choke full', and 'choke-full' are nonstandard forms of 'chock-full'.",
+ ChockFull::default(),
+ 4,
+ );
+ }
+
+ #[test]
+ fn lower_space_chalk() {
+ assert_suggestion_result(
+ "The codebase is chalk full of errors that we need to address.",
+ ChockFull::default(),
+ "The codebase is chock-full of errors that we need to address.",
+ );
+ }
+
+ #[test]
+ fn lower_space_choke() {
+ assert_suggestion_result(
+ "The project is choke full of questionable decisions that we need to revisit.",
+ ChockFull::default(),
+ "The project is chock-full of questionable decisions that we need to revisit.",
+ );
+ }
+
+ #[test]
+ fn upper_space_chalk() {
+ assert_suggestion_result(
+ "Chalk full of deprecated methods; we should refactor.",
+ ChockFull::default(),
+ "Chock-full of deprecated methods; we should refactor.",
+ );
+ }
+
+ #[test]
+ fn upper_space_choke() {
+ assert_suggestion_result(
+ "Choke full of unnecessary complexity; simplify it.",
+ ChockFull::default(),
+ "Chock-full of unnecessary complexity; simplify it.",
+ );
+ }
+
+ #[test]
+ fn lower_hyphen_chalk() {
+ assert_suggestion_result(
+ "The code is chalk-full of bugs; we need to debug before release.",
+ ChockFull::default(),
+ "The code is chock-full of bugs; we need to debug before release.",
+ );
+ }
+
+ #[test]
+ fn lower_hyphen_choke() {
+ assert_suggestion_result(
+ "The project is choke-full of warnings; we should address them.",
+ ChockFull::default(),
+ "The project is chock-full of warnings; we should address them.",
+ );
+ }
+
+ #[test]
+ fn upper_hyphen_chalk() {
+ assert_suggestion_result(
+ "Chalk-full of features, but we only need a few.",
+ ChockFull::default(),
+ "Chock-full of features, but we only need a few.",
+ );
+ }
+
+ #[test]
+ fn upper_hyphen_choke() {
+ assert_suggestion_result(
+ "Choke-full of pitfalls; let's consider alternatives.",
+ ChockFull::default(),
+ "Chock-full of pitfalls; let's consider alternatives.",
+ );
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 7ac6a6302..f27daea2f 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -5,6 +5,7 @@ use super::an_a::AnA;
use super::avoid_curses::AvoidCurses;
use super::boring_words::BoringWords;
use super::capitalize_personal_pronouns::CapitalizePersonalPronouns;
+use super::chock_full::ChockFull;
use super::closed_compounds::Overnight;
use super::closed_compounds::{
Anybody, Anyhow, Anywhere, Backplane, Devops, Everywhere, Henceforth, However, Insofar,
@@ -265,6 +266,7 @@ create_lint_group_config!(
SomewhatSomething => true,
LetsConfusion => true,
DespiteOf => true,
+ ChockFull => true,
HumanLife => true,
NeedHelp => true,
NoLonger => true,
diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rs
index 3dca39187..f06a21f39 100644
--- a/harper-core/src/linting/matcher.rs
+++ b/harper-core/src/linting/matcher.rs
@@ -134,9 +134,10 @@ impl Matcher {
"my","french" => "my French"
});
- // hyphenate phrasal adjectives
+ // hyphenated phrases
triggers.extend(pt! {
"case", "sensitive" => "case-sensitive",
+ "chock","full" => "chock-full",
"ngram" => "n-gram",
"off","the","cuff" => "off-the-cuff",
"Tree", "sitter" => "Tree-sitter",
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index c86189b97..84a5826f9 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -6,6 +6,7 @@ mod an_a;
mod avoid_curses;
mod boring_words;
mod capitalize_personal_pronouns;
+mod chock_full;
mod closed_compounds;
mod compound_nouns;
mod correct_number_suffix;
@@ -54,6 +55,7 @@ pub use an_a::AnA;
pub use avoid_curses::AvoidCurses;
pub use boring_words::BoringWords;
pub use capitalize_personal_pronouns::CapitalizePersonalPronouns;
+pub use chock_full::ChockFull;
pub use closed_compounds::Overnight;
pub use closed_compounds::{
Anybody, Anyhow, Anywhere, Backplane, Devops, Everywhere, Henceforth, However, Insofar,