Skip to content

Commit

Permalink
Fix false positives in no-literals
Browse files Browse the repository at this point in the history
This rule should only check strings.

Fixes jsx-eslint#1301
  • Loading branch information
davidyorr committed Jul 13, 2017
1 parent 739ece1 commit 92b6a1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ ruleTester.run('jsx-no-literals', rule, {
`,
parser: 'babel-eslint',
options: [{noStrings: true}]
}, {
code: '<Foo bar={true} />',
parser: 'babel-eslint',
options: [{noStrings: true}]
}, {
code: '<Foo bar={false} />',
parser: 'babel-eslint',
options: [{noStrings: true}]
}, {
code: '<Foo bar={100} />',
parser: 'babel-eslint',
options: [{noStrings: true}]
}, {
code: `
<Foo bar="test">
Expand All @@ -140,7 +152,17 @@ 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}]
}

],

invalid: [
Expand Down

0 comments on commit 92b6a1a

Please sign in to comment.