-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Description
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.0Which 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