Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for setting the jsx pragma value via config #82

Merged
merged 1 commit into from
May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/rules/jsx-uses-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ If you are using the @jsx pragma this rule will mark the designated variable and

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


## Rule Details

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


## Rule Options

```js
...
"jsx-uses-react": [<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>;
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Just some little things: can you make a Rule Options section and use the same format as the other rules for the config file example ?

You can see an example here: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md#rule-options


## 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.
3 changes: 2 additions & 1 deletion lib/rules/jsx-uses-react.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';

// --------------------------------------------------------------------------
// 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,{"pragma":"Foo"}]*/ var Foo; <div />;', ecmaFeatures: {jsx: true}}
],
invalid: [
{code: '/*eslint jsx-uses-react:1*/ var React;',
Expand Down