@@ -30,161 +30,146 @@ const ruleTester = new RuleTester({parserOptions});
30
30
ruleTester . run ( 'require-render-return' , rule , {
31
31
32
32
valid : [ {
33
- // ES6 class
34
- code : [
35
- 'class Hello extends React.Component {' ,
36
- ' render() {' ,
37
- ' return <div>Hello {this.props.name}</div>;' ,
38
- ' }' ,
39
- '}'
40
- ] . join ( '\n' )
33
+ code : `
34
+ class Hello extends React.Component {
35
+ render() {
36
+ return <div>Hello {this.props.name}</div>;
37
+ }
38
+ }
39
+ `
41
40
} , {
42
- // ES6 class with render property
43
- code : [
44
- 'class Hello extends React.Component {' ,
45
- ' render = () => {' ,
46
- ' return <div>Hello {this.props.name}</div>;' ,
47
- ' }' ,
48
- '}'
49
- ] . join ( '\n' ) ,
41
+ code : `
42
+ class Hello extends React.Component {
43
+ render = () => {
44
+ return <div>Hello {this.props.name}</div>;
45
+ }
46
+ }
47
+ ` ,
50
48
parser : 'babel-eslint'
51
49
} , {
52
- // ES6 class with render property (implicit return)
53
- code : [
54
- 'class Hello extends React.Component {' ,
55
- ' render = () => (' ,
56
- ' <div>Hello {this.props.name}</div>' ,
57
- ' )' ,
58
- '}'
59
- ] . join ( '\n' ) ,
50
+ code : `
51
+ class Hello extends React.Component {
52
+ render = () => (
53
+ <div>Hello {this.props.name}</div>
54
+ )
55
+ }
56
+ ` ,
60
57
parser : 'babel-eslint'
61
58
} , {
62
- // ES5 class
63
- code : [
64
- 'var Hello = createReactClass({' ,
65
- ' displayName: \'Hello\',' ,
66
- ' render: function() {' ,
67
- ' return <div></div>' ,
68
- ' }' ,
69
- '});'
70
- ] . join ( '\n' )
59
+ code : `
60
+ var Hello = createReactClass({
61
+ displayName: 'Hello',
62
+ render: function() {
63
+ return <div></div>
64
+ }
65
+ });
66
+ `
71
67
} , {
72
- // Stateless function
73
- code : [
74
- 'function Hello() {' ,
75
- ' return <div></div>;' ,
76
- '}'
77
- ] . join ( '\n' )
68
+ code : `
69
+ function Hello() {
70
+ return <div></div>;
71
+ }
72
+ `
78
73
} , {
79
- // Stateless arrow function
80
- code : [
81
- 'var Hello = () => (' ,
82
- ' <div></div>' ,
83
- ');'
84
- ] . join ( '\n' ) ,
74
+ code : `
75
+ var Hello = () => (
76
+ <div></div>
77
+ );
78
+ ` ,
85
79
parser : 'babel-eslint'
86
80
} , {
87
- // Return in a switch...case
88
- code : [
89
- 'var Hello = createReactClass({' ,
90
- ' render: function() {' ,
91
- ' switch (this.props.name) {' ,
92
- ' case \'Foo\':' ,
93
- ' return <div>Hello Foo</div>;' ,
94
- ' default:' ,
95
- ' return <div>Hello {this.props.name}</div>;' ,
96
- ' }' ,
97
- ' }' ,
98
- '});'
99
- ] . join ( '\n' )
81
+ code : `
82
+ var Hello = createReactClass({
83
+ render: function() {
84
+ switch (this.props.name) {
85
+ case 'Foo':
86
+ return <div>Hello Foo</div>;
87
+ default:
88
+ return <div>Hello {this.props.name}</div>;
89
+ }
90
+ }
91
+ });
92
+ `
100
93
} , {
101
- // Return in a if...else
102
- code : [
103
- 'var Hello = createReactClass({' ,
104
- ' render: function() {' ,
105
- ' if (this.props.name === \'Foo\') {' ,
106
- ' return <div>Hello Foo</div>;' ,
107
- ' } else {' ,
108
- ' return <div>Hello {this.props.name}</div>;' ,
109
- ' }' ,
110
- ' }' ,
111
- '});'
112
- ] . join ( '\n' )
94
+ code : `
95
+ var Hello = createReactClass({
96
+ render: function() {
97
+ if (this.props.name === 'Foo') {
98
+ return <div>Hello Foo</div>;
99
+ } else {
100
+ return <div>Hello {this.props.name}</div>;
101
+ }
102
+ }
103
+ });
104
+ `
113
105
} , {
114
- // Not a React component
115
- code : [
116
- 'class Hello {' ,
117
- ' render() {}' ,
118
- '}'
119
- ] . join ( '\n' )
106
+ code : `
107
+ class Hello {
108
+ render() {}
109
+ }
110
+ `
120
111
} , {
121
112
// ES6 class without a render method
122
113
code : 'class Hello extends React.Component {}'
123
114
} , {
124
115
// ES5 class without a render method
125
116
code : 'var Hello = createReactClass({});'
126
117
} , {
127
- // ES5 class with an imported render method
128
- code : [
129
- 'var render = require(\'./render\');' ,
130
- 'var Hello = createReactClass({' ,
131
- ' render' ,
132
- '});'
133
- ] . join ( '\n' )
118
+ code : `
119
+ var render = require('./render');
120
+ var Hello = createReactClass({
121
+ render
122
+ });
123
+ `
134
124
} , {
135
- // Invalid render method (but accepted by Babel)
136
- code : [
137
- 'class Foo extends Component {' ,
138
- ' render' ,
139
- '}'
140
- ] . join ( '\n' ) ,
125
+ code : `
126
+ class Foo extends Component {
127
+ render
128
+ }
129
+ ` ,
141
130
parser : 'babel-eslint'
142
131
} ] ,
143
132
144
133
invalid : [ {
145
- // Missing return in ES5 class
146
- code : [
147
- 'var Hello = createReactClass({' ,
148
- ' displayName: \'Hello\',' ,
149
- ' render: function() {}' ,
150
- '});'
151
- ] . join ( '\n' ) ,
134
+ code : `
135
+ var Hello = createReactClass({
136
+ displayName: 'Hello',
137
+ render: function() {}
138
+ });
139
+ ` ,
152
140
errors : [ {
153
141
message : 'Your render method should have return statement'
154
142
} ]
155
143
} , {
156
- // Missing return in ES6 class
157
- code : [
158
- 'class Hello extends React.Component {' ,
159
- ' render() {} ' ,
160
- '}'
161
- ] . join ( '\n' ) ,
144
+ code : `
145
+ class Hello extends React.Component {
146
+ render() {}
147
+ }
148
+ ` ,
162
149
errors : [ {
163
150
message : 'Your render method should have return statement'
164
151
} ]
165
152
} , {
166
- // Missing return (but one is present in a sub-function)
167
- code : [
168
- 'class Hello extends React.Component {' ,
169
- ' render() {' ,
170
- ' const names = this.props.names.map(function(name) {' ,
171
- ' return <div>{name}</div>' ,
172
- ' });' ,
173
- ' } ' ,
174
- '}'
175
- ] . join ( '\n' ) ,
153
+ code : `
154
+ class Hello extends React.Component {
155
+ render() {
156
+ const names = this.props.names.map(function(name) {
157
+ return <div>{name}</div>
158
+ });
159
+ }
160
+ }
161
+ ` ,
176
162
errors : [ {
177
163
message : 'Your render method should have return statement'
178
164
} ]
179
165
} , {
180
- // Missing return ES6 class render property
181
- code : [
182
- 'class Hello extends React.Component {' ,
183
- ' render = () => {' ,
184
- ' <div>Hello {this.props.name}</div>' ,
185
- ' }' ,
186
- '}'
187
- ] . join ( '\n' ) ,
166
+ code : `
167
+ class Hello extends React.Component {
168
+ render = () => {
169
+ <div>Hello {this.props.name}</div>
170
+ }
171
+ }
172
+ ` ,
188
173
parser : 'babel-eslint' ,
189
174
errors : [ {
190
175
message : 'Your render method should have return statement'
0 commit comments