Skip to content

Commit

Permalink
Remove rulesConfig and export a shareable config (fixes #192)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Feb 14, 2016
1 parent b3cc7a5 commit b396e6c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 108 deletions.
86 changes: 38 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,6 @@ With ESLint 2.x.x:

Finally, enable all of the rules that you would like to use.

```json
{
"rules": {
"react/display-name": 1,
"react/forbid-prop-types": 1,
"react/no-danger": 1,
"react/no-deprecated": 1,
"react/no-did-mount-set-state": 1,
"react/no-did-update-set-state": 1,
"react/no-direct-mutation-state": 1,
"react/no-is-mounted": 1,
"react/no-multi-comp": 1,
"react/no-set-state": 1,
"react/no-string-refs": 1,
"react/no-unknown-property": 1,
"react/prefer-es6-class": 1,
"react/prop-types": 1,
"react/react-in-jsx-scope": 1,
"react/require-extension": 1,
"react/self-closing-comp": 1,
"react/sort-comp": 1,
"react/wrap-multilines": 1,

"react/jsx-boolean-value": 1,
"react/jsx-closing-bracket-location": 1,
"react/jsx-curly-spacing": 1,
"react/jsx-equals-spacing": 1,
"react/jsx-handler-names": 1,
"react/jsx-indent-props": 1,
"react/jsx-indent": 1,
"react/jsx-key": 1,
"react/jsx-max-props-per-line": 1,
"react/jsx-no-bind": 1,
"react/jsx-no-duplicate-props": 1,
"react/jsx-no-literals": 1,
"react/jsx-no-undef": 1,
"react/jsx-pascal-case": 1,
"react/jsx-sort-prop-types": 1,
"react/jsx-sort-props": 1,
"react/jsx-space-before-closing": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1
}
}
```

# List of supported rules

* [display-name](docs/rules/display-name.md): Prevent missing `displayName` in a React component definition
Expand All @@ -137,7 +91,7 @@ Finally, enable all of the rules that you would like to use.
* [sort-comp](docs/rules/sort-comp.md): Enforce component methods order
* [wrap-multilines](docs/rules/wrap-multilines.md): Prevent missing parentheses around multilines JSX (fixable)

### JSX-specific rules
## JSX-specific rules

* [jsx-boolean-value](docs/rules/jsx-boolean-value.md): Enforce boolean attributes notation in JSX (fixable)
* [jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md): Validate closing bracket location in JSX
Expand All @@ -159,10 +113,46 @@ Finally, enable all of the rules that you would like to use.
* [jsx-uses-react](docs/rules/jsx-uses-react.md): Prevent React to be incorrectly marked as unused
* [jsx-uses-vars](docs/rules/jsx-uses-vars.md): Prevent variables used in JSX to be incorrectly marked as unused

## React Native
## React Native rules

If you're searching for React Native specific linting rules, check out [eslint-plugin-react-native](https://github.com/Intellicode/eslint-plugin-react-native).

# Recommended configuration

This plugin export a `recommended` configuration that enforce React good practices.

To enable this configuration use the `extends` property in your `.eslintrc` config file:

```js
{
"plugins": [
"react"
],
"extends": "plugin:react/recommended"
}
```

See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.

The rules enabled in this configuration are:

* [display-name](docs/rules/display-name.md)
* [jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md)
* [jsx-no-undef](docs/rules/jsx-no-undef.md)
* [jsx-uses-react](docs/rules/jsx-uses-react.md)
* [jsx-uses-vars](docs/rules/jsx-uses-vars.md)
* [no-danger](docs/rules/no-danger.md)
* [no-deprecated](docs/rules/no-deprecated.md)
* [no-did-mount-set-state](docs/rules/no-did-mount-set-state.md) with `allow-in-func` option
* [no-did-update-set-state](docs/rules/no-did-update-set-state.md) with `allow-in-func` option
* [no-direct-mutation-state](docs/rules/no-direct-mutation-state.md)
* [no-is-mounted](docs/rules/no-is-mounted.md)
* [no-unknown-property](docs/rules/no-unknown-property.md)
* [prop-types](docs/rules/prop-types.md)
* [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md)

**Note**: This configuration will also enable JSX in [parser options](http://eslint.org/docs/user-guide/configuring#specifying-parser-options).

# License

ESLint-plugin-React is licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
Expand Down
64 changes: 24 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,29 @@ module.exports = {
'jsx-key': require('./lib/rules/jsx-key'),
'no-string-refs': require('./lib/rules/no-string-refs')
},
rulesConfig: {
'jsx-uses-react': 0,
'no-multi-comp': 0,
'prop-types': 0,
'display-name': 0,
'wrap-multilines': 0,
'self-closing-comp': 0,
'no-deprecated': 0,
'no-danger': 0,
'no-set-state': 0,
'no-is-mounted': 0,
'no-did-mount-set-state': 0,
'no-did-update-set-state': 0,
'react-in-jsx-scope': 0,
'jsx-uses-vars': 1,
'jsx-handler-names': 0,
'jsx-pascal-case': 0,
'jsx-no-bind': 0,
'jsx-no-undef': 0,
'no-unknown-property': 0,
'jsx-curly-spacing': 0,
'jsx-equals-spacing': 0,
'jsx-sort-props': 0,
'sort-prop-types': 0,
'jsx-sort-prop-types': 0,
'jsx-boolean-value': 0,
'sort-comp': 0,
'require-extension': 0,
'jsx-no-duplicate-props': 0,
'jsx-max-props-per-line': 0,
'jsx-no-literals': 0,
'jsx-indent-props': 0,
'jsx-indent': 0,
'jsx-closing-bracket-location': 0,
'jsx-space-before-closing': 0,
'no-direct-mutation-state': 0,
'forbid-prop-types': 0,
'prefer-es6-class': 0,
'jsx-key': 0,
'no-string-refs': 0
configs: {
recommended: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
},
rules: {
'react/display-name': 2,
'react/jsx-no-duplicate-props': 2,
'react/jsx-no-undef': 2,
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/no-danger': 2,
'react/no-deprecated': 2,
'react/no-did-mount-set-state': [2, 'allow-in-func'],
'react/no-did-update-set-state': [2, 'allow-in-func'],
'react/no-direct-mutation-state': 2,
'react/no-is-mounted': 2,
'react/no-unknown-property': 2,
'react/prop-types': 2,
'react/react-in-jsx-scope': 2
}
}
}
};
25 changes: 5 additions & 20 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var rules = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
return path.basename(f, '.js');
});

var defaultSettings = {
'jsx-uses-vars': 1
};

describe('all rule files should be exported by the plugin', function() {
rules.forEach(function(ruleName) {
it('should export ' + ruleName, function() {
Expand All @@ -24,22 +20,11 @@ describe('all rule files should be exported by the plugin', function() {
require(path.join('../lib/rules', ruleName))
);
});
});
});

if (defaultSettings.hasOwnProperty(ruleName)) {
var val = defaultSettings[ruleName];
it('should configure ' + ruleName + ' to ' + val + ' by default', function() {
assert.equal(
plugin.rulesConfig[ruleName],
val
);
});
} else {
it('should configure ' + ruleName + ' off by default', function() {
assert.equal(
plugin.rulesConfig[ruleName],
0
);
});
}
describe('configurations', function() {
it('should export a \'recommended\' configuration', function() {
assert(plugin.configs.recommended);
});
});

0 comments on commit b396e6c

Please sign in to comment.