Skip to content

Commit 0414389

Browse files
committed
Update files to match new coding rules
1 parent 372ae6d commit 0414389

File tree

6 files changed

+124
-19
lines changed

6 files changed

+124
-19
lines changed

lib/rules/display-name.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ module.exports = function(context) {
1212

1313
var hasDisplayName = false;
1414

15+
function isComponentDefinition(node) {
16+
return (
17+
node &&
18+
node.callee &&
19+
node.callee.object &&
20+
node.callee.property &&
21+
node.callee.object.name === 'React' &&
22+
node.callee.property.name === 'createClass'
23+
);
24+
}
25+
1526
// --------------------------------------------------------------------------
1627
// Public
1728
// --------------------------------------------------------------------------
@@ -20,7 +31,7 @@ module.exports = function(context) {
2031

2132
'ObjectExpression': function(node) {
2233

23-
if (!node.parent.callee || node.parent.callee.object.name !== 'React' || node.parent.callee.property.name !== 'createClass') {
34+
if (!isComponentDefinition(node.parent)) {
2435
return;
2536
}
2637

@@ -30,16 +41,18 @@ module.exports = function(context) {
3041
hasDisplayName = true;
3142
}
3243
});
33-
3444
},
3545

3646
'ObjectExpression:exit': function(node) {
37-
if (!node.parent.callee || node.parent.callee.object.name !== 'React' || node.parent.callee.property.name !== 'createClass') {
47+
48+
if (!isComponentDefinition(node.parent)) {
3849
return;
3950
}
51+
4052
if (!hasDisplayName) {
4153
context.report(node, 'Component definition is missing display name');
4254
}
55+
4356
hasDisplayName = false;
4457
}
4558
};

lib/rules/prop-types.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ module.exports = function(context) {
1212

1313
var hasPropTypes = false;
1414

15+
function isComponentDefinition(node) {
16+
return (
17+
node &&
18+
node.callee &&
19+
node.callee.object &&
20+
node.callee.property &&
21+
node.callee.object.name === 'React' &&
22+
node.callee.property.name === 'createClass'
23+
);
24+
}
25+
1526
// --------------------------------------------------------------------------
1627
// Public
1728
// --------------------------------------------------------------------------
@@ -20,7 +31,7 @@ module.exports = function(context) {
2031

2132
'ObjectExpression': function(node) {
2233

23-
if (!node.parent.callee || node.parent.callee.object.name !== 'React' || node.parent.callee.property.name !== 'createClass') {
34+
if (!isComponentDefinition(node.parent)) {
2435
return;
2536
}
2637

@@ -30,16 +41,18 @@ module.exports = function(context) {
3041
hasPropTypes = true;
3142
}
3243
});
33-
3444
},
3545

3646
'ObjectExpression:exit': function(node) {
37-
if (!node.parent.callee || node.parent.callee.object.name !== 'React' || node.parent.callee.property.name !== 'createClass') {
47+
48+
if (!isComponentDefinition(node.parent)) {
3849
return;
3950
}
51+
4052
if (!hasPropTypes) {
4153
context.report(node, 'Component definition is missing props validation');
4254
}
55+
4356
hasPropTypes = false;
4457
}
4558
};

tests/lib/rules/display-name.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ eslintTester.addRuleTest('lib/rules/display-name', {
2020

2121
valid: [
2222
{
23-
code: 'var Hello = React.createClass({displayName: \'Hello\',render: function() {return <div>Hello {this.props.name}</div>;}});',
23+
code: '\
24+
var Hello = React.createClass({\
25+
displayName: \'Hello\',\
26+
render: function() {\
27+
return <div>Hello {this.props.name}</div>;\
28+
}\
29+
});',
2430
settings: {
2531
ecmascript: 6,
2632
jsx: true
@@ -30,7 +36,12 @@ eslintTester.addRuleTest('lib/rules/display-name', {
3036

3137
invalid: [
3238
{
33-
code: 'var Hello = React.createClass({render: function() {return <div>Hello {this.props.name}</div>;}});',
39+
code: '\
40+
var Hello = React.createClass({\
41+
render: function() {\
42+
return <div>Hello {this.props.name}</div>;\
43+
}\
44+
});',
3445
settings: {
3546
ecmascript: 6,
3647
jsx: true

tests/lib/rules/no-multi-comp.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ eslintTester.addRuleTest('lib/rules/no-multi-comp', {
2020

2121
valid: [
2222
{
23-
code: 'var Hello = require(\'./components/Hello\');var HelloJohn = React.createClass({render: function() {return <Hello name="John" />;}});',
23+
code: '\
24+
var Hello = require(\'./components/Hello\');\
25+
var HelloJohn = React.createClass({\
26+
render: function() {\
27+
return <Hello name="John" />;\
28+
}\
29+
});',
2430
settings: {
2531
ecmascript: 6,
2632
jsx: true
@@ -30,7 +36,17 @@ eslintTester.addRuleTest('lib/rules/no-multi-comp', {
3036

3137
invalid: [
3238
{
33-
code: 'var Hello = React.createClass({render: function() {return <div>Hello {this.props.name}</div>;}});var HelloJohn = React.createClass({render: function() {return <Hello name="John" />;}});',
39+
code: '\
40+
var Hello = React.createClass({\
41+
render: function() {\
42+
return <div>Hello {this.props.name}</div>;\
43+
}\
44+
});\
45+
var HelloJohn = React.createClass({\
46+
render: function() {\
47+
return <Hello name="John" />;\
48+
}\
49+
});',
3450
settings: {
3551
ecmascript: 6,
3652
jsx: true

tests/lib/rules/prop-types.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
2020

2121
valid: [
2222
{
23-
code: 'var Hello = React.createClass({propTypes: {name: React.PropTypes.string.isRequired},render: function() {return <div>Hello {this.props.name}</div>;}});',
23+
code: '\
24+
var Hello = React.createClass({\
25+
propTypes: {\
26+
name: React.PropTypes.string.isRequired\
27+
},\
28+
render: function() {\
29+
return <div>Hello {this.props.name}</div>;\
30+
}\
31+
});',
2432
settings: {
2533
ecmascript: 6,
2634
jsx: true
@@ -30,7 +38,12 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
3038

3139
invalid: [
3240
{
33-
code: 'var Hello = React.createClass({render: function() {return <div>Hello {this.props.name}</div>;}});',
41+
code: '\
42+
var Hello = React.createClass({\
43+
render: function() {\
44+
return <div>Hello {this.props.name}</div>;\
45+
}\
46+
});',
3447
settings: {
3548
ecmascript: 6,
3649
jsx: true

tests/lib/rules/wrap-multilines.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@ eslintTester.addRuleTest('lib/rules/wrap-multilines', {
2020

2121
valid: [
2222
{
23-
code: 'var Hello = React.createClass({render: function() {return <p>Hello {this.props.name}</p>;}});',
23+
code: '\
24+
var Hello = React.createClass({\
25+
render: function() {\
26+
return <p>Hello {this.props.name}</p>;\
27+
}\
28+
});',
2429
settings: {
2530
ecmascript: 6,
2631
jsx: true
2732
}
2833
}, {
29-
code: 'var Hello = React.createClass({render: function() {return (\n<div>\n<p>Hello {this.props.name}</p>\n</div>\n);}});',
34+
code: '\
35+
var Hello = React.createClass({\
36+
render: function() {\
37+
return (\n\
38+
<div>\n\
39+
<p>Hello {this.props.name}</p>\n\
40+
</div>\n\
41+
);\
42+
}\
43+
});',
3044
settings: {
3145
ecmascript: 6,
3246
jsx: true
@@ -38,13 +52,24 @@ eslintTester.addRuleTest('lib/rules/wrap-multilines', {
3852
jsx: true
3953
}
4054
}, {
41-
code: 'var hello = (\n<div>\n<p>Hello</p>\n</div>\n);',
55+
code: '\
56+
var hello = (\n\
57+
<div>\n\
58+
<p>Hello</p>\n\
59+
</div>\n\
60+
);',
4261
settings: {
4362
ecmascript: 6,
4463
jsx: true
4564
}
4665
}, {
47-
code: 'var hello; hello = (\n<div>\n<p>Hello</p>\n</div>\n);',
66+
code: '\
67+
var hello;\
68+
hello = (\n\
69+
<div>\n\
70+
<p>Hello</p>\n\
71+
</div>\n\
72+
);',
4873
settings: {
4974
ecmascript: 6,
5075
jsx: true
@@ -54,7 +79,14 @@ eslintTester.addRuleTest('lib/rules/wrap-multilines', {
5479

5580
invalid: [
5681
{
57-
code: 'var Hello = React.createClass({render: function() {return <div>\n<p>Hello {this.props.name}</p>\n</div>;}});',
82+
code: '\
83+
var Hello = React.createClass({\
84+
render: function() {\
85+
return <div>\n\
86+
<p>Hello {this.props.name}</p>\n\
87+
</div>;\
88+
}\
89+
});',
5890
settings: {
5991
ecmascript: 6,
6092
jsx: true
@@ -63,7 +95,10 @@ eslintTester.addRuleTest('lib/rules/wrap-multilines', {
6395
message: 'Missing parentheses around multilines JSX'
6496
}]
6597
}, {
66-
code: 'var hello = <div>\n<p>Hello</p>\n</div>;',
98+
code: '\
99+
var hello = <div>\n\
100+
<p>Hello</p>\n\
101+
</div>;',
67102
settings: {
68103
ecmascript: 6,
69104
jsx: true
@@ -72,7 +107,11 @@ eslintTester.addRuleTest('lib/rules/wrap-multilines', {
72107
message: 'Missing parentheses around multilines JSX'
73108
}]
74109
}, {
75-
code: 'var hello; hello = <div>\n<p>Hello</p>\n</div>;',
110+
code: '\
111+
var hello;\
112+
hello = <div>\n\
113+
<p>Hello</p>\n\
114+
</div>;',
76115
settings: {
77116
ecmascript: 6,
78117
jsx: true

0 commit comments

Comments
 (0)