Skip to content

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

feat(core): add rule for `widely accepted`

Elijah Potter8ea1c31fd726
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 40072336b..eefced450 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -62,6 +62,7 @@ use super::unclosed_quotes::UnclosedQuotes;
use super::use_genitive::UseGenitive;
use super::was_aloud::WasAloud;
use super::whereas::Whereas;
+use super::widely_accepted::WidelyAccepted;
use super::wordpress_dotcom::WordPressDotcom;
use super::{CurrencyPlacement, Linter, NoOxfordComma, OxfordComma};
use super::{Lint, PatternLinter};
@@ -341,6 +342,7 @@ impl LintGroup {
insert_struct_rule!(LetsConfusion, true);
insert_pattern_rule!(DespiteOf, true);
insert_pattern_rule!(ChockFull, true);
+ insert_struct_rule!(WidelyAccepted, true);
insert_pattern_rule!(Confident, true);
insert_pattern_rule!(Oxymorons, true);
insert_pattern_rule!(Hedging, true);
diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rs
index a434dbd94..36372c277 100644
--- a/harper-core/src/linting/mod.rs
+++ b/harper-core/src/linting/mod.rs
@@ -65,6 +65,7 @@ mod unclosed_quotes;
mod use_genitive;
mod was_aloud;
mod whereas;
+mod widely_accepted;
mod wordpress_dotcom;
pub use adjective_of_a::AdjectiveOfA;
@@ -126,6 +127,7 @@ pub use unclosed_quotes::UnclosedQuotes;
pub use use_genitive::UseGenitive;
pub use was_aloud::WasAloud;
pub use whereas::Whereas;
+pub use widely_accepted::WidelyAccepted;
pub use wordpress_dotcom::WordPressDotcom;
use crate::{Document, LSend};
diff --git a/harper-core/src/linting/widely_accepted.rs b/harper-core/src/linting/widely_accepted.rs
new file mode 100644
index 000000000..1813603af
--- /dev/null
+++ b/harper-core/src/linting/widely_accepted.rs
@@ -0,0 +1,44 @@
+use crate::{
+ Token,
+ linting::{Lint, LintKind, PatternLinter, Suggestion},
+ patterns::{AnyCapitalization, Pattern, SequencePattern, WordSet},
+};
+
+pub struct WidelyAccepted {
+ pattern: SequencePattern,
+}
+
+impl Default for WidelyAccepted {
+ fn default() -> Self {
+ let pattern = SequencePattern::default()
+ .then(AnyCapitalization::new("wide".chars().collect()))
+ .then_whitespace()
+ .then(WordSet::new(&["accepted", "acceptable", "used"]));
+
+ Self { pattern }
+ }
+}
+
+impl PatternLinter for WidelyAccepted {
+ fn pattern(&self) -> &dyn Pattern {
+ &self.pattern
+ }
+
+ fn match_to_lint(&self, matched_tokens: &[Token], _source: &[char]) -> Option<Lint> {
+ // We only need to replace the `wide` token with `widely`.
+ let wide_token = matched_tokens.first()?;
+
+ Some(Lint {
+ span: wide_token.span,
+ lint_kind: LintKind::Miscellaneous,
+ message: "Use the adverb `widely` in this context. For example, `widely accepted` or `widely used` is standard usage."
+ .to_owned(),
+ suggestions: vec![Suggestion::ReplaceWith("widely".chars().collect())],
+ priority: 31,
+ })
+ }
+
+ fn description(&self) -> &str {
+ "Flags `wide accepted`, `wide acceptable`, or `wide used` and recommends switching `wide` to the adverb `widely`."
+ }
+}
diff --git a/justfile b/justfile
index fd7fcb129..4caf3552f 100644
--- a/justfile
+++ b/justfile
@@ -358,7 +358,7 @@ registerlinter module name:
sed -i "/pub use an_a::AnA;/a pub use {{module}}::{{name}};" "$D/mod.rs"
sed -i "/use super::an_a::AnA;/a use super::{{module}}::{{name}};" "$D/lint_group.rs"
- sed -i "/insert_struct_rule!(ChockFull, true);/a \ \ \ \ insert_struct_rule!({{name}}, true);" "$D/lint_group.rs"
+ sed -i "/insert_pattern_rule!(ChockFull, true);/a \ \ \ \ insert_struct_rule!({{name}}, true);" "$D/lint_group.rs"
just format
# Print affixes and their descriptions from affixes.json