Skip to content

Comments

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

Open
LouisLau-art wants to merge 1 commit intoAutomattic:masterfrom
LouisLau-art:fix/few-vs-a-few
Open

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

Conversation

@LouisLau-art
Copy link

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
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
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.

// inserting an article would be incorrect.
if matches!(
prev_word.as_deref(),
Some("too" | "very" | "so" | "quite" | "how")
Copy link
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
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
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.

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