Skip to content

fix(linter): pre-compile jest assert-function patterns and skip invalid ones#23644

Closed
shulaoda wants to merge 1 commit into
oxc-project:mainfrom
shulaoda:06-19-fix_jest_assert_function_pattern
Closed

fix(linter): pre-compile jest assert-function patterns and skip invalid ones#23644
shulaoda wants to merge 1 commit into
oxc-project:mainfrom
shulaoda:06-19-fix_jest_assert_function_pattern

Conversation

@shulaoda

Copy link
Copy Markdown
Contributor

matches_assert_function_name (used by jest/prefer-ending-with-an-expect) recompiled every pattern with Regex::new(...) on every node visited — a hot path — and used .unwrap(), so a user-supplied assertFunctionNames pattern that expands to an invalid regex (e.g. "["(?ui)^[(\.|$)) would panic the linter.

Patterns are now compiled once when the rule config is built (mirroring the existing expect-expect rule), stored in a #[serde(skip)] field, and matches_assert_function_name takes the pre-compiled &[Regex]. Invalid patterns are skipped via Regex::new(...).ok() instead of panicking. This fixes both the per-call recompilation and the panic.

Regression tests: a malformed pattern no longer panics and the test block is still reported; a valid pattern alongside a malformed one still matches.

@shulaoda
shulaoda requested a review from camc314 as a code owner June 19, 2026 11:59
@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 66 skipped benchmarks1


Comparing shulaoda:06-19-fix_jest_assert_function_pattern (75f1fc2) with main (eb8bedc)

Open in CodSpeed

Footnotes

  1. 66 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@shulaoda
shulaoda marked this pull request as draft June 19, 2026 12:24
@camc314 camc314 added the A-linter Area - Linter label Jun 19, 2026
@camc314 camc314 self-assigned this Jun 19, 2026
graphite-app Bot pushed a commit that referenced this pull request Jul 3, 2026
…ns (#24122)

## Summary

- deserialize rule options through `DefaultRuleConfig`
- convert and validate configured assertion function patterns during deserialization
- propagate invalid regex configuration errors instead of panicking at lint runtime

Closes [#23644](#23644)
@graphite-app graphite-app Bot closed this in #24122 Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants