Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(#253): lint span both words, not just the second
Grant Lemons2ed85b71041f
diff --git a/harper-core/src/linting/repeated_words.rs b/harper-core/src/linting/repeated_words.rsindex d377c0b2c..60c7c0410 100644--- a/harper-core/src/linting/repeated_words.rs+++ b/harper-core/src/linting/repeated_words.rs@@ -1,6 +1,6 @@use super::{Lint, LintKind, Linter, Suggestion};-use crate::token::{Token, TokenKind, TokenStringExt};-use crate::{Document, Span};+use crate::token::TokenStringExt;+use crate::{CharStringExt, Document, Span};#[derive(Debug, Clone, Default)]pub struct RepeatedWords;@@ -16,30 +16,19 @@ impl Linter for RepeatedWords {let word_a = document.get_span_content(tok_a.span);let word_b = document.get_span_content(tok_b.span);- if word_a == word_b {+ if word_a.to_lower() == word_b.to_lower() {let intervening_tokens = &chunk[idx_a + 1..*idx_b];if intervening_tokens.iter().any(|t| !t.kind.is_whitespace()) {continue;}- // Detect and remove the whitespace between the repetitions.- let remove_end = tok_b.span.end;-- let remove_start = if let Some(Token {- span,- kind: TokenKind::Space(_),- }) = intervening_tokens.last()- {- span.start- } else {- tok_b.span.start- };-lints.push(Lint {- span: Span::new(remove_start, remove_end),+ span: Span::new(tok_a.span.start, tok_b.span.end),lint_kind: LintKind::Repetition,- suggestions: vec![Suggestion::Remove],+ suggestions: vec![Suggestion::ReplaceWith(+ document.get_span_content(tok_a.span).to_vec(),+ )],message: "Did you mean to repeat this word?".to_string(),..Default::default()})