Skip to content

Commit

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

People have been reporting on vercel#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 vercel#32121
  • Loading branch information
thibautsabot authored and natew committed Feb 16, 2022
1 parent e137494 commit 5d292fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 5d292fa

Please sign in to comment.