Unverified Commit 90eae2c0 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix crash of lint rule no-document-import-in-page (#28148)



Fixes #28030 
Fixes #28169

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
parent 53134269
......@@ -16,9 +16,11 @@ module.exports = {
}
const page = context.getFilename().split('pages')[1]
if (!page) {
return
}
const { name, dir } = path.parse(page)
if (
!page ||
name.startsWith('_document') ||
(dir === '/_document' && name === 'index')
) {
......
......@@ -86,6 +86,13 @@ ruleTester.run('no-document-import-in-page', rule, {
`,
filename: 'pages/_document/index.tsx',
},
{
code: `import Document from "next/document"
export const Test = () => <p>Test</p>
`,
filename: 'components/test.js',
},
],
invalid: [
{
......
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