Skip to content

Commit

Permalink
Merge pull request #390 from Automattic/infinite-lint-loops
Browse files Browse the repository at this point in the history
fix(core): infinite lint loops
  • Loading branch information
elijah-potter authored Jan 21, 2025
2 parents 449d1b5 + b94d3b7 commit 4d8b80e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 48 deletions.
3 changes: 2 additions & 1 deletion harper-core/dictionary.dict
Original file line number Diff line number Diff line change
Expand Up @@ -45440,7 +45440,8 @@ thatch/14MDRSZG
thatcher/1M
thatching/14M
thaw/41MDGS
the/-+81JG~
the/-+J~
thing/SM
theater/1SM
theatergoer/1SM
theatrical/51YS
Expand Down
4 changes: 2 additions & 2 deletions harper-core/src/linting/currency_placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl Linter for CurrencyPlacement {
lints.extend(generate_lint_for_tokens(*a, *b, document));
}

for (a, b, c) in chunk.iter().tuple_windows() {
if !b.kind.is_whitespace() {
for (p, a, b, c) in chunk.iter().tuple_windows() {
if !b.kind.is_whitespace() || p.kind.is_currency() {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions harper-core/src/linting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@ mod tests {
let transformed_str: String = text.iter().collect();

assert_eq!(transformed_str.as_str(), expected_result);

// Applying the suggestions should fix all the lints.
assert_lint_count(&transformed_str, linter, 0);
}
}
25 changes: 0 additions & 25 deletions harper-core/src/linting/pronoun_contraction/avoid_contraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,3 @@ impl PatternLinter for AvoidContraction {
"This rule looks for situations where a contraction was used where it shouldn't have been."
}
}

#[cfg(test)]
mod tests {
use crate::linting::tests::assert_suggestion_result;

use super::AvoidContraction;

#[test]
fn issue_139() {
assert_suggestion_result(
"it would be great if you're PR was merged into tower-lsp",
AvoidContraction::default(),
"it would be great if your PR was merged into tower-lsp",
);
}

#[test]
fn car() {
assert_suggestion_result(
"You're car is black.",
AvoidContraction::default(),
"Your car is black.",
);
}
}
42 changes: 42 additions & 0 deletions harper-core/src/linting/pronoun_contraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,45 @@ use avoid_contraction::AvoidContraction;
use should_contract::ShouldContract;

merge_linters! {PronounContraction => ShouldContract, AvoidContraction => "Choosing when to contract pronouns is a challenging art. This rule looks for faults." }

#[cfg(test)]
mod tests {
use super::PronounContraction;
use crate::linting::tests::assert_suggestion_result;

#[test]
fn issue_225() {
assert_suggestion_result(
"Your the man",
PronounContraction::default(),
"You're the man",
);
}

#[test]
fn were_team() {
assert_suggestion_result(
"Were the best team.",
PronounContraction::default(),
"We're the best team.",
);
}

#[test]
fn issue_139() {
assert_suggestion_result(
"it would be great if you're PR was merged into tower-lsp",
PronounContraction::default(),
"it would be great if your PR was merged into tower-lsp",
);
}

#[test]
fn car() {
assert_suggestion_result(
"You're car is black.",
PronounContraction::default(),
"Your car is black.",
);
}
}
20 changes: 0 additions & 20 deletions harper-core/src/linting/pronoun_contraction/should_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,3 @@ impl PatternLinter for ShouldContract {
"Neglecting the apostrophe when contracting pronouns with \"are\" (like \"your\" and \"you are\") is a fatal, but extremely common mistake to make."
}
}

#[cfg(test)]
mod tests {
use super::ShouldContract;
use crate::linting::tests::assert_suggestion_result;

#[test]
fn issue_225() {
assert_suggestion_result("Your the man", ShouldContract::default(), "You're the man");
}

#[test]
fn were_team() {
assert_suggestion_result(
"Were the best team.",
ShouldContract::default(),
"We're the best team.",
);
}
}

0 comments on commit 4d8b80e

Please sign in to comment.