Automattic / Automattic/harper

`Expr` cannot match some `Optional` parts

Open
#3,958 0 comments 0 reactions 0 assignees View on GitHub
bug harper-core linting
Dominant language
Rust
Stars
15.4k
Forks
627
Avg merge
1d 15h
Merged PRs (30d)
106

Description

I'm working on a linter that needs a pattern with an optional arbitrary word between two set words:

"implement" + (optional word) + "into"

Surprisingly, even though this doesn't seem very different from what I've done several times in other linters, this one only succeeds when the optional word is present but fails when it's absent. Here's the `Expr`:
```rs
SequenceExpr::word_set(&[
"implement",
"implemented",
"implementing",
"implements",
])
.then_optional(
SequenceExpr::whitespace()
.then_any_word()
)
.t_ws()
.t_aco("into")
```
I also tried with the whitespace on the other side:
```rs
SequenceExpr::word_set(&[
"implement",
"implemented",
"implementing",
"implements",
])
.t_ws()
.then_optional(
SequenceExpr::any_word().t_ws()
)
.t_aco("into")
```
Either of these should match both "implement into" and "implement foobar into", but both only match the latter.

I've spent a few hours on this, thinking I'd just overlooked something in my linter. I've also tried an agent on it that often finds things and it hasn't hit it yet. So I think this is a real latent bug.

Contributor guide

Open the contributing guide

Research direction

Start by locating the Rust implementation of SequenceExpr and reproduce the two expressions against both "implement into" and "implement foobar into". Trace how then_optional handles whitespace and word matching; done means both expressions match both inputs without breaking the existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.