Skip to content

Commit 38e5f31

Browse files
Improve no-useless-assertion for nested assertions (#316)
* Update to `[email protected]` * Improve `no-useless-assertion` for nested assertions
1 parent a0db272 commit 38e5f31

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/rules/no-useless-assertions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getMatchingDirectionFromAssertionKind,
1616
hasSomeDescendant,
1717
isPotentiallyEmpty,
18+
FirstConsumedChars,
1819
} from "regexp-ast-analysis"
1920
import { mention } from "../utils/mention"
2021

@@ -211,14 +212,13 @@ export default createRule("no-useless-assertions", {
211212
return
212213
}
213214

214-
const firstOf = getFirstConsumedChar(
215-
assertion.alternatives,
216-
direction,
217-
flags,
215+
const firstOf = FirstConsumedChars.toLook(
216+
getFirstConsumedChar(
217+
assertion.alternatives,
218+
direction,
219+
flags,
220+
),
218221
)
219-
if (firstOf.empty) {
220-
return
221-
}
222222

223223
// the idea here is that a negate lookaround accepts when non-negated version reject and vise versa.
224224
const accept = assertion.negate ? "reject" : "accept"

tests/lib/rules/no-useless-assertions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,9 @@ tester.run("no-useless-assertions", rule as any, {
356356
},
357357
],
358358
},
359+
{
360+
code: String.raw`/(?=a|$)b/u`,
361+
errors: ["The lookahead '(?=a|$)' will always reject."],
362+
},
359363
],
360364
})

0 commit comments

Comments
 (0)