Skip to content

Commit

Permalink
feat(core): extended OxfordCommas to cover *or* cases
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 7, 2025
1 parent d516897 commit 29983db
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions harper-core/src/linting/oxford_comma.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
patterns::{Pattern, SequencePattern},
patterns::{EitherPattern, Pattern, SequencePattern},
Document, Token, TokenStringExt,
};

Expand All @@ -21,7 +21,10 @@ impl OxfordComma {
))
.then_noun_phrase()
.then_whitespace()
.then_exact_word("and")
.then(Box::new(EitherPattern::new(vec![
Box::new(SequencePattern::aco("and")),
Box::new(SequencePattern::aco("or")),
])))
.then_whitespace()
.then_noun_phrase(),
}
Expand Down Expand Up @@ -136,4 +139,18 @@ mod tests {
fn allows_clean_nations() {
assert_lint_count("The team consists of players from different countries: France, Germany, Italy, and Spain.", OxfordComma::default(), 0);
}

#[test]
fn or_writing() {
assert_suggestion_result("Harper can be a lifesaver when writing technical documents, emails or other formal forms of communication.", OxfordComma::default(), "Harper can be a lifesaver when writing technical documents, emails, or other formal forms of communication.",);
}

#[test]
fn sports() {
assert_suggestion_result(
"They enjoy playing soccer, basketball or tennis.",
OxfordComma::default(),
"They enjoy playing soccer, basketball, or tennis.",
);
}
}

0 comments on commit 29983db

Please sign in to comment.