From 29983db520f368a76b827f7e21f58bd10e3f2960 Mon Sep 17 00:00:00 2001 From: Elijah Potter Date: Tue, 7 Jan 2025 09:02:55 -0700 Subject: [PATCH] feat(core): extended `OxfordCommas` to cover `*or*` cases --- harper-core/src/linting/oxford_comma.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/harper-core/src/linting/oxford_comma.rs b/harper-core/src/linting/oxford_comma.rs index 51dcf683..a52a228c 100644 --- a/harper-core/src/linting/oxford_comma.rs +++ b/harper-core/src/linting/oxford_comma.rs @@ -1,5 +1,5 @@ use crate::{ - patterns::{Pattern, SequencePattern}, + patterns::{EitherPattern, Pattern, SequencePattern}, Document, Token, TokenStringExt, }; @@ -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(), } @@ -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.", + ); + } }