Skip to content

Commit 5989125

Browse files
committed
Merge pull request airbnb#618 from kesne/jgens/react-defaults
[eslint config] [react] [minor] Including missing defaults to the react eslint; enable react/jsx-quotes
2 parents 8c76e4f + d02a506 commit 5989125

3 files changed

Lines changed: 68 additions & 17 deletions

File tree

packages/eslint-config-airbnb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"devDependencies": {
4040
"babel-tape-runner": "1.2.0",
4141
"eslint": "^1.8.0",
42-
"eslint-plugin-react": "^3.7.1",
42+
"eslint-plugin-react": "^3.11.3",
4343
"react": "^0.13.3",
4444
"tape": "^4.2.2"
4545
},

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,70 @@ module.exports = {
77
},
88
'rules': {
99
// Prevent missing displayName in a React component definition
10+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
1011
'react/display-name': 0,
1112
// Enforce boolean attributes notation in JSX
12-
'react/jsx-boolean-value': 2,
13+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
14+
'react/jsx-boolean-value': [2, 'never'],
15+
// Validate closing bracket location in JSX
16+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
17+
'react/jsx-closing-bracket-location': [2, 'line-aligned'],
1318
// Enforce or disallow spaces inside of curly braces in JSX attributes
19+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
1420
'react/jsx-curly-spacing': 0,
21+
// Validate props indentation in JSX
22+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
23+
'react/jsx-indent-props': [2, 2],
1524
// Prevent duplicate props in JSX
25+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
1626
'react/jsx-no-duplicate-props': 0,
1727
// Disallow undeclared variables in JSX
28+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
1829
'react/jsx-no-undef': 2,
1930
// Enforce quote style for JSX attributes
20-
'react/jsx-quotes': 0,
31+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quote.md
32+
'react/jsx-quotes': [2, 'double'],
2133
// Enforce propTypes declarations alphabetical sorting
34+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md
2235
'react/jsx-sort-prop-types': 0,
2336
// Enforce props alphabetical sorting
37+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
2438
'react/jsx-sort-props': 0,
2539
// Prevent React to be incorrectly marked as unused
40+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
2641
'react/jsx-uses-react': 2,
2742
// Prevent variables used in JSX to be incorrectly marked as unused
43+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
2844
'react/jsx-uses-vars': 2,
2945
// Prevent usage of dangerous JSX properties
46+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
3047
'react/no-danger': 0,
3148
// Prevent usage of setState in componentDidMount
49+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
3250
'react/no-did-mount-set-state': [2, 'allow-in-func'],
3351
// Prevent usage of setState in componentDidUpdate
34-
'react/no-did-update-set-state': 2,
52+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
53+
'react/no-did-update-set-state': [2, 'allow-in-func'],
3554
// Prevent multiple component definition per file
55+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
3656
'react/no-multi-comp': 2,
3757
// Prevent usage of unknown DOM property
58+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
3859
'react/no-unknown-property': 2,
3960
// Prevent missing props validation in a React component definition
61+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
4062
'react/prop-types': 2,
4163
// Prevent missing React when using JSX
64+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
4265
'react/react-in-jsx-scope': 2,
4366
// Restrict file extensions that may be required
67+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-extension.md
4468
'react/require-extension': 0,
4569
// Prevent extra closing tags for components without children
70+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
4671
'react/self-closing-comp': 2,
4772
// Enforce component methods order
73+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
4874
'react/sort-comp': [2, {
4975
'order': [
5076
'lifecycle',
@@ -56,6 +82,11 @@ module.exports = {
5682
]
5783
}],
5884
// Prevent missing parentheses around multilines JSX
59-
'react/wrap-multilines': 2
85+
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
86+
'react/wrap-multilines': [2, {
87+
declaration: true,
88+
assignment: true,
89+
return: true
90+
}]
6091
}
6192
};

react/README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626

2727
- Use class extends React.Component unless you have a very good reason to use mixins.
2828

29+
eslint rules: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md).
30+
2931
```javascript
3032
// bad
3133
const Listing = React.createClass({
3234
render() {
3335
return <div />;
3436
}
3537
});
36-
38+
3739
// good
3840
class Listing extends React.Component {
3941
render() {
@@ -46,7 +48,10 @@
4648

4749
- **Extensions**: Use `.jsx` extension for React components.
4850
- **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
49-
- **Reference Naming**: Use PascalCase for React components and camelCase for their instances:
51+
- **Reference Naming**: Use PascalCase for React components and camelCase for their instances.
52+
53+
eslint rules: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md).
54+
5055
```javascript
5156
// bad
5257
const reservationCard = require('./ReservationCard');
@@ -92,6 +97,8 @@
9297
## Alignment
9398
- Follow these alignment styles for JSX syntax
9499

100+
eslint rules: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md).
101+
95102
```javascript
96103
// bad
97104
<Foo superLongParam="bar"
@@ -121,6 +128,8 @@
121128
> Why? JSX attributes [can't contain escaped quotes](http://eslint.org/docs/rules/jsx-quotes), so double quotes make conjunctions like `"don't"` easier to type.
122129
> Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.
123130
131+
eslint rules: [`react/jsx-quotes`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-quotes.md).
132+
124133
```javascript
125134
// bad
126135
<Foo bar='bar' />
@@ -169,7 +178,10 @@
169178
```
170179
171180
## Parentheses
172-
- Wrap JSX tags in parentheses when they span more than one line:
181+
- Wrap JSX tags in parentheses when they span more than one line.
182+
183+
eslint rules: [`react/wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md).
184+
173185
```javascript
174186
/// bad
175187
render() {
@@ -196,6 +208,9 @@
196208
197209
## Tags
198210
- Always self-close tags that have no children.
211+
212+
eslint rules: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md).
213+
199214
```javascript
200215
// bad
201216
<Foo className="stuff"></Foo>
@@ -205,6 +220,9 @@
205220
```
206221
207222
- If your component has multi-line properties, close its tag on a new line.
223+
224+
eslint rules: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md).
225+
208226
```javascript
209227
// bad
210228
<Foo
@@ -243,7 +261,7 @@
243261
## Ordering
244262
245263
- Ordering for class extends React.Component:
246-
264+
247265
1. constructor
248266
1. optional static methods
249267
1. getChildContext
@@ -262,31 +280,31 @@
262280
- How to define propTypes, defaultProps, contextTypes, etc...
263281
264282
```javascript
265-
import React, { Component, PropTypes } from 'react';
266-
283+
import React, { PropTypes } from 'react';
284+
267285
const propTypes = {
268286
id: PropTypes.number.isRequired,
269287
url: PropTypes.string.isRequired,
270288
text: PropTypes.string,
271289
};
272-
290+
273291
const defaultProps = {
274292
text: 'Hello World',
275293
};
276-
277-
class Link extends Component {
294+
295+
class Link extends React.Component {
278296
static methodsAreOk() {
279297
return true;
280298
}
281-
299+
282300
render() {
283301
return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>
284302
}
285303
}
286-
304+
287305
Link.propTypes = propTypes;
288306
Link.defaultProps = defaultProps;
289-
307+
290308
export default Link;
291309
```
292310
@@ -314,4 +332,6 @@
314332
1. *Optional render methods* like renderNavigation() or renderProfilePicture()
315333
1. render
316334
335+
eslint rules: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md).
336+
317337
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)