Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(#253): correct homophone to homograph and separate test
Grant Lemons4a51cc3884f8
diff --git a/harper-core/src/document.rs b/harper-core/src/document.rsindex c20b765ce..f7c121f79 100644--- a/harper-core/src/document.rs+++ b/harper-core/src/document.rs@@ -502,7 +502,7 @@ impl TokenStringExt for Document {create_fns_on_doc!(sentence_terminator);create_fns_on_doc!(chunk_terminator);create_fns_on_doc!(punctuation);- create_fns_on_doc!(homophone);+ create_fns_on_doc!(likely_homograph);fn first_sentence_word(&self) -> Option<Token> {self.tokens.first_sentence_word()diff --git a/harper-core/src/linting/repeated_words.rs b/harper-core/src/linting/repeated_words.rsindex f2b1e2f11..bacb72696 100644--- a/harper-core/src/linting/repeated_words.rs+++ b/harper-core/src/linting/repeated_words.rs@@ -16,7 +16,7 @@ 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 !tok_a.kind.is_homophone() && word_a.to_lower() == word_b.to_lower() {+ if !tok_a.kind.is_likely_homograph() && 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()) {@@ -51,8 +51,12 @@ mod tests {}#[test]- fn does_not_lint_homophones() {+ fn does_not_lint_homographs_address() {assert_lint_count("To address address problems.", RepeatedWords::default(), 0);+ }++ #[test]+ fn does_not_lint_homographs_record() {assert_lint_count("To record record profits.", RepeatedWords::default(), 0);}}diff --git a/harper-core/src/token.rs b/harper-core/src/token.rsindex 9df4b1704..3da5722d7 100644--- a/harper-core/src/token.rs+++ b/harper-core/src/token.rs@@ -323,12 +323,12 @@ impl TokenKind {metadata.is_noun()}- pub fn is_homophone(&self) -> bool {+ pub fn is_likely_homograph(&self) -> bool {let TokenKind::Word(metadata) = self else {return false;};- metadata.is_homophone()+ metadata.is_likely_homograph()}pub fn is_comma(&self) -> bool {@@ -405,7 +405,7 @@ pub trait TokenStringExt {create_decl_for!(sentence_terminator);create_decl_for!(chunk_terminator);create_decl_for!(punctuation);- create_decl_for!(homophone);+ create_decl_for!(likely_homograph);fn iter_linking_verb_indices(&self) -> impl Iterator<Item = usize> + '_;fn iter_linking_verbs(&self) -> impl Iterator<Item = Token> + '_;@@ -438,7 +438,7 @@ impl TokenStringExt for [Token] {create_fns_for!(unlintable);create_fns_for!(sentence_terminator);create_fns_for!(chunk_terminator);- create_fns_for!(homophone);+ create_fns_for!(likely_homograph);fn first_non_whitespace(&self) -> Option<Token> {self.iter().find(|t| !t.kind.is_whitespace()).copied()diff --git a/harper-core/src/word_metadata.rs b/harper-core/src/word_metadata.rsindex b57abcb44..e1e0060f4 100644--- a/harper-core/src/word_metadata.rs+++ b/harper-core/src/word_metadata.rs@@ -113,9 +113,9 @@ impl WordMetadata {)}- /// Checks if the word is a homophone+ /// Checks if the word is a homograph/// This is based off of metadata, so it is not guaranteed to be correct- pub fn is_homophone(&self) -> bool {+ pub fn is_likely_homograph(&self) -> bool {[matches!(self.noun,