Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions harper-core/src/linting/that_than.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,23 @@
.t_ws()
.then_word_except(&["way"]);

// "less [adj] that [...]" is almost always a comparison where "that"
// should be "than". "more [adj] that" is excluded because it frequently
// introduces a correct subordinate clause ("more clear that users
// need to...").
let periphrastic_that_nextword = SequenceExpr::word("less")

Check failure on line 28 in harper-core/src/linting/that_than.rs

View workflow job for this annotation

GitHub Actions / just check-rust

no associated function or constant named `word` found for struct `SequenceExpr` in the current scope
.t_ws()
.then_positive_adjective()
.t_ws()
.t_aco("that")
.t_ws()
.then_word_except(&["way"]);

Self {
expr: adjective_er_that_nextword,
expr: SequenceExpr::any_of(vec![
Box::new(adjective_er_that_nextword),
Box::new(periphrastic_that_nextword),
]),
}
}
}
Expand All @@ -35,11 +50,13 @@
}

fn match_to_lint(&self, toks: &[Token], src: &[char]) -> Option<Lint> {
if toks.len() != 5 {
return None;
}
let that_idx = match toks.len() {
5 => 2,
7 => 4,
_ => return None,
};

let that_tok = &toks[2];
let that_tok = &toks[that_idx];

Some(Lint {
span: that_tok.span,
Expand Down Expand Up @@ -187,6 +204,26 @@
)
}

// less [adj] that

#[test]
fn fix_less_common_that() {
assert_suggestion_result(
"way less common that mp3",
ThatThan::default(),
"way less common than mp3",
);
}

#[test]
fn fix_less_reliable_that() {
assert_suggestion_result(
"this approach is less reliable that the previous one",
ThatThan::default(),
"this approach is less reliable than the previous one",
);
}

// more/less adj that

#[test]
Expand Down Expand Up @@ -221,7 +258,7 @@
#[test]
fn dont_flag_its_better_that() {
assert_lint_count(
"Its better that the shock should all come at once.",
"It's better that the shock should all come at once.",
ThatThan::default(),
0,
)
Expand Down
Loading