Skip to content

Commit cf2edd9

Browse files
davidyorrljharb
authored andcommitted
Fix false positives in no-literals
This rule should only check strings. Fixes #1301
1 parent bca3c88 commit cf2edd9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/rules/jsx-no-literals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444

4545
function getValidation(node) {
4646
const standard = !/^[\s]+$/.test(node.value) &&
47+
typeof node.value === 'string' &&
4748
node.parent &&
4849
node.parent.type.indexOf('JSX') !== -1 &&
4950
node.parent.type !== 'JSXAttribute';

tests/lib/rules/jsx-no-literals.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ ruleTester.run('jsx-no-literals', rule, {
126126
`,
127127
parser: 'babel-eslint',
128128
options: [{noStrings: true}]
129+
}, {
130+
code: '<Foo bar={true} />',
131+
parser: 'babel-eslint',
132+
options: [{noStrings: true}]
133+
}, {
134+
code: '<Foo bar={false} />',
135+
parser: 'babel-eslint',
136+
options: [{noStrings: true}]
137+
}, {
138+
code: '<Foo bar={100} />',
139+
parser: 'babel-eslint',
140+
options: [{noStrings: true}]
129141
}, {
130142
code: `
131143
<Foo bar="test">
@@ -140,7 +152,17 @@ ruleTester.run('jsx-no-literals', rule, {
140152
</Foo>
141153
`,
142154
options: [{noStrings: true}]
155+
}, {
156+
code: '<Foo bar={true} />',
157+
options: [{noStrings: true}]
158+
}, {
159+
code: '<Foo bar={false} />',
160+
options: [{noStrings: true}]
161+
}, {
162+
code: '<Foo bar={100} />',
163+
options: [{noStrings: true}]
143164
}
165+
144166
],
145167

146168
invalid: [

0 commit comments

Comments
 (0)