Skip to content

Commit

Permalink
Fix no-server-import-in-page eslint rule for subfolder middleware (#3…
Browse files Browse the repository at this point in the history
…2139)

People have been reporting on #30973 that the `no-server-import-in-page` eslint rule is reporting false positives for `_middleware` files inside sub-page folders.

Unlike `_document`, we can have multiple `_middleware` files.

Fixes #32121
  • Loading branch information
thibautsabot committed Dec 5, 2021
1 parent 20814c3 commit 5b4e139
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -21,8 +21,8 @@ module.exports = {

if (
!page ||
page.startsWith(`${path.sep}_middleware`) ||
page.startsWith(`${path.posix.sep}_middleware`)
page.includes(`${path.sep}_middleware`) ||
page.includes(`${path.posix.sep}_middleware`)
) {
return
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/eslint-plugin-next/no-server-import-in-page.test.ts
Expand Up @@ -78,6 +78,15 @@ ruleTester.run('no-server-import-in-page', rule, {
`,
filename: 'pagesapp/src/pages/_middleware.js',
},
{
code: `import { NextFetchEvent, NextRequest } from "next/server"
export function middleware(req, ev) {
return new Response('Hello, world!')
}
`,
filename: 'src/pages/subFolder/_middleware.js',
},
],
invalid: [
{
Expand Down

0 comments on commit 5b4e139

Please sign in to comment.