Skip to content

Commit 6ea4972

Browse files
committed
Account for when there are more than one child
1 parent 1a0cac1 commit 6ea4972

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/rules/jsx-curly-brace-presence.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ module.exports = {
8888
);
8989
}
9090

91-
function shouldCheckForUnnecessaryCurly(expressionType, parentType, config) {
92-
if (expressionType !== 'Literal') {
91+
function shouldCheckForUnnecessaryCurly(expressionType, parent, config) {
92+
const {type: parentType} = parent;
93+
94+
if (
95+
expressionType !== 'Literal' || (
96+
parentType === 'JSXElement' &&
97+
parent.children.length !== 1
98+
)
99+
) {
93100
return false;
94101
}
95102

@@ -110,12 +117,9 @@ module.exports = {
110117

111118
return {
112119
JSXExpressionContainer: function(node) {
113-
const {
114-
expression: {type},
115-
parent: {type: parentType}
116-
} = node;
120+
const {expression: {type}, parent} = node;
117121

118-
if (shouldCheckForUnnecessaryCurly(type, parentType, userConfig)) {
122+
if (shouldCheckForUnnecessaryCurly(type, parent, userConfig)) {
119123
lintUnnecessaryCurly(node);
120124
}
121125
},

tests/lib/rules/jsx-curly-brace-presence.js

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
3636
{
3737
code: '<App>foo</App>'
3838
},
39+
{
40+
code: '<App>{"foo"}{<Component>bar</Component>}</App>'
41+
},
3942
{
4043
code: '<App prop=\'bar\'>foo</App>'
4144
},
@@ -59,6 +62,10 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
5962
code: '<MyComponent>foo</MyComponent>',
6063
options: [{children: 'never'}]
6164
},
65+
{
66+
code: '<MyComponent>{<App/>}{"123"}</MyComponent>',
67+
options: [{children: 'never'}]
68+
},
6269
{
6370
code: '<MyComponent prop={\'bar\'}>foo</MyComponent>',
6471
options: [{props: 'always'}]

0 commit comments

Comments
 (0)