Skip to content

Commit

Permalink
Move a function to jsxUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Sep 7, 2019
1 parent ffe97ce commit 973b027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/rules/jsx-no-useless-fragment.js
Expand Up @@ -60,12 +60,7 @@ function trimLikeReact(text) {
function isKeyedElement(node) {
return node.type === 'JSXElement' &&
node.openingElement.attributes &&
node.openingElement.attributes.some(attribute => (
attribute.type === 'JSXAttribute' &&
attribute.name &&
attribute.name.type === 'JSXIdentifier' &&
attribute.name.name === 'key'
));
node.openingElement.attributes.some(jsxUtil.isJSXAttributeKey);
}

module.exports = {
Expand Down
14 changes: 13 additions & 1 deletion lib/util/jsx.js
Expand Up @@ -64,8 +64,20 @@ function isJSX(node) {
return node && ['JSXElement', 'JSXFragment'].indexOf(node.type) >= 0;
}

/**
* Check if node is like `key={...}` as in `<Foo key={...} />`
* @param {ASTNode} node
*/
function isJSXAttributeKey(node) {
return node.type === 'JSXAttribute' &&
node.name &&
node.name.type === 'JSXIdentifier' &&
node.name.name === 'key';
}

module.exports = {
isDOMComponent,
isFragment,
isJSX
isJSX,
isJSXAttributeKey
};

0 comments on commit 973b027

Please sign in to comment.