Skip to content
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

[jsx curly brace presence]: fix jsx tags in braces #2422

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/rules/jsx-curly-brace-presence.js
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
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>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this arguably is a breaking change :-/ hopefully we can consider this a patch though.

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