Skip to content

Commit

Permalink
Add pragma config option to react-in-jsx-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Neal Granger committed Dec 3, 2015
1 parent 0c2ffa7 commit eb522c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
20 changes: 20 additions & 0 deletions docs/rules/react-in-jsx-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ var Foo = require('foo');
var Hello = <div>Hello {this.props.name}</div>;
```

## Rule Options

```js
...
"react-in-jsx-scope": [<enabled>, { "pragma": <string> }]
...
```

### `pragma`

As an alternative to specifying the above pragma in each source file, you can specify
this configuration option:

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

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


## When Not To Use It

If you are setting `React` as a global variable you can disable this rule.
13 changes: 11 additions & 2 deletions lib/rules/react-in-jsx-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;

module.exports = function(context) {

var id = 'React';
var config = context.options[0] || {};
var id = config.pragma || 'React';
var NOT_DEFINED_MESSAGE = '\'{{name}}\' must be in scope when using JSX';

return {
Expand All @@ -41,4 +42,12 @@ module.exports = function(context) {

};

module.exports.schema = [];
module.exports.schema = [{
type: 'object',
properties: {
pragma: {
type: 'string'
}
},
additionalProperties: false
}];

0 comments on commit eb522c0

Please sign in to comment.