Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): infinite lint loops #390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 @@ -43,28 +43,3 @@ impl PatternLinter for AvoidContraction {
"This rule looks for situations where a contraction was used where it shouldn't."
}
}

#[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.",
);
}
}
Loading