Skip to content

Commit f5d00c0

Browse files
committed
update the option to be part of an object
1 parent cc503b3 commit f5d00c0

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

docs/rules/jsx-no-literals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ var Hello = <div>{'test'}</div>;
2323

2424
There is only one option:
2525

26-
* `no-strings` - Enforces no string literals used as children, wrapped or unwrapped.
26+
* `noStrings` - Enforces no string literals used as children, wrapped or unwrapped.
2727

2828
To use, you can specify like the following:
2929

3030
```json
31-
"react/jsx-no-literals": ["no-strings"]
31+
"react/jsx-no-literals": [{"noStrings": false}]
3232
```
3333

3434
In this configuration, the following are considered warnings:

lib/rules/jsx-no-literals.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// Rule Definition
1010
// ------------------------------------------------------------------------------
1111

12-
var NO_STRINGS = 'no-strings';
13-
1412
module.exports = {
1513
meta: {
1614
docs: {
@@ -20,17 +18,18 @@ module.exports = {
2018
},
2119

2220
schema: [{
23-
enum: [NO_STRINGS]
24-
}, {
2521
type: 'object',
26-
properties: {},
22+
properties: {
23+
noStrings: {
24+
type: 'boolean'
25+
}
26+
},
2727
additionalProperties: false
2828
}]
2929
},
3030

3131
create: function(context) {
32-
33-
const isNoStrings = context.options[0] === NO_STRINGS;
32+
const isNoStrings = context.options[0] ? context.options[0].noStrings : false;
3433

3534
const message = isNoStrings ?
3635
'Strings not allowed in JSX files' :

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,29 @@ ruleTester.run('jsx-no-literals', rule, {
117117
</Foo>
118118
`,
119119
parser: 'babel-eslint',
120-
options: ['no-strings']
120+
options: [{noStrings: true}]
121121
}, {
122122
code: `
123123
<Foo bar="test">
124124
{translate('my.translate.key')}
125125
</Foo>
126126
`,
127127
parser: 'babel-eslint',
128-
options: ['no-strings']
128+
options: [{noStrings: true}]
129129
}, {
130130
code: `
131131
<Foo bar="test">
132132
{intl.formatText(message)}
133133
</Foo>
134134
`,
135-
options: ['no-strings']
135+
options: [{noStrings: true}]
136136
}, {
137137
code: `
138138
<Foo bar="test">
139139
{translate('my.translate.key')}
140140
</Foo>
141141
`,
142-
options: ['no-strings']
142+
options: [{noStrings: true}]
143143
}
144144
],
145145

@@ -240,15 +240,15 @@ ruleTester.run('jsx-no-literals', rule, {
240240
</Foo>
241241
`,
242242
parser: 'babel-eslint',
243-
options: ['no-strings'],
243+
options: [{noStrings: true}],
244244
errors: [{message: 'Strings not allowed in JSX files'}]
245245
}, {
246246
code: `
247247
<Foo bar="test">
248248
{'Test'}
249249
</Foo>
250250
`,
251-
options: ['no-strings'],
251+
options: [{noStrings: true}],
252252
errors: [{message: 'Strings not allowed in JSX files'}]
253253
}, {
254254
code: `
@@ -257,15 +257,15 @@ ruleTester.run('jsx-no-literals', rule, {
257257
</Foo>
258258
`,
259259
parser: 'babel-eslint',
260-
options: ['no-strings'],
260+
options: [{noStrings: true}],
261261
errors: [{message: 'Strings not allowed in JSX files'}]
262262
}, {
263263
code: `
264264
<Foo bar="test">
265265
Test
266266
</Foo>
267267
`,
268-
options: ['no-strings'],
268+
options: [{noStrings: true}],
269269
errors: [{message: 'Strings not allowed in JSX files'}]
270270
}
271271
]

0 commit comments

Comments
 (0)