Skip to content

Commit fbf81eb

Browse files
committed
Merge pull request #581 from tikotzky/update-eslint-react
[eslint config] [react] add missing rules from eslint-plugin-react (enforcing where necessary)
2 parents fcd1c1d + f2afce7 commit fbf81eb

File tree

1 file changed

+50
-9
lines changed
  • packages/eslint-config-airbnb/rules

1 file changed

+50
-9
lines changed

packages/eslint-config-airbnb/rules/react.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ module.exports = {
55
'ecmaFeatures': {
66
'jsx': true
77
},
8+
// View link below for react rules documentation
9+
// https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
810
'rules': {
911
// Prevent missing displayName in a React component definition
1012
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
11-
'react/display-name': 0,
13+
'react/display-name': [0, {'acceptTranspilerName', false}],
14+
// Forbid certain propTypes (any, array, object)
15+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
16+
'react/forbid-prop-types': [0, {'forbid': ['any', 'array', 'object']}],
1217
// Enforce boolean attributes notation in JSX
1318
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
1419
'react/jsx-boolean-value': [2, 'never'],
@@ -17,46 +22,82 @@ module.exports = {
1722
'react/jsx-closing-bracket-location': [2, 'line-aligned'],
1823
// Enforce or disallow spaces inside of curly braces in JSX attributes
1924
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
20-
'react/jsx-curly-spacing': 0,
25+
'react/jsx-curly-spacing': [0, 'never', {'allowMultiline': true}],
26+
// Enforce event handler naming conventions in JSX
27+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
28+
'react/jsx-handler-names': [0, {
29+
'eventHandlerPrefix': 'handle',
30+
'eventHandlerPropPrefix': 'on',
31+
}],
2132
// Validate props indentation in JSX
2233
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
2334
'react/jsx-indent-props': [2, 2],
35+
// Validate JSX has key prop when in array or iterator
36+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
37+
'react/jsx-key': 0,
38+
// Limit maximum of props on a single line in JSX
39+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
40+
'react/jsx-max-props-per-line': [0, {'maximum': 1}],
2441
// Prevent usage of .bind() and arrow functions in JSX props
2542
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
2643
'react/jsx-no-bind': 2,
2744
// Prevent duplicate props in JSX
2845
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
29-
'react/jsx-no-duplicate-props': 0,
46+
'react/jsx-no-duplicate-props': [0, {'ignoreCase': false}],
47+
// Prevent usage of unwrapped JSX strings
48+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
49+
'react/jsx-no-literals': 0,
3050
// Disallow undeclared variables in JSX
3151
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
3252
'react/jsx-no-undef': 2,
53+
// Enforce PascalCase for user-defined JSX components
54+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
55+
'react/jsx-pascal-case': 0,
3356
// Enforce propTypes declarations alphabetical sorting
3457
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md
35-
'react/jsx-sort-prop-types': 0,
58+
'react/jsx-sort-prop-types': [0, {
59+
'ignoreCase': false,
60+
'callbacksLast': false,
61+
}],
3662
// Enforce props alphabetical sorting
3763
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
38-
'react/jsx-sort-props': 0,
64+
'react/jsx-sort-props': [0, {
65+
'ignoreCase': false,
66+
'callbacksLast': false,
67+
}],
3968
// Prevent React to be incorrectly marked as unused
4069
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
41-
'react/jsx-uses-react': 2,
70+
'react/jsx-uses-react': [2, {'pragma': 'React'}],
4271
// Prevent variables used in JSX to be incorrectly marked as unused
4372
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
4473
'react/jsx-uses-vars': 2,
4574
// Prevent usage of dangerous JSX properties
4675
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
4776
'react/no-danger': 0,
77+
// Prevent usage of deprecated methods
78+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
79+
'react/no-deprecated': [1, {"react": "0.14.0"}],
4880
// Prevent usage of setState in componentDidMount
4981
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
5082
'react/no-did-mount-set-state': [2, 'allow-in-func'],
5183
// Prevent usage of setState in componentDidUpdate
5284
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
5385
'react/no-did-update-set-state': [2, 'allow-in-func'],
86+
// Prevent direct mutation of this.state
87+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
88+
'react/no-direct-mutation-state': 0,
5489
// Prevent usage of isMounted
5590
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
5691
'react/no-is-mounted': 2,
5792
// Prevent multiple component definition per file
5893
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
59-
'react/no-multi-comp': 2,
94+
'react/no-multi-comp': [2, {'ignoreStateless': false}],
95+
// Prevent usage of setState
96+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
97+
'react/no-set-state': 0,
98+
// Prevent using string references
99+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
100+
'react/no-string-refs': 0,
60101
// Prevent usage of unknown DOM property
61102
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
62103
'react/no-unknown-property': 2,
@@ -65,13 +106,13 @@ module.exports = {
65106
'react/prefer-es6-class': [2, 'always'],
66107
// Prevent missing props validation in a React component definition
67108
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
68-
'react/prop-types': 2,
109+
'react/prop-types': [2, {'ignore': [], customValidators: []}],
69110
// Prevent missing React when using JSX
70111
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
71112
'react/react-in-jsx-scope': 2,
72113
// Restrict file extensions that may be required
73114
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-extension.md
74-
'react/require-extension': 0,
115+
'react/require-extension': [0, {'extensions': ['.jsx']}],
75116
// Prevent extra closing tags for components without children
76117
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
77118
'react/self-closing-comp': 2,

0 commit comments

Comments
 (0)