Repository: yannickcr/eslint-plugin-react (js)

Issue:
no-literals: only check strings
should the no-literals rule check if the `node.value` is a string? with the new `{ "noStrings": true }` option (https://github.com/yannickcr/eslint-plugin-react/pull/1202) I'm getting errors for explicitly set boolean and number props `booleanprop={true}` `numberprop={100}`

Pull request description:
Fix false positives in no-literals
This rule should only check strings.

Fixes #1301

Patch:
diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js
index 8b170543..797f5fc5 100644
--- a/lib/rules/jsx-no-literals.js
+++ b/lib/rules/jsx-no-literals.js
@@ -44,6 +44,7 @@ module.exports = {
 
     function getValidation(node) {
       const standard = !/^[\s]+$/.test(node.value) &&
+          typeof node.value === 'string' &&
           node.parent &&
           node.parent.type.indexOf('JSX') !== -1 &&
           node.parent.type !== 'JSXAttribute';
@@ -63,6 +64,12 @@ module.exports = {
         if (getValidation(node)) {
           reportLiteralNode(node);
         }
+      },
+
+      TemplateLiteral: function(node) {
+        if (isNoStrings && node.parent.type === 'JSXExpressionContainer') {
+          reportLiteralNode(node);
+        }
       }
 
     };


Test patch:
diff --git a/tests/lib/rules/jsx-no-literals.js b/tests/lib/rules/jsx-no-literals.js
index d506d877..78fdf65c 100644
--- a/tests/lib/rules/jsx-no-literals.js
+++ b/tests/lib/rules/jsx-no-literals.js
@@ -140,7 +140,43 @@ ruleTester.run('jsx-no-literals', rule, {
         </Foo>
       `,
       options: [{noStrings: true}]
+    }, {
+      code: '<Foo bar={true} />',
+      options: [{noStrings: true}]
+    }, {
+      code: '<Foo bar={false} />',
+      options: [{noStrings: true}]
+    }, {
+      code: '<Foo bar={100} />',
+      options: [{noStrings: true}]
+    }, {
+      code: '<Foo bar={null} />',
+      options: [{noStrings: true}]
+    }, {
+      code: '<Foo bar={{}} />',
+      options: [{noStrings: true}]
+    }, {
+      code: [
+        'class Comp1 extends Component {',
+        '  asdf() {}',
+        '  render() {',
+        '    return <Foo bar={this.asdf} />;',
+        '  }',
+        '}'
+      ].join('\n'),
+      options: [{noStrings: true}]
+    }, {
+      code: [
+        'class Comp1 extends Component {',
+        '  render() {',
+        '    let foo = `bar`;',
+        '    return <div />;',
+        '  }',
+        '}'
+      ].join('\n'),
+      options: [{noStrings: true}]
     }
+
   ],
 
   invalid: [
@@ -267,6 +303,18 @@ ruleTester.run('jsx-no-literals', rule, {
       `,
       options: [{noStrings: true}],
       errors: [{message: 'Strings not allowed in JSX files'}]
+    }, {
+      code: [
+        '<Foo>',
+        '  {`Test`}',
+        '</Foo>'
+      ].join('\n'),
+      options: [{noStrings: true}],
+      errors: [{message: 'Strings not allowed in JSX files'}]
+    }, {
+      code: '<Foo bar={`Test`} />',
+      options: [{noStrings: true}],
+      errors: [{message: 'Strings not allowed in JSX files'}]
     }
   ]
 });