Skip to content

fix(linter): respect flags overrides for RegExp(/regex/i, "u")#22678

Merged
graphite-app[bot] merged 1 commit into
mainfrom
05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_
May 24, 2026
Merged

fix(linter): respect flags overrides for RegExp(/regex/i, "u")#22678
graphite-app[bot] merged 1 commit into
mainfrom
05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_

Conversation

@Sysix

@Sysix Sysix commented May 22, 2026

Copy link
Copy Markdown
Member

Pull request overview

This PR fixes linter handling of RegExp/new RegExp when the first argument is a regex literal and the second argument overrides flags (e.g. RegExp(/ab/u, "i")), aligning analysis with runtime behavior and addressing #13436.

closes #13436

Sysix commented May 22, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions Bot added the A-linter Area - Linter label May 22, 2026
@Sysix Sysix force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch from 4aa60a7 to 0df085e Compare May 22, 2026 15:12
@codspeed-hq

codspeed-hq Bot commented May 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 55 skipped benchmarks1


Comparing 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ (0e91242) with main (b84941e)

Open in CodSpeed

Footnotes

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

@Sysix Sysix force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch from 0df085e to 20ce418 Compare May 22, 2026 15:43
@Sysix Sysix requested a review from Copilot May 22, 2026 15:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes linter handling of RegExp/new RegExp when the first argument is a regex literal and the second argument overrides flags (e.g. RegExp(/ab/u, "i")), aligning analysis with runtime behavior and addressing #13436.

Changes:

  • Update ConstructorParser to support regex-literal text for the constructor pattern argument and always parse the flags argument as a string/template literal.
  • Update linter regex utilities to (a) avoid processing RegExpLiteral nodes that are part of RegExp(...)/new RegExp(...), and (b) reparse patterns only when Unicode-related flags (u/v) differ.
  • Extend no_misleading_character_class tests and snapshots to cover overridden-flag scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/oxc_regular_expression/src/parser/parser_impl.rs Improves constructor parsing to accept regex-literal patterns and correctly parse constructor flags.
crates/oxc_linter/src/utils/regex.rs Adjusts regex-node dispatch to respect constructor flag overrides and avoid double-processing literals.
crates/oxc_linter/src/snapshots/eslint_no_misleading_character_class.snap Updates diagnostics snapshots for newly covered overridden-flag cases.
crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs Adds/adjusts test cases covering overridden flags for RegExp/new RegExp.

Comment thread crates/oxc_linter/src/utils/regex.rs
Comment thread crates/oxc_regular_expression/src/parser/parser_impl.rs Outdated
Comment thread crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs Outdated
@Sysix Sysix force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch from 20ce418 to 65da5d0 Compare May 22, 2026 16:29
@Sysix Sysix marked this pull request as ready for review May 22, 2026 16:33
@Sysix Sysix requested review from camc314 and leaysgur as code owners May 22, 2026 16:33
@Sysix Sysix marked this pull request as draft May 22, 2026 17:18
@Sysix Sysix force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch from 65da5d0 to 314bcb9 Compare May 22, 2026 18:07
@Sysix Sysix force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch 2 times, most recently from 8a766d6 to 0e91242 Compare May 22, 2026 19:14
@Sysix Sysix marked this pull request as ready for review May 22, 2026 19:31
Comment thread crates/oxc_linter/src/utils/regex.rs
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 24, 2026

camc314 commented May 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

)

> ## Pull request overview
>
> This PR fixes linter handling of `RegExp`/`new RegExp` when the first argument is a regex literal and the second argument overrides flags (e.g. `RegExp(/ab/u, "i")`), aligning analysis with runtime behavior and addressing #13436.

closes #13436
@graphite-app graphite-app Bot force-pushed the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch from 0e91242 to ed445ba Compare May 24, 2026 13:18
@graphite-app graphite-app Bot merged commit ed445ba into main May 24, 2026
29 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 24, 2026
@graphite-app graphite-app Bot deleted the 05-22-fix_linter_respect_flags_overrides_for_regexp__regex_i_u_ branch May 24, 2026 13:21
Dunqing added a commit that referenced this pull request May 26, 2026
# Oxlint
### 🚀 Features

- 10da26b linter: `no-misleading-character-class` add suggestions for
regex literal (#22681) (Sysix)
- b84941e linter/vue: Implement no-expose-after-await rule (#22675)
(bab)
- 98b98c1 linter/vue: Implement no-computed-properties-in-data rule
(#22674) (bab)
- 868e2e8 linter: Add suggestion for `no-misleading-character-class`
(#22631) (Sysix)
- 2d4c919 oxlint: Support `vite-plus/resolveConfig` for vite.config.ts
(#22456) (leaysgur)
- 2a60012 linter/vue: Implement require-render-return rule (#22613)
(bab)
- 9f227fd linter/vue: Implement no-deprecated-props-default-this rule
(#21892) (bab)
- 9cd28b3 linter: Add debug option to print files to be linted (#22546)
(camchenry)
- 87f065e linter/vue: Implement return-in-emits-validator rule (#21935)
(bab)
- ea0380c linter/unicorn: Implement `import-style` rule (#22173) (Hao
Chen)
- dde40fe linter/vue: Implement no-watch-after-await rule (#22006) (bab)
- a735eb0 linter/vue: Implement valid-next-tick rule (#22531) (bab)
- 6dc615d linter/vue: Implement no-shared-component-data rule (#21842)
(bab)
- a656418 linter/vue: Implement valid-define-options rule (#22107) (bab)
- bb6f1b2 linter/vue: Implement require-slots-as-functions rule (#22244)
(bab)
- 5fa4774 linter/n: Implement `callback-return` rule (#22470) (Mikhail
Baev)

### 🐛 Bug Fixes

- 52bd016 linter: Respect allow unused disable directives in LSP
(#22715) (camc314)
- fa7c463 semantic: Correct TS enum member symbol spans (#22689)
(camc314)
- ed445ba linter: Respect flags overrides for `RegExp(/regex/i, "u")`
(#22678) (Sysix)
- 26b9396 semantic: Resolve parameter decorators outside parameter scope
(#22623) (camc314)
- 203952d linter: `no-misleading-character-class` fix
`is_unicode_code_point_escape` check (#22655) (Sysix)
- 2f64d3d linter: `no-misleading-character-class` own diagnostic for
surrogate pairs without u flag (#22654) (Sysix)
- 0c6ebc2 linter/eslint/no-lone-blocks: Do not flag empty loops (#22649)
(Mikhail Baev)
- 2a7562e linter/no-focused-tests: Mark fixer as a suggestion (#22645)
(camc314)
- dbe644f linter: Respect args none for unused rest parameters (#22627)
(camc314)
- d0211b0 linter: Allow undefined in DummyRuleMap index (#22626)
(camc314)
- 36fc0ec oxlint/lsp: "ignore this" actions merge with existing
directive (#22604) (Sysix)
- f7f370e linter/vitest/prefer-expect-type-of: Recommend `toBeTypeOf`
instead of `expectTypeOf` (#22612) (Mikhail Baev)
- 77063e5 linter/consistent-indexed-object-style: Preserve interface
modifiers in fixes (#22579) (camc314)
- 4f33aa7 linter: Treat `TSGlobalDeclaration` as ambient in
`has_ambient_typescript_ancestor` (#22577) (camc314)

### ⚡ Performance

- c22938d linter/no-async-endpoint-handlers: Populate node types
(#22601) (camc314)
- 607486e linter/no-negated-condition: Populate node types (#22602)
(camc314)
- 4dcaa59 linter/consistent-type-imports: Populate node types (#22600)
(camc314)
- 5bd3b25 linter/no-unused-vars: Avoid cloned ancestor iterator (#22598)
(camc314)
- 97fe9ba linter/no-extra-non-null-assertion: Reduce node matches
(#22588) (camc314)
- ae98296 linter/consistent-indexed-object-style: Populate node types
(#22578) (camc314)
# Oxfmt
### 🚀 Features

- 16b8058 oxfmt: Support `vite-plus/resolveConfig` for vite.config.ts
(#22454) (leaysgur)

### 🐛 Bug Fixes

- 5a26479 formatter: Preserve import phases (#22692) (Cameron)

### ⚡ Performance

- 78cf83f formatter: Pre-size output buffer using source text length
(#22594) (Dunqing)

Co-authored-by: Dunqing <[email protected]>
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.

linter: respect second flags of new RegExp(/ab/u, "i")

4 participants