Skip to content

Commit

Permalink
adding support for setting the jsx pragma value via config
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicbarnes committed May 26, 2015
1 parent 598ab38 commit 4822162
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/rules/jsx-uses-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ var Foo = require('foo');
var Hello = <div>Hello {this.props.name}</div>;
```

As an alternative to specifying the above pragma in each source file, you can include an
additional option in your rule configuration.

```js
[2, 'Foo']
```

```js
var Foo = require('Foo');

var Hello = <div>Hello {this.props.name}</div>;
```

## When Not To Use It

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.
2 changes: 1 addition & 1 deletion lib/rules/jsx-uses-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;

module.exports = function(context) {

var id = 'React';
var id = context.options[0] || 'React';

// --------------------------------------------------------------------------
// Public
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/jsx-uses-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ eslintTester.addRuleTest('node_modules/eslint/lib/rules/no-unused-vars', {
valid: [
{code: '/*eslint jsx-uses-react:1*/ var React; <div />;', ecmaFeatures: {jsx: true}},
{code: '/*eslint jsx-uses-react:1*/ var React; (function () { <div /> })();', ecmaFeatures: {jsx: true}},
{code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var Foo; <div />;', ecmaFeatures: {jsx: true}}
{code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var Foo; <div />;', ecmaFeatures: {jsx: true}},
{code: '/*eslint jsx-uses-react:[1,"Foo"]*/ var Foo; <div />;', ecmaFeatures: {jsx: true}}
],
invalid: [
{code: '/*eslint jsx-uses-react:1*/ var React;',
Expand Down

0 comments on commit 4822162

Please sign in to comment.