Skip to content

Commit

Permalink
[jsx curly brace presence]: fix jsx tags in braces
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoyopenroot committed Sep 28, 2019
1 parent 4a05fa2 commit fd09319
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ module.exports = {
expression.quasis[0].value.raw :
expression.raw.substring(1, expression.raw.length - 1)
}"`;
} else if (jsxUtil.isJSX(expression)) {
const sourceCode = context.getSourceCode();

textToReplace = sourceCode.getText(expression);
} else {
textToReplace = expressionType === 'TemplateLiteral' ?
expression.quasis[0].value.cooked : expression.value;
Expand Down Expand Up @@ -190,6 +194,8 @@ module.exports = {
)
) {
reportUnnecessaryCurly(JSXExpressionNode);
} else if (jsxUtil.isJSX(expression)) {
reportUnnecessaryCurly(JSXExpressionNode);
}
}

Expand Down
14 changes: 13 additions & 1 deletion tests/lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
options: [{props: 'never'}]
},
{
code: '<App>{<myApp></myApp>}</App>'
code: '<App>{<myApp></myApp>}</App>',
options: [{children: 'always'}]
},
{
code: '<App>{[]}</App>'
Expand Down Expand Up @@ -313,6 +314,17 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
options: [{props: 'never'}],
errors: [{message: unnecessaryCurlyMessage}]
},
{
code: '<App>{<myApp></myApp>}</App>',
output: '<App><myApp></myApp></App>',
options: [{children: 'never'}],
errors: [{message: unnecessaryCurlyMessage}]
},
{
code: '<App>{<myApp></myApp>}</App>',
output: '<App><myApp></myApp></App>',
errors: [{message: unnecessaryCurlyMessage}]
},
{
code: '<App prop={`foo`}>foo</App>',
output: '<App prop="foo">foo</App>',
Expand Down

0 comments on commit fd09319

Please sign in to comment.