Skip to content

feat(linter): add suggestion for no-misleading-character-class#22631

Merged
graphite-app[bot] merged 1 commit into
mainfrom
05-20-feat_linter_add_suggestion_for_no-misleading-character-class_
May 21, 2026
Merged

feat(linter): add suggestion for no-misleading-character-class#22631
graphite-app[bot] merged 1 commit into
mainfrom
05-20-feat_linter_add_suggestion_for_no-misleading-character-class_

Conversation

@Sysix

@Sysix Sysix commented May 20, 2026

Copy link
Copy Markdown
Member

Pull request overview

Adds an auto-fix suggestion capability to the eslint/no-misleading-character-class rule (focused on surrogate pairs without a Unicode-mode flag) and refactors regex-utility helpers to expose pattern/flags spans for reuse.

Changes:

* Exposes regex constructor argument span helpers (`RegexFlagsParseResult`, `get_regex_flags_span`, `get_regex_pattern_span`) for rule-level fixers.

* Updates `no-misleading-character-class` to emit a suggestion to add a Unicode flag (`u`) for `RegExp(...)` / `new RegExp(...)` cases (while intentionally skipping regex literals).

* Expands/adjusts fixer test cases to cover constructor calls.

Sysix commented May 20, 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.

@codspeed-hq

codspeed-hq Bot commented May 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 55 skipped benchmarks1


Comparing 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ (43342ed) with 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check (24a35a8)

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.

@camc314 camc314 self-assigned this May 21, 2026
@graphite-app graphite-app Bot changed the base branch from 05-19-refactor_linter_add_helper_function_get_regex_flag_span_ to graphite-base/22631 May 21, 2026 11:58
@graphite-app graphite-app Bot force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from e2d8d7c to 721289e Compare May 21, 2026 12:01
@graphite-app graphite-app Bot force-pushed the graphite-base/22631 branch from 532c94d to 4f58992 Compare May 21, 2026 12:01
@graphite-app graphite-app Bot changed the base branch from graphite-base/22631 to main May 21, 2026 12:02
@graphite-app graphite-app Bot force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 721289e to 7e80386 Compare May 21, 2026 12:02
@Sysix Sysix changed the base branch from main to graphite-base/22631 May 21, 2026 17:36
@Sysix Sysix force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 7e80386 to 127a6bc Compare May 21, 2026 17:36
@Sysix Sysix force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 127a6bc to 86b405c Compare May 21, 2026 19:29
@Sysix Sysix changed the base branch from graphite-base/22631 to 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check May 21, 2026 19:29
@Sysix Sysix force-pushed the 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check branch from 09a70c5 to 75c660f Compare May 21, 2026 19:53
@Sysix Sysix force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch 2 times, most recently from 74d63ff to 48e7221 Compare May 21, 2026 19:58
@Sysix Sysix force-pushed the 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check branch from 75c660f to a31a88a Compare May 21, 2026 19:58
@Sysix Sysix force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 48e7221 to 55ea218 Compare May 21, 2026 20:06
@Sysix Sysix force-pushed the 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check branch from a31a88a to 24a35a8 Compare May 21, 2026 20:06
@Sysix Sysix requested a review from Copilot May 21, 2026 20:09

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

Adds an auto-fix suggestion capability to the eslint/no-misleading-character-class rule (focused on surrogate pairs without a Unicode-mode flag) and refactors regex-utility helpers to expose pattern/flags spans for reuse.

Changes:

  • Exposes regex constructor argument span helpers (RegexFlagsParseResult, get_regex_flags_span, get_regex_pattern_span) for rule-level fixers.
  • Updates no-misleading-character-class to emit a suggestion to add a Unicode flag (u) for RegExp(...) / new RegExp(...) cases (while intentionally skipping regex literals).
  • Expands/adjusts fixer test cases to cover constructor calls.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_linter/src/utils/regex.rs Makes regex-argument span parsing utilities public and factors out pattern-span extraction.
crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs Adds a suggestion fixer to append/extend flags with u for RegExp constructor usage; updates rule category and tests.
Comments suppressed due to low confidence (3)

crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs:491

  • When there is no flags argument, the fixer inserts , "u" after pattern_span (the inner string/template literal span). If the first RegExp argument is parenthesized (e.g. new RegExp(("[🇯🇵]"))), inserting at the inner literal produces a SequenceExpression inside the parentheses (e.g. ("[🇯🇵]", "u")), which changes the argument value to "u" and breaks the fix’s intent.

To avoid changing semantics, the insertion point needs to be the full first-argument expression span (including parentheses), while still using the inner literal span for ConstructorParser validation.

    } else {
        fixer.insert_text_after(&pattern_span, r#", "u""#)
    }

crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs:856

  • These expected fix outputs place , "u" inside the parenthesized first argument (e.g. RegExp(("…", "u"))), which changes the first argument into a SequenceExpression and makes the pattern argument evaluate to "u". The expected fixes should add the flags as a second argument to RegExp, outside any parentheses that belong to the first argument expression.
        (r#"var r = new RegExp(("[🇯🇵]"))"#, r#"var r = new RegExp(("[🇯🇵]", "u"))"#, None),
        (r#"var r = new RegExp((("[🇯🇵]")))"#, r#"var r = new RegExp((("[🇯🇵]", "u")))"#, None),
        (r#"var r = new RegExp(("[🇯🇵]"),)"#, r#"var r = new RegExp(("[🇯🇵]", "u"),)"#, None),

crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs:891

  • In a template literal, \👍 is an identity escape, so the resulting string value does not contain a literal backslash (it evaluates to 👍). If the intention is to test a pattern that actually contains a backslash before the emoji (and to align with the preceding string-literal case that expects no fix because the regex would be invalid), the source should use \\👍 inside the template.

As written, this case is effectively just [👍] and doesn’t test the “Backslash + …” scenario described in the comment.

        (
            r"RegExp(`[\👍]`)",
            r#"RegExp(`[\👍]`, "u")"#,
            Some(serde_json::json!([{ "allowEscape": true }])),
        ),

Comment thread crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs
@Sysix Sysix marked this pull request as ready for review May 21, 2026 20:25
@Sysix Sysix requested a review from camc314 as a code owner May 21, 2026 20:25
@Sysix Sysix marked this pull request as draft May 21, 2026 20:25
@Sysix Sysix force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 55ea218 to 43342ed Compare May 21, 2026 20:39
@Sysix Sysix added the C-enhancement Category - New feature or request label May 21, 2026
@Sysix Sysix marked this pull request as ready for review May 21, 2026 20:55
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 21, 2026

camc314 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Merge activity

)

> ## Pull request overview
>
> Adds an auto-fix _suggestion_ capability to the `eslint/no-misleading-character-class` rule (focused on surrogate pairs without a Unicode-mode flag) and refactors regex-utility helpers to expose pattern/flags spans for reuse.
>
> **Changes:**
>
>     * Exposes regex constructor argument span helpers (`RegexFlagsParseResult`, `get_regex_flags_span`, `get_regex_pattern_span`) for rule-level fixers.
>
>     * Updates `no-misleading-character-class` to emit a suggestion to add a Unicode flag (`u`) for `RegExp(...)` / `new RegExp(...)` cases (while intentionally skipping regex literals).
>
>     * Expands/adjusts fixer test cases to cover constructor calls.
>
@graphite-app graphite-app Bot force-pushed the 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check branch from 24a35a8 to 203952d Compare May 21, 2026 21:14
@graphite-app graphite-app Bot force-pushed the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch from 43342ed to 868e2e8 Compare May 21, 2026 21:15
Base automatically changed from 05-21-fix_linter_no-misleading-character-class_fix_is_unicode_code_point_escape_check to main May 21, 2026 21:18
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 21, 2026
@graphite-app graphite-app Bot merged commit 868e2e8 into main May 21, 2026
31 checks passed
@graphite-app graphite-app Bot deleted the 05-20-feat_linter_add_suggestion_for_no-misleading-character-class_ branch May 21, 2026 21:19
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 C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants