Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#34030): ignore non-checkable jsx spread attribute #34473

Merged
merged 6 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
ijjk marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 11 additions & 0 deletions test/unit/eslint-plugin-next/inline-script-id.test.ts
Expand Up @@ -98,6 +98,17 @@ ruleTester.run('inline-script-id', rule, {
)
}`,
},
{
code: `import Script from 'next/script';
const spread = { strategy: "lazyOnload" }
export default function TestPage() {
return (
<Script {...spread} id={"test-script"}>
{\`console.log('Hello world');\`}
</Script>
)
}`,
},
],
invalid: [
{
Expand Down