Skip to content

Commit a69e3d2

Browse files
authored
feat: fed up of→fed up with (#2833)
Only when the dialect is not British Also changes `out.add()` to `out.add_chunk_expr_linter()` in `lint_group.rs` for three other linters that use `Dialect` with `ExprLinter`
1 parent ffd142c commit a69e3d2

3 files changed

Lines changed: 112 additions & 3 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
use crate::{
2+
Dialect, Token,
3+
expr::{Expr, SequenceExpr},
4+
linting::{ExprLinter, Lint, LintKind, Suggestion, expr_linter::Chunk},
5+
};
6+
7+
pub struct FedUpWith {
8+
expr: Box<dyn Expr>,
9+
dialect: Dialect,
10+
}
11+
12+
impl FedUpWith {
13+
pub fn new(dialect: Dialect) -> Self {
14+
let expr = SequenceExpr::fixed_phrase("fed up of");
15+
16+
Self {
17+
expr: Box::new(expr),
18+
dialect,
19+
}
20+
}
21+
}
22+
23+
impl ExprLinter for FedUpWith {
24+
type Unit = Chunk;
25+
26+
fn expr(&self) -> &dyn Expr {
27+
self.expr.as_ref()
28+
}
29+
30+
fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
31+
if self.dialect == Dialect::British {
32+
return None;
33+
}
34+
35+
let oftok = toks.last()?;
36+
let ofspan = oftok.span;
37+
38+
Some(Lint {
39+
span: ofspan,
40+
lint_kind: LintKind::Usage,
41+
suggestions: vec![Suggestion::replace_with_match_case_str(
42+
"with",
43+
ofspan.get_content(src),
44+
)],
45+
message: "`Fed up of` is not accepted outside of British English.".to_string(),
46+
..Default::default()
47+
})
48+
}
49+
50+
fn description(&self) -> &str {
51+
"Corrects `fed up of` to `fed up with` in dialects other than British English."
52+
}
53+
}
54+
55+
#[cfg(test)]
56+
mod tests {
57+
use super::FedUpWith;
58+
use crate::Dialect;
59+
use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
60+
61+
#[test]
62+
fn correct_fed_up_of_in_us_english() {
63+
assert_suggestion_result(
64+
"I am fed up of Bugzilla reports being ignored.",
65+
FedUpWith::new(Dialect::American),
66+
"I am fed up with Bugzilla reports being ignored.",
67+
);
68+
}
69+
70+
#[test]
71+
fn correct_fed_up_of_in_canadian_english() {
72+
assert_suggestion_result(
73+
"Fed up of long links ??? Use ✨ Linsh ✨, a CLI tool to shorten links.",
74+
FedUpWith::new(Dialect::Canadian),
75+
"Fed up with long links ??? Use ✨ Linsh ✨, a CLI tool to shorten links.",
76+
);
77+
}
78+
79+
#[test]
80+
fn correct_fed_up_of_in_aus_english() {
81+
assert_suggestion_result(
82+
"Fed up of the lack of Twitter embedded timeline styling options?",
83+
FedUpWith::new(Dialect::Australian),
84+
"Fed up with the lack of Twitter embedded timeline styling options?",
85+
);
86+
}
87+
88+
#[test]
89+
fn correct_fed_up_of_in_indian_english() {
90+
assert_suggestion_result(
91+
"I got fed up of finding my IP (v4) address in the big pile of text that ifconfig outputs on OS X.",
92+
FedUpWith::new(Dialect::Indian),
93+
"I got fed up with finding my IP (v4) address in the big pile of text that ifconfig outputs on OS X.",
94+
);
95+
}
96+
97+
#[test]
98+
fn dont_flag_fed_up_of_in_british_english() {
99+
assert_no_lints(
100+
"Fed up of having to repeat the same actions for installing webmin so here's a script for 16.04+",
101+
FedUpWith::new(Dialect::British),
102+
);
103+
}
104+
}

harper-core/src/linting/lint_group.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use super::expand_time_shorthands::ExpandTimeShorthands;
7171
use super::expr_linter::run_on_chunk;
7272
use super::far_be_it::FarBeIt;
7373
use super::fascinated_by::FascinatedBy;
74+
use super::fed_up_with::FedUpWith;
7475
use super::feel_fell::FeelFell;
7576
use super::few_units_of_time_ago::FewUnitsOfTimeAgo;
7677
use super::filler_words::FillerWords;
@@ -639,7 +640,7 @@ impl LintGroup {
639640
);
640641
out.config.set_rule_enabled("InflectedVerbAfterTo", true);
641642

642-
out.add("InOnTheCards", InOnTheCards::new(dialect));
643+
out.add_chunk_expr_linter("InOnTheCards", InOnTheCards::new(dialect));
643644
out.config.set_rule_enabled("InOnTheCards", true);
644645

645646
out.add(
@@ -651,10 +652,10 @@ impl LintGroup {
651652
out.add("PossessiveNoun", PossessiveNoun::new(dictionary.clone()));
652653
out.config.set_rule_enabled("PossessiveNoun", false);
653654

654-
out.add("Regionalisms", Regionalisms::new(dialect));
655+
out.add_chunk_expr_linter("Regionalisms", Regionalisms::new(dialect));
655656
out.config.set_rule_enabled("Regionalisms", true);
656657

657-
out.add("HaveTakeALook", HaveTakeALook::new(dialect));
658+
out.add_chunk_expr_linter("HaveTakeALook", HaveTakeALook::new(dialect));
658659
out.config.set_rule_enabled("HaveTakeALook", true);
659660

660661
out.add("MassNouns", MassNouns::new(dictionary.clone()));
@@ -701,6 +702,9 @@ impl LintGroup {
701702
out.add_chunk_expr_linter("DidPast", DidPast::new(dictionary.clone()));
702703
out.config.set_rule_enabled("DidPast", true);
703704

705+
out.add_chunk_expr_linter("FedUpWith", FedUpWith::new(dialect));
706+
out.config.set_rule_enabled("FedUpWith", true);
707+
704708
out
705709
}
706710

harper-core/src/linting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ mod expand_time_shorthands;
6666
mod expr_linter;
6767
mod far_be_it;
6868
mod fascinated_by;
69+
mod fed_up_with;
6970
mod feel_fell;
7071
mod few_units_of_time_ago;
7172
mod filler_words;

0 commit comments

Comments
 (0)