Skip to content

Commit

Permalink
fix(#253): correct homophone to homograph and separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Nov 17, 2024
1 parent 890c1ff commit 4a51cc3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion harper-core/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions harper-core/src/linting/repeated_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions harper-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> + '_;
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions harper-core/src/word_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4a51cc3

Please sign in to comment.