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.",
);
}
}

2 comments on commit 29983db

@ccoVeille
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should have been updated to mention the or

29983db#diff-ce301fc752684fe434e0eceeb657696fdc489530108543fe5ee86a16e51adce8L84

"The Oxford comma is one of the more controversial rules in common use today. Here, we make sure that we put a comma before and when listing out more than two ideas."

BTW, I found no PR for this commit, is it normal?

@elijah-potter
Copy link
Collaborator Author

@elijah-potter elijah-potter commented on 29983db Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should have been updated to mention the or

Would you like to open a PR for this, or would you rather I make the change? If you decide to do the former, you would be able to get a feel for our contribution process 😄. I also want to make sure you get added to the contributors list, even if it is a small change.

Thanks for noticing!

BTW, I found no PR for this commit, is it normal?

We're only just now starting to strongly incorporate PRs into how we evolve the code. For old commits, it is normal.

Please sign in to comment.