Skip to content

Commit

Permalink
[Fix] jsx-curly-brace-presence: ignore containers with comments
Browse files Browse the repository at this point in the history
Fixes #2885
  • Loading branch information
golopot committed Jan 13, 2021
1 parent f34ee91 commit f0e29f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/jsx-curly-brace-presence.md
Expand Up @@ -151,6 +151,7 @@ Examples of **correct** code for this rule, even when configured with `"never"`:
*/
<App>{' '}</App>
<App>{' '}</App>
<App>{/* comment */ <Bpp />}</App> // the comment makes the container necessary
```

## When Not To Use It
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -235,6 +235,11 @@ module.exports = {
const expression = JSXExpressionNode.expression;
const expressionType = expression.type;

// Curly braces containing comments are necessary
if (context.getSourceCode().getCommentsInside(JSXExpressionNode).length > 0) {
return;
}

if (
(expressionType === 'Literal' || expressionType === 'JSXText')
&& typeof expression.value === 'string'
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -417,6 +417,28 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
};
`,
options: [{props: 'never', children: 'never'}]
},
{
code: `<App>{/* comment */}</App>`
},
{
code: `<App>{/* comment */ <Foo />}</App>`
},
{
code: `<App>{/* comment */ 'foo'}</App>`
},
{
code: `<App prop={/* comment */ 'foo'} />`
},
{
code: `
<App>
{
// comment
<Foo />
}
</App>
`
}
],

Expand Down

0 comments on commit f0e29f9

Please sign in to comment.