Skip to content

harper-core: flag 'few' in more time contexts#2660

Open
LouisLau-art wants to merge 2 commits intoAutomattic:masterfrom
LouisLau-art:fix/few-vs-a-few
Open

harper-core: flag 'few' in more time contexts#2660
LouisLau-art wants to merge 2 commits intoAutomattic:masterfrom
LouisLau-art:fix/few-vs-a-few

Conversation

@LouisLau-art
Copy link
Copy Markdown

Closes #1114.

What changed

  • Expand the existing FewUnitsOfTimeAgo rule from only matching few <time unit> ago to matching few <time unit> and then using surrounding context to decide whether it should be corrected to a few.
  • This allows catching very common constructions like After few minutes ... and Few minutes after ....

Heuristics (intentionally conservative)

Triggers when few <time unit> is followed by ago/after/before/later or preceded by after/before/in/within/for/since.
Skips when it already has an article (a/an/the) or when few is clearly negative (too/very/so/quite/how few).

Tests

  • Re-enable sentence-start cases (previously ignored).
  • Add new test cases for after few minutes / few minutes after.
  • Add basic false-positive guards (the few ..., too few ..., past few ...).

Copy link
Copy Markdown
Collaborator

@hippietrail hippietrail left a comment

Choose a reason for hiding this comment

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

So cool to see someone working on this! I made the original few_units_of_time_ago linter before I added match_to_lint_with_context()

| "your"
| "his"
| "her"
| "their"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See if .is_determiner() on TokenKind works here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a method on TokenKind, which is accessed from the .kind field of the Token. Note that my/our/your/his/her/their are considered "possessive determiners" so should be included. If not there's a method to check for those too. Did you leave out "its" intentionally?

// inserting an article would be incorrect.
if matches!(
prev_word.as_deref(),
Some("too" | "very" | "so" | "quite" | "how")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See if .is_degree_adverb() on TokenKind works here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this PR is close, but I am also interested if that method would work instead. @LouisLau-art, would you give it whirl?

@LouisLau-art
Copy link
Copy Markdown
Author

Thanks for the context — really appreciate you building the original linter! I used the existing behavior as a baseline and tried to keep the new context checks minimal + well-covered by tests.

Copy link
Copy Markdown
Collaborator

@elijah-potter elijah-potter left a comment

Choose a reason for hiding this comment

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

@LouisLau-art, I'd love to get this merged. Would you give that method a whirl and remove the parenthesized bit at the end of the description? Thanks!

Copy link
Copy Markdown
Collaborator

@hippietrail hippietrail left a comment

Choose a reason for hiding this comment

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

I added some thoughts to my previous review.

| "your"
| "his"
| "her"
| "their"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a method on TokenKind, which is accessed from the .kind field of the Token. Note that my/our/your/his/her/their are considered "possessive determiners" so should be included. If not there's a method to check for those too. Did you leave out "its" intentionally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag "few" used when it should be "a few"

3 participants