Skip to content

Commit

Permalink
fix(core): Automattic#341 by adding check to make sure we don't inclu…
Browse files Browse the repository at this point in the history
…de `*-only`
  • Loading branch information
elijah-potter committed Jan 2, 2025
1 parent 2c9c340 commit b56af6b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions harper-core/src/linting/terminating_conjunctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl Default for TerminatingConjunctions {
Self {
pattern: Box::new(ConsumesRemainingPattern::new(Box::new(
SequencePattern::default()
.then_anything_but_hyphen()
.then_any_word_in(Lrc::new(
[
"although",
Expand Down Expand Up @@ -92,4 +93,13 @@ mod tests {
fn no_false_positive() {
assert_lint_count("Cookies and milk.", TerminatingConjunctions::default(), 0)
}

#[test]
fn issue_341() {
assert_lint_count(
"The structure has a couple of fields marked read-only, like A and B",
TerminatingConjunctions::default(),
0,
);
}
}
13 changes: 13 additions & 0 deletions harper-core/src/patterns/sequence_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ macro_rules! gen_then_from_is {
tok.kind.[< is_$quality >]()
}))
}

pub fn [< then_anything_but_$quality >] (mut self) -> Self{
self.token_patterns.push(Box::new(|tok: &Token, _source: &[char]| {
if tok.kind.[< is_$quality >](){
false
}else{
true
}
}));

self
}
}
};
}
Expand All @@ -43,6 +55,7 @@ impl SequencePattern {
gen_then_from_is!(case_separator);
gen_then_from_is!(adverb);
gen_then_from_is!(adjective);
gen_then_from_is!(hyphen);

pub fn then_exact_word(mut self, word: &'static str) -> Self {
self.token_patterns
Expand Down
4 changes: 4 additions & 0 deletions harper-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl TokenKind {
matches!(self, TokenKind::Punctuation(Punctuation::Ellipsis))
}

pub fn is_hyphen(&self) -> bool {
matches!(self, TokenKind::Punctuation(Punctuation::Hyphen))
}

pub fn is_adjective(&self) -> bool {
matches!(
self,
Expand Down

0 comments on commit b56af6b

Please sign in to comment.