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`
This commit is contained in:
Jiachi Liu 2021-08-17 00:04:42 +08:00 committed by GitHub
parent 531342691d
commit 90eae2c00f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -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')
) {

View file

@ -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: [
{