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
34 changes: 33 additions & 1 deletion harper-core/src/linting/spell_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::num::NonZero;
use lru::LruCache;
use smallvec::ToSmallVec;

use super::Suggestion;
use super::{Lint, LintKind, Linter};
use super::{Suggestion, informal_laughter::is_informal_laughter};
use crate::document::Document;
use crate::spell::{Dictionary, suggest_correct_spelling};
use crate::{CharString, CharStringExt, Dialect, TokenStringExt};
Expand Down Expand Up @@ -73,6 +73,10 @@ impl<T: Dictionary> Linter for SpellCheck<T> {
for word in document.iter_words() {
let word_chars = document.get_span_content(&word.span);

if is_informal_laughter(word_chars) {
continue;
}

if let Some(metadata) = word.kind.as_word().unwrap()
&& metadata.dialects.is_dialect_enabled(self.dialect)
&& (self.dictionary.contains_exact_word(word_chars)
Expand Down Expand Up @@ -150,6 +154,24 @@ mod tests {
};
use crate::{DictWordMetadata, Document};

#[test]
fn athough_suggests_although() {
assert_suggestion_result(
"athough it was late, we continued.",
SpellCheck::new(FstDictionary::curated(), Dialect::American),
"although it was late, we continued.",
);
}

#[test]
fn athough_suggests_although_capitalized() {
assert_suggestion_result(
"Athough it was late, we continued.",
SpellCheck::new(FstDictionary::curated(), Dialect::American),
"Although it was late, we continued.",
);
}

// Capitalization tests

#[test]
Expand Down Expand Up @@ -1007,4 +1029,14 @@ mod tests {
"children's",
);
}

#[test]
fn allows_informal_laughter() {
for source in ["hahah", "hahaha", "hahahah", "Hahahah", "HAHAHA"] {
assert_no_lints(
source,
SpellCheck::new(FstDictionary::curated(), Dialect::American),
);
}
}
}
Loading