Skip to content

Commit

Permalink
Merge pull request #735 from Automattic/then-edge-cases
Browse files Browse the repository at this point in the history
fix(core): address edge cases in `ThenThan` rule
  • Loading branch information
elijah-potter authored Feb 21, 2025
2 parents b5509e3 + 39e5c10 commit acea47f
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions harper-core/src/linting/then_than.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::{Lint, LintKind, PatternLinter};
use crate::Token;
use crate::char_string::char_string;
use crate::linting::Suggestion;
use crate::patterns::{All, Invert, OwnedPatternExt, Pattern, SequencePattern, WordSet};
use crate::patterns::{
All, AnyCapitalization, Invert, OwnedPatternExt, Pattern, SequencePattern, WordSet,
};

#[doc = "Corrects the misuse of `then` to `than`."]
pub struct ThenThan {
Expand All @@ -18,7 +21,9 @@ impl ThenThan {
|tok: &Token, _source: &[char]| tok.kind.is_adjective(),
)))
.then_whitespace()
.then_any_capitalization_of("then"),
.then_any_capitalization_of("then")
.then_whitespace()
.then(Invert::new(AnyCapitalization::new(char_string!("that")))),
),
// Denotes exceptions to the rule.
Box::new(Invert::new(WordSet::new(&["back"]))),
Expand All @@ -38,7 +43,7 @@ impl PatternLinter for ThenThan {
self.pattern.as_ref()
}
fn match_to_lint(&self, matched_tokens: &[Token], source: &[char]) -> Option<Lint> {
let span = matched_tokens.last()?.span;
let span = matched_tokens[2].span;
let offending_text = span.get_content(source);

Some(Lint {
Expand Down Expand Up @@ -171,4 +176,19 @@ mod tests {
fn allows_this_then() {
assert_lint_count("Do this then that.", ThenThan::default(), 0);
}

#[test]
fn allows_issue_720() {
assert_lint_count(
"And if just one of those is set incorrectly or it has the tiniest bit of dirt inside then that will wreak havoc with the engine's running ability.",
ThenThan::default(),
0,
);
assert_lint_count("So let's check it out then.", ThenThan::default(), 0);
assert_lint_count(
"And if just the tiniest bit of dirt gets inside then that will wreak havoc.",
ThenThan::default(),
0,
);
}
}

0 comments on commit acea47f

Please sign in to comment.