Skip to content

Commit

Permalink
Fix crash of lint rule no-document-import-in-page (#28148)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
huozhi committed Aug 16, 2021
1 parent 5313426 commit 90eae2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -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')
) {
Expand Down
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 90eae2c

Please sign in to comment.