Skip to content

Commit b396e6c

Browse files
committed
Remove rulesConfig and export a shareable config (fixes #192)
1 parent b3cc7a5 commit b396e6c

File tree

3 files changed

+67
-108
lines changed

3 files changed

+67
-108
lines changed

README.md

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,6 @@ With ESLint 2.x.x:
6969

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

72-
```json
73-
{
74-
"rules": {
75-
"react/display-name": 1,
76-
"react/forbid-prop-types": 1,
77-
"react/no-danger": 1,
78-
"react/no-deprecated": 1,
79-
"react/no-did-mount-set-state": 1,
80-
"react/no-did-update-set-state": 1,
81-
"react/no-direct-mutation-state": 1,
82-
"react/no-is-mounted": 1,
83-
"react/no-multi-comp": 1,
84-
"react/no-set-state": 1,
85-
"react/no-string-refs": 1,
86-
"react/no-unknown-property": 1,
87-
"react/prefer-es6-class": 1,
88-
"react/prop-types": 1,
89-
"react/react-in-jsx-scope": 1,
90-
"react/require-extension": 1,
91-
"react/self-closing-comp": 1,
92-
"react/sort-comp": 1,
93-
"react/wrap-multilines": 1,
94-
95-
"react/jsx-boolean-value": 1,
96-
"react/jsx-closing-bracket-location": 1,
97-
"react/jsx-curly-spacing": 1,
98-
"react/jsx-equals-spacing": 1,
99-
"react/jsx-handler-names": 1,
100-
"react/jsx-indent-props": 1,
101-
"react/jsx-indent": 1,
102-
"react/jsx-key": 1,
103-
"react/jsx-max-props-per-line": 1,
104-
"react/jsx-no-bind": 1,
105-
"react/jsx-no-duplicate-props": 1,
106-
"react/jsx-no-literals": 1,
107-
"react/jsx-no-undef": 1,
108-
"react/jsx-pascal-case": 1,
109-
"react/jsx-sort-prop-types": 1,
110-
"react/jsx-sort-props": 1,
111-
"react/jsx-space-before-closing": 1,
112-
"react/jsx-uses-react": 1,
113-
"react/jsx-uses-vars": 1
114-
}
115-
}
116-
```
117-
11872
# List of supported rules
11973

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

140-
### JSX-specific rules
94+
## JSX-specific rules
14195

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

162-
## React Native
116+
## React Native rules
163117

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

120+
# Recommended configuration
121+
122+
This plugin export a `recommended` configuration that enforce React good practices.
123+
124+
To enable this configuration use the `extends` property in your `.eslintrc` config file:
125+
126+
```js
127+
{
128+
"plugins": [
129+
"react"
130+
],
131+
"extends": "plugin:react/recommended"
132+
}
133+
```
134+
135+
See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.
136+
137+
The rules enabled in this configuration are:
138+
139+
* [display-name](docs/rules/display-name.md)
140+
* [jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md)
141+
* [jsx-no-undef](docs/rules/jsx-no-undef.md)
142+
* [jsx-uses-react](docs/rules/jsx-uses-react.md)
143+
* [jsx-uses-vars](docs/rules/jsx-uses-vars.md)
144+
* [no-danger](docs/rules/no-danger.md)
145+
* [no-deprecated](docs/rules/no-deprecated.md)
146+
* [no-did-mount-set-state](docs/rules/no-did-mount-set-state.md) with `allow-in-func` option
147+
* [no-did-update-set-state](docs/rules/no-did-update-set-state.md) with `allow-in-func` option
148+
* [no-direct-mutation-state](docs/rules/no-direct-mutation-state.md)
149+
* [no-is-mounted](docs/rules/no-is-mounted.md)
150+
* [no-unknown-property](docs/rules/no-unknown-property.md)
151+
* [prop-types](docs/rules/prop-types.md)
152+
* [react-in-jsx-scope](docs/rules/react-in-jsx-scope.md)
153+
154+
**Note**: This configuration will also enable JSX in [parser options](http://eslint.org/docs/user-guide/configuring#specifying-parser-options).
155+
166156
# License
167157

168158
ESLint-plugin-React is licensed under the [MIT License](http://www.opensource.org/licenses/mit-license.php).

index.js

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,29 @@ module.exports = {
4242
'jsx-key': require('./lib/rules/jsx-key'),
4343
'no-string-refs': require('./lib/rules/no-string-refs')
4444
},
45-
rulesConfig: {
46-
'jsx-uses-react': 0,
47-
'no-multi-comp': 0,
48-
'prop-types': 0,
49-
'display-name': 0,
50-
'wrap-multilines': 0,
51-
'self-closing-comp': 0,
52-
'no-deprecated': 0,
53-
'no-danger': 0,
54-
'no-set-state': 0,
55-
'no-is-mounted': 0,
56-
'no-did-mount-set-state': 0,
57-
'no-did-update-set-state': 0,
58-
'react-in-jsx-scope': 0,
59-
'jsx-uses-vars': 1,
60-
'jsx-handler-names': 0,
61-
'jsx-pascal-case': 0,
62-
'jsx-no-bind': 0,
63-
'jsx-no-undef': 0,
64-
'no-unknown-property': 0,
65-
'jsx-curly-spacing': 0,
66-
'jsx-equals-spacing': 0,
67-
'jsx-sort-props': 0,
68-
'sort-prop-types': 0,
69-
'jsx-sort-prop-types': 0,
70-
'jsx-boolean-value': 0,
71-
'sort-comp': 0,
72-
'require-extension': 0,
73-
'jsx-no-duplicate-props': 0,
74-
'jsx-max-props-per-line': 0,
75-
'jsx-no-literals': 0,
76-
'jsx-indent-props': 0,
77-
'jsx-indent': 0,
78-
'jsx-closing-bracket-location': 0,
79-
'jsx-space-before-closing': 0,
80-
'no-direct-mutation-state': 0,
81-
'forbid-prop-types': 0,
82-
'prefer-es6-class': 0,
83-
'jsx-key': 0,
84-
'no-string-refs': 0
45+
configs: {
46+
recommended: {
47+
parserOptions: {
48+
ecmaFeatures: {
49+
jsx: true
50+
}
51+
},
52+
rules: {
53+
'react/display-name': 2,
54+
'react/jsx-no-duplicate-props': 2,
55+
'react/jsx-no-undef': 2,
56+
'react/jsx-uses-react': 2,
57+
'react/jsx-uses-vars': 2,
58+
'react/no-danger': 2,
59+
'react/no-deprecated': 2,
60+
'react/no-did-mount-set-state': [2, 'allow-in-func'],
61+
'react/no-did-update-set-state': [2, 'allow-in-func'],
62+
'react/no-direct-mutation-state': 2,
63+
'react/no-is-mounted': 2,
64+
'react/no-unknown-property': 2,
65+
'react/prop-types': 2,
66+
'react/react-in-jsx-scope': 2
67+
}
68+
}
8569
}
8670
};

tests/index.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ var rules = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
1212
return path.basename(f, '.js');
1313
});
1414

15-
var defaultSettings = {
16-
'jsx-uses-vars': 1
17-
};
18-
1915
describe('all rule files should be exported by the plugin', function() {
2016
rules.forEach(function(ruleName) {
2117
it('should export ' + ruleName, function() {
@@ -24,22 +20,11 @@ describe('all rule files should be exported by the plugin', function() {
2420
require(path.join('../lib/rules', ruleName))
2521
);
2622
});
23+
});
24+
});
2725

28-
if (defaultSettings.hasOwnProperty(ruleName)) {
29-
var val = defaultSettings[ruleName];
30-
it('should configure ' + ruleName + ' to ' + val + ' by default', function() {
31-
assert.equal(
32-
plugin.rulesConfig[ruleName],
33-
val
34-
);
35-
});
36-
} else {
37-
it('should configure ' + ruleName + ' off by default', function() {
38-
assert.equal(
39-
plugin.rulesConfig[ruleName],
40-
0
41-
);
42-
});
43-
}
26+
describe('configurations', function() {
27+
it('should export a \'recommended\' configuration', function() {
28+
assert(plugin.configs.recommended);
4429
});
4530
});

0 commit comments

Comments
 (0)