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:
parent
531342691d
commit
90eae2c00f
2 changed files with 10 additions and 1 deletions
|
@ -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: [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue