a28e775e88
## Feature - [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. [Feature Request](https://github.com/vercel/next.js/discussions/26365) - [x] Eslint unit ests added - [x] Errors have helpful link attached, see `contributing.md` Let me know if this looks good or something needs to be changed. I still need to add the error links and improve the eslint error messages. I don't know if the CI runs the ESLint tests, but current all pass locally
29 lines
730 B
JavaScript
29 lines
730 B
JavaScript
const path = require('path')
|
|
|
|
module.exports = {
|
|
meta: {
|
|
docs: {
|
|
description: 'Disallow importing next/script inside pages/_document.js',
|
|
recommended: true,
|
|
},
|
|
},
|
|
create: function (context) {
|
|
return {
|
|
ImportDeclaration(node) {
|
|
if (node.source.value !== 'next/script') {
|
|
return
|
|
}
|
|
|
|
const document = context.getFilename().split('pages')[1]
|
|
if (!document || !path.parse(document).name.startsWith('_document')) {
|
|
return
|
|
}
|
|
|
|
context.report({
|
|
node,
|
|
message: `next/script should not be used in pages/_document.js. See: https://nextjs.org/docs/messages/no-script-in-document-page `,
|
|
})
|
|
},
|
|
}
|
|
},
|
|
}
|