这是indexloc提供的服务,不要输入任何密码
Skip to content

config.matcher in Proxy/Middleware broken when auto-fixed to String.raw by linters #86125

@LangRizkie

Description

@LangRizkie

Link to the code that reproduces this issue

https://github.com/LangRizkie/next-boilerplate-test

To Reproduce

Next.js middleware’s config.matcher expects regular strings. However, static analysis tools such as SonarQube and Oxc sometimes auto-fix these strings to use String.raw. This transformation breaks regex patterns in the matcher, leading to unexpected routing behavior.

example:
export const config = { matcher: ['/((?!api|_next|favicon\\.ico|.*\\.[\\w]+$).*)'] }
auto-fixed to:
export const config = { matcher: [String.raw/((?!api|_next|favicon.ico|..[\w]+$).)] }

This conversion changes the value type and causes the middleware matcher to fail, especially for complex regex patterns. For the quick fix I'm disable the rule but does it really work that way?

Current vs. Expected behavior

Expected Behavior

config.matcher should fully support String.raw without modification by auto-fix tools, preserving the intended regex semantics.

Provide environment information

next: 16.0.1
eslint: ^9.39.0
eslint-plugin-sonarjs: ^3.0.5
eslint-plugin-unicorn: ^62.0.0

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    RuntimeRelated to Node.js or Edge Runtime with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions