Skip to content

Commit b21b741

Browse files
committed
Merge pull request #82 from dominicbarnes/jsx-pragma-config
Add support for setting the jsx pragma value in eslintrc (fixes #80)
2 parents 598ab38 + 82b7063 commit b21b741

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docs/rules/jsx-uses-react.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ If you are using the @jsx pragma this rule will mark the designated variable and
77

88
This rule has no effect if the `no-unused-vars` rule is not enabled.
99

10+
1011
## Rule Details
1112

1213
The following patterns are considered warnings:
@@ -39,6 +40,27 @@ var Foo = require('foo');
3940
var Hello = <div>Hello {this.props.name}</div>;
4041
```
4142

43+
44+
## Rule Options
45+
46+
```js
47+
...
48+
"jsx-uses-react": [<enabled>, { "pragma": <string> }]
49+
...
50+
```
51+
52+
### `pragma`
53+
54+
As an alternative to specifying the above pragma in each source file, you can specify
55+
this configuration option:
56+
57+
```js
58+
var Foo = require('Foo');
59+
60+
var Hello = <div>Hello {this.props.name}</div>;
61+
```
62+
63+
4264
## When Not To Use It
4365

4466
If you are not using JSX, if React is declared as global variable or if you do not use the `no-unused-vars` rule then you can disable this rule.

lib/rules/jsx-uses-react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
1414

1515
module.exports = function(context) {
1616

17-
var id = 'React';
17+
var config = context.options[0] || {};
18+
var id = config.pragma || 'React';
1819

1920
// --------------------------------------------------------------------------
2021
// Public

tests/lib/rules/jsx-uses-react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ eslintTester.addRuleTest('node_modules/eslint/lib/rules/no-unused-vars', {
2222
valid: [
2323
{code: '/*eslint jsx-uses-react:1*/ var React; <div />;', ecmaFeatures: {jsx: true}},
2424
{code: '/*eslint jsx-uses-react:1*/ var React; (function () { <div /> })();', ecmaFeatures: {jsx: true}},
25-
{code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var Foo; <div />;', ecmaFeatures: {jsx: true}}
25+
{code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var Foo; <div />;', ecmaFeatures: {jsx: true}},
26+
{code: '/*eslint jsx-uses-react:[1,{"pragma":"Foo"}]*/ var Foo; <div />;', ecmaFeatures: {jsx: true}}
2627
],
2728
invalid: [
2829
{code: '/*eslint jsx-uses-react:1*/ var React;',

0 commit comments

Comments
 (0)