2020-05-18 21:24:37 +02:00
|
|
|
module.exports = function (context) {
|
2020-05-07 07:36:01 +02:00
|
|
|
return {
|
|
|
|
JSXOpeningElement(node) {
|
|
|
|
if (node.name.name !== 'script') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (node.attributes.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
2020-05-29 00:11:29 +02:00
|
|
|
const attributeNames = node.attributes
|
|
|
|
.filter((attr) => attr.type === 'JSXAttribute')
|
|
|
|
.map((attr) => attr.name.name)
|
2020-05-07 07:36:01 +02:00
|
|
|
if (
|
2020-05-29 00:11:29 +02:00
|
|
|
attributeNames.includes('src') &&
|
|
|
|
!attributeNames.includes('async') &&
|
|
|
|
!attributeNames.includes('defer')
|
2020-05-07 07:36:01 +02:00
|
|
|
) {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
message:
|
2021-06-03 14:01:24 +02:00
|
|
|
'External synchronous scripts are forbidden. See: https://nextjs.org/docs/messages/no-sync-scripts.',
|
2020-05-07 07:36:01 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.schema = []
|