Skip to content

Commit

Permalink
fix: recognize react JSXFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardchen committed Sep 2, 2020
1 parent 10e3a47 commit 719f496
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ module.exports = {
scriptVisitor.JSXText(node);
},

'JSXFragment > Literal'(node) {
scriptVisitor.JSXText(node);
},

JSXAttribute(node) {
const attrName = node.name.name;

Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-literal-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ ruleTester.run('no-literal-string', rule, {
// JSX
{ code: '<div>foo</div>', errors },
{ code: '<div>foo</div>', options: [{ markupOnly: true }], errors },
{ code: '<>foo999</>', options: [{ markupOnly: true }], errors },
{ code: '<div>FOO</div>', errors },
{
code: '<div>{"hello world"}</div>',
Expand Down Expand Up @@ -242,6 +243,12 @@ tsTester.run('no-literal-string', rule, {
{ code: "type T ={t?:'name'|'abc'};function Button({t='name'}:T){}" },
],
invalid: [
{
code: '<>foo999</>',
filename: 'a.tsx',
options: [{ markupOnly: true }],
errors,
},
{
code: `<button className={styles.btn}>loading</button>`,
filename: 'a.tsx',
Expand Down

0 comments on commit 719f496

Please sign in to comment.