diff --git a/lib/rules/jsx-curly-brace-presence.js b/lib/rules/jsx-curly-brace-presence.js
index f3c3f7e25d..0da2074b0d 100755
--- a/lib/rules/jsx-curly-brace-presence.js
+++ b/lib/rules/jsx-curly-brace-presence.js
@@ -100,11 +100,11 @@ module.exports = {
return rawStringValue.replace(/\\/g, '\\\\');
}
- function needToEscapeCharacterForJSX(raw) {
+ function needToEscapeCharacterForJSX(raw, node) {
return (
containsBackslash(raw)
|| containsHTMLEntity(raw)
- || containsDisallowedJSXTextChars(raw)
+ || (node.parent.type !== 'JSXAttribute' && containsDisallowedJSXTextChars(raw))
);
}
@@ -238,7 +238,7 @@ module.exports = {
(JSXExpressionNode.parent.type === 'JSXAttribute' && !isWhiteSpaceLiteral(expression))
|| !isLiteralWithTrailingWhiteSpaces(expression)
)
- && !needToEscapeCharacterForJSX(expression.raw) && (
+ && !needToEscapeCharacterForJSX(expression.raw, JSXExpressionNode) && (
jsxUtil.isJSX(JSXExpressionNode.parent)
|| !containsQuoteCharacters(expression.value)
)
@@ -249,7 +249,7 @@ module.exports = {
&& expression.expressions.length === 0
&& expression.quasis[0].value.raw.indexOf('\n') === -1
&& !isStringWithTrailingWhiteSpaces(expression.quasis[0].value.raw)
- && !needToEscapeCharacterForJSX(expression.quasis[0].value.raw) && (
+ && !needToEscapeCharacterForJSX(expression.quasis[0].value.raw, JSXExpressionNode) && (
jsxUtil.isJSX(JSXExpressionNode.parent)
|| !containsQuoteCharacters(expression.quasis[0].value.cooked)
)
diff --git a/tests/lib/rules/jsx-curly-brace-presence.js b/tests/lib/rules/jsx-curly-brace-presence.js
index 6d9772fb0c..74e4dba85c 100755
--- a/tests/lib/rules/jsx-curly-brace-presence.js
+++ b/tests/lib/rules/jsx-curly-brace-presence.js
@@ -244,14 +244,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
code: '{""}',
options: ['never']
},
- {
- code: 'bar',
- options: ['never']
- },
- {
- code: '"}>foo',
- options: ['never']
- },
{
code: 'bar',
options: ['never']
@@ -800,6 +792,40 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
{message: missingCurlyMessage}
],
options: [{children: 'always'}]
+ },
+ {
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [
+ {message: unnecessaryCurlyMessage}
+ ],
+ options: [{props: 'never'}]
+ },
+ {
+ code: `
+
+ `,
+ output: `
+
+ `,
+ errors: [{message: unnecessaryCurlyMessage}],
+ options: ['never']
+ },
+ {
+ code: 'bar',
+ output: 'bar',
+ errors: [{message: unnecessaryCurlyMessage}],
+ options: ['never']
+ },
+ {
+ code: '"}>foo',
+ output: 'foo',
+ errors: [{message: unnecessaryCurlyMessage}],
+ options: ['never']
}
]
});