rsnext/packages/eslint-plugin-next/lib/rules/no-sync-scripts.js

29 lines
732 B
JavaScript
Raw Normal View History

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