Skip to content

Commit

Permalink
fix(vercel#34030): ignore non-checkable jsx spread attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Feb 17, 2022
1 parent ba78437 commit 5be9cb4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/eslint-plugin-next/lib/rules/inline-script-id.js
Expand Up @@ -28,16 +28,30 @@ module.exports = {
}

const attributeNames = new Set()

let hasNonCheckableSpreadAttribute = false
node.openingElement.attributes.forEach((attribute) => {
// Early return if we already have a non-checkable spread attribute, for better performance
if (hasNonCheckableSpreadAttribute) return

if (attribute.type === 'JSXAttribute') {
attributeNames.add(attribute.name.name)
} else if (attribute.type === 'JSXSpreadAttribute') {
attribute.argument.properties.forEach((property) => {
attributeNames.add(property.key.name)
})
if (attribute.argument?.properties) {
attribute.argument.properties.forEach((property) => {
attributeNames.add(property.key.name)
})
} else {
// JSXSpreadAttribute without properties is not checkable
hasNonCheckableSpreadAttribute = true
}
}
})

// https://github.com/vercel/next.js/issues/34030
// If there is a non-checkable spread attribute, we simply ignore them
if (hasNonCheckableSpreadAttribute) return

if (
node.children.length > 0 ||
attributeNames.has('dangerouslySetInnerHTML')
Expand Down

0 comments on commit 5be9cb4

Please sign in to comment.