forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-css-tags.js
46 lines (44 loc) · 1.07 KB
/
no-css-tags.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
const url = 'https://nextjs.org/docs/messages/no-css-tags'
module.exports = {
meta: {
docs: {
description: 'Prevent manual stylesheet tags.',
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'link') {
return
}
if (node.attributes.length === 0) {
return
}
const attributes = node.attributes.filter(
(attr) => attr.type === 'JSXAttribute'
)
if (
attributes.find(
(attr) =>
attr.name.name === 'rel' && attr.value.value === 'stylesheet'
) &&
attributes.find(
(attr) =>
attr.name.name === 'href' &&
attr.value.type === 'Literal' &&
!/^https?/.test(attr.value.value)
)
) {
context.report({
node,
message: `Do not include stylesheets manually. See: ${url}`,
})
}
},
}
},
}