Skip to content

fix(that-than): catch 'less/fewer [adj] that' periphrastic comparison typos#3786

Open
yakubka wants to merge 1 commit into
Automattic:masterfrom
yakubka:fix/that-than-less-adj-pattern
Open

fix(that-than): catch 'less/fewer [adj] that' periphrastic comparison typos#3786
yakubka wants to merge 1 commit into
Automattic:masterfrom
yakubka:fix/that-than-less-adj-pattern

Conversation

@yakubka

@yakubka yakubka commented Jul 8, 2026

Copy link
Copy Markdown

Fixes #3736.

The ThatThan linter currently catches comparative adjective forms like "smaller that", "faster that", "longer that" by matching tokens where TokenKind::is_comparative_adjective precedes "that". It does not catch periphrastic comparisons of the form "less/fewer [positive adjective] that [...]", so "way less common that mp3" passes through unflagged.

This PR adds a second branch to the SequenceExpr that matches "less" or "fewer" followed by a positive adjective, then "that", then any word except "way". The match_to_lint function now derives the "that" token index from toks.len() to support both the 5-token pattern (adj ws that ws word) and the new 7-token pattern (less ws adj ws that ws word).

"more [adj] that" is excluded intentionally. "more [adj] that [clause]" frequently introduces a correct subordinate clause ("more clear that users need to...", "more explicit that those files are..."), so flagging it would produce too many false positives without deeper grammatical analysis. The existing test cases dont_flag_more_explicit_that and dont_flag_more_clear_that still pass.

Three new tests cover the added pattern. The remaining existing tests are unchanged.

Yokubjon Nurullaev identified the gap in the periphrastic branch, wrote the SequenceExpr and updated match_to_lint to handle the variable token index.

IbrokhimN reviewed the "more" exclusion decision, proposed the dont_flag tests that guard against subordinate clause false positives, and added the fix_fewer_errors_that test case.

… typos

Added a second SequenceExpr branch to ThatThan that matches
'less' or 'fewer' followed by a plain (positive) adjective, then 'that',
then any word except 'way'. This catches patterns like:
  'way less common that mp3'     -> 'way less common than mp3'
  'less reliable that the previous one' -> 'less reliable than the previous one'
  'fewer errors that expected'   -> 'fewer errors than expected'

The original linter only handled comparative adjectives (words ending -er
like 'smaller', 'faster') preceding 'that'. Periphrastic comparisons using
'less'/'fewer' + plain adjective were missed.

'more [adj] that [...]' is deliberately excluded because it frequently
introduces a correct subordinate clause ('more clear that users need to...'),
making it too noisy to flag without deeper grammatical analysis.

match_to_lint now derives the 'that' token index from toks.len() instead
of hardcoding 2, supporting the 5-token (adj that word) and 7-token
(less adj that word) patterns.

Fixes Automattic#3736.

Co-authored-by: IbrokhimN <ibragimnurullayev@gmail.com>
@hippietrail

Copy link
Copy Markdown
Collaborator

The ThatThan linter currently catches comparative adjective forms like "smaller that", "faster that", "longer that" by matching tokens where TokenKind::is_comparative_adjective precedes "that". It does not catch periphrastic comparisons of the form "less/fewer [positive adjective] that [...]", so "way less common that mp3" passes through unflagged.

"Fewer [adjective]" is not grammatical. "Fewer" can be used before a plural noun. You surely meant "less/more" here?

@hippietrail hippietrail left a comment

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.

You surely mean "less <adj>" and "more <adj>" and not "fewer <adj>"?

// "that" should be "than". "more [adj] that" is excluded because it
// frequently introduces a correct subordinate clause ("more clear that
// users need to...").
let periphrastic_that_nextword = SequenceExpr::word_set(&["less", "fewer"])

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.

This is "fewer correct" than you think it might be (-;

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.

False negative missing "that" as a typo for "than"

2 participants