forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-styled-jsx-in-document.js
47 lines (43 loc) · 1.08 KB
/
no-styled-jsx-in-document.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const path = require('path')
const url = 'https://nextjs.org/docs/messages/no-styled-jsx-in-document'
module.exports = {
meta: {
docs: {
description: 'Prevent usage of `styled-jsx` in `pages/_document.js`.',
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
JSXOpeningElement(node) {
const document = context.getFilename().split('pages')[1]
if (!document) {
return
}
const { name, dir } = path.parse(document)
if (
!(
name.startsWith('_document') ||
(dir === '/_document' && name === 'index')
)
) {
return
}
if (
node.name.name === 'style' &&
node.attributes.find(
(attr) => attr.type === 'JSXAttribute' && attr.name.name === 'jsx'
)
) {
context.report({
node,
message: `\`styled-jsx\` should not be used in \`pages/_document.js\`. See: ${url}`,
})
}
},
}
},
}