Skip to content

Commit 973b027

Browse files
committed
Move a function to jsxUtils
1 parent ffe97ce commit 973b027

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/rules/jsx-no-useless-fragment.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ function trimLikeReact(text) {
6060
function isKeyedElement(node) {
6161
return node.type === 'JSXElement' &&
6262
node.openingElement.attributes &&
63-
node.openingElement.attributes.some(attribute => (
64-
attribute.type === 'JSXAttribute' &&
65-
attribute.name &&
66-
attribute.name.type === 'JSXIdentifier' &&
67-
attribute.name.name === 'key'
68-
));
63+
node.openingElement.attributes.some(jsxUtil.isJSXAttributeKey);
6964
}
7065

7166
module.exports = {

lib/util/jsx.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,20 @@ function isJSX(node) {
6464
return node && ['JSXElement', 'JSXFragment'].indexOf(node.type) >= 0;
6565
}
6666

67+
/**
68+
* Check if node is like `key={...}` as in `<Foo key={...} />`
69+
* @param {ASTNode} node
70+
*/
71+
function isJSXAttributeKey(node) {
72+
return node.type === 'JSXAttribute' &&
73+
node.name &&
74+
node.name.type === 'JSXIdentifier' &&
75+
node.name.name === 'key';
76+
}
77+
6778
module.exports = {
6879
isDOMComponent,
6980
isFragment,
70-
isJSX
81+
isJSX,
82+
isJSXAttributeKey
7183
};

0 commit comments

Comments
 (0)