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
[New]jsx-key
: add check for unique key
#2701
Conversation
### `checkUniquePropKey` (default: `true`) | ||
|
||
When `false` the validation for unique `key` in array literal and sibling JSX elements is disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid a breaking change, this also needs to default to false, just like checkFragmentShorthand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i can see an argument for it not being enabled by default, but i don't think it's worth the risk)
const reactPragma = pragmaUtil.getFromContext(context); | ||
const fragmentPragma = pragmaUtil.getFragmentFromContext(context); | ||
const processedNodes = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const processedNodes = new Set(); | |
const processedNodes = new WeakSet(); |
if (hasProp(node.openingElement.attributes, 'key')) { | ||
return; | ||
} | ||
function nodeProcessed(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reads like it's a predicate, but it also has the side effect of marking the node as processed. maybe it needs a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. 🤔 What do you think about checkAndMarkNodeProcessed
? I am not crazy about this one but at least express better the behavior.
a1538c7
to
6cc9a00
Compare
jsx-key
: add check for unique key
Please mark this PR as ready for review once it is ready. |
Add
key
uniqueness check in array literal and sibling JSX elements.Closes #2614