Unverified Commit 9bbba98c authored by Steven's avatar Steven Committed by GitHub

Fix `next lint` no-document-import-in-page on Windows (#28745)

Fixes #28596 
parent 801e48ea
...@@ -16,7 +16,11 @@ module.exports = { ...@@ -16,7 +16,11 @@ module.exports = {
const paths = context.getFilename().split('pages') const paths = context.getFilename().split('pages')
const page = paths[paths.length - 1] const page = paths[paths.length - 1]
if (!page || page.startsWith('/_document')) { if (
!page ||
page.startsWith('/_document') ||
page.startsWith('\\_document')
) {
return return
} }
......
...@@ -28,6 +28,20 @@ ruleTester.run('no-document-import-in-page', rule, { ...@@ -28,6 +28,20 @@ ruleTester.run('no-document-import-in-page', rule, {
`, `,
filename: 'pages/_document.js', filename: 'pages/_document.js',
}, },
{
code: `import Document from "next/document"
export default class MyDocument extends Document {
render() {
return (
<Html>
</Html>
);
}
}
`,
filename: 'pages\\_document.js',
},
{ {
code: `import NextDocument from "next/document" code: `import NextDocument from "next/document"
...@@ -128,5 +142,19 @@ ruleTester.run('no-document-import-in-page', rule, { ...@@ -128,5 +142,19 @@ ruleTester.run('no-document-import-in-page', rule, {
}, },
], ],
}, },
{
code: `import Document from "next/document"
export const Test = () => <p>Test</p>
`,
filename: 'pages\\test.js',
errors: [
{
message:
'next/document should not be imported outside of pages/_document.js. See https://nextjs.org/docs/messages/no-document-import-in-page.',
type: 'ImportDeclaration',
},
],
},
], ],
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment