@@ -21,168 +21,163 @@ const MESSAGE = 'Component is not optimized. Please add a shouldComponentUpdate
21
21
const ruleTester = new RuleTester ( { parserOptions} ) ;
22
22
ruleTester . run ( 'react-require-optimization' , rule , {
23
23
valid : [ {
24
- code : [
25
- ' class A {}'
26
- ] . join ( '\n' )
27
- } , {
28
- code : [
29
- ' import React from "react";' +
30
- ' class YourComponent extends React.Component {' +
31
- ' shouldComponentUpdate () {}' +
32
- '}'
33
- ] . join ( '\n' )
34
- } , {
35
- code : [
36
- ' import React, {Component} from "react";' +
37
- ' class YourComponent extends Component {' +
38
- ' shouldComponentUpdate () {}' +
39
- '}'
40
- ] . join ( '\n' )
41
- } , {
42
- code : [
43
- ' import React, {Component} from "react";' ,
44
- ' @reactMixin.decorate(PureRenderMixin)' ,
45
- ' class YourComponent extends Component {' ,
46
- ' componetnDidMount () {}' ,
47
- ' render() {}' ,
48
- '}'
49
- ] . join ( '\n' ) ,
24
+ code : `
25
+ class A {}
26
+ `
27
+ } , {
28
+ code : `
29
+ import React from "react";
30
+ class YourComponent extends React.Component {
31
+ shouldComponentUpdate () {}
32
+ }
33
+ `
34
+ } , {
35
+ code : `
36
+ import React, {Component} from "react";
37
+ class YourComponent extends Component {
38
+ shouldComponentUpdate () {}
39
+ }
40
+ `
41
+ } , {
42
+ code : `
43
+ import React, {Component} from "react";
44
+ @reactMixin.decorate(PureRenderMixin)
45
+ class YourComponent extends Component {
46
+ componetnDidMount () {}
47
+ render() {}
48
+ }
49
+ ` ,
50
50
parser : 'babel-eslint'
51
51
} , {
52
- code : [
53
- 'import React from "react";' +
54
- 'createReactClass({' +
55
- 'shouldComponentUpdate: function () {}' +
56
- '})'
57
- ] . join ( '\n' )
58
- } , {
59
- code : [
60
- 'import React from "react";' +
61
- 'createReactClass({' +
62
- 'mixins: [PureRenderMixin]' +
63
- '})'
64
- ] . join ( '\n' )
65
- } , {
66
- code : [
67
- '@reactMixin.decorate(PureRenderMixin)' ,
68
- 'class DecoratedComponent extends Component {' +
69
- '}'
70
- ] . join ( '\n' ) ,
52
+ code : `
53
+ import React from "react";
54
+ createReactClass({
55
+ shouldComponentUpdate: function () {}
56
+ })
57
+ `
58
+ } , {
59
+ code : `
60
+ import React from "react";
61
+ createReactClass({
62
+ mixins: [PureRenderMixin]
63
+ })
64
+ `
65
+ } , {
66
+ code : `
67
+ @reactMixin.decorate(PureRenderMixin)
68
+ class DecoratedComponent extends Component {}
69
+ ` ,
71
70
parser : 'babel-eslint'
72
71
} , {
73
- code : [
74
- ' const FunctionalComponent = function (props) {' +
75
- ' return <div />;' +
76
- '}'
77
- ] . join ( '\n' ) ,
72
+ code : `
73
+ const FunctionalComponent = function (props) {
74
+ return <div />;
75
+ }
76
+ ` ,
78
77
parser : 'babel-eslint'
79
78
} , {
80
- code : [
81
- ' function FunctionalComponent(props) {' +
82
- ' return <div />;' +
83
- '}'
84
- ] . join ( '\n' ) ,
79
+ code : `
80
+ function FunctionalComponent(props) {
81
+ return <div />;
82
+ }
83
+ ` ,
85
84
parser : 'babel-eslint'
86
85
} , {
87
- code : [
88
- ' const FunctionalComponent = (props) => {' +
89
- ' return <div />;' +
90
- '}'
91
- ] . join ( '\n' ) ,
86
+ code : `
87
+ const FunctionalComponent = (props) => {
88
+ return <div />;
89
+ }
90
+ ` ,
92
91
parser : 'babel-eslint'
93
92
} , {
94
- code : [
95
- '@bar' ,
96
- '@pureRender' ,
97
- '@foo' ,
98
- 'class DecoratedComponent extends Component {' +
99
- '}'
100
- ] . join ( '\n' ) ,
93
+ code : `
94
+ @bar
95
+ @pureRender
96
+ @foo
97
+ class DecoratedComponent extends Component {}
98
+ ` ,
101
99
parser : 'babel-eslint' ,
102
100
options : [ { allowDecorators : [ 'renderPure' , 'pureRender' ] } ]
103
101
} , {
104
- code : [
105
- ' import React from "react";' +
106
- ' class YourComponent extends React.PureComponent {}'
107
- ] . join ( '\n' ) ,
102
+ code : `
103
+ import React from "react";
104
+ class YourComponent extends React.PureComponent {}
105
+ ` ,
108
106
parser : 'babel-eslint' ,
109
107
options : [ { allowDecorators : [ 'renderPure' , 'pureRender' ] } ]
110
108
} , {
111
- code : [
112
- ' import React, {PureComponent} from "react";' +
113
- ' class YourComponent extends PureComponent {}'
114
- ] . join ( '\n' ) ,
109
+ code : `
110
+ import React, {PureComponent} from "react";
111
+ class YourComponent extends PureComponent {}
112
+ ` ,
115
113
parser : 'babel-eslint' ,
116
114
options : [ { allowDecorators : [ 'renderPure' , 'pureRender' ] } ]
117
115
} ] ,
118
116
119
117
invalid : [ {
120
- code : [
121
- ' import React from "react";' +
122
- ' class YourComponent extends React.Component {}'
123
- ] . join ( '\n' ) ,
118
+ code : `
119
+ import React from "react";
120
+ class YourComponent extends React.Component {}
121
+ ` ,
124
122
errors : [ {
125
123
message : MESSAGE
126
124
} ]
127
125
} , {
128
- code : [
129
- ' import React from "react";' ,
130
- ' class YourComponent extends React.Component {' ,
131
- ' handleClick() {}' ,
132
- ' render() {' ,
133
- ' return <div onClick={this.handleClick}>123</div>' ,
134
- ' }' ,
135
- '}'
136
- ] . join ( '\n' ) ,
126
+ code : `
127
+ import React from "react";
128
+ class YourComponent extends React.Component {
129
+ handleClick() {}
130
+ render() {
131
+ return <div onClick={this.handleClick}>123</div>
132
+ }
133
+ }
134
+ ` ,
137
135
parser : 'babel-eslint' ,
138
136
errors : [ {
139
137
message : MESSAGE
140
138
} ]
141
139
} , {
142
- code : [
143
- ' import React, {Component} from "react";' +
144
- ' class YourComponent extends Component {}'
145
- ] . join ( '\n' ) ,
140
+ code : `
141
+ import React, {Component} from "react";
142
+ class YourComponent extends Component {}
143
+ ` ,
146
144
errors : [ {
147
145
message : MESSAGE
148
146
} ]
149
147
} , {
150
- code : [
151
- 'import React from "react";' +
152
- 'createReactClass({' +
153
- '})'
154
- ] . join ( '\n' ) ,
148
+ code : `
149
+ import React from "react";
150
+ createReactClass({})
151
+ ` ,
155
152
errors : [ {
156
153
message : MESSAGE
157
154
} ]
158
155
} , {
159
- code : [
160
- ' import React from "react";' +
161
- ' createReactClass({' +
162
- ' mixins: [RandomMixin]' +
163
- '})'
164
- ] . join ( '\n' ) ,
156
+ code : `
157
+ import React from "react";
158
+ createReactClass({
159
+ mixins: [RandomMixin]
160
+ })
161
+ ` ,
165
162
errors : [ {
166
163
message : MESSAGE
167
164
} ]
168
165
} , {
169
- code : [
170
- '@reactMixin.decorate(SomeOtherMixin)' ,
171
- 'class DecoratedComponent extends Component {' +
172
- '}'
173
- ] . join ( '\n' ) ,
166
+ code : `
167
+ @reactMixin.decorate(SomeOtherMixin)
168
+ class DecoratedComponent extends Component {}
169
+ ` ,
174
170
errors : [ {
175
171
message : MESSAGE
176
172
} ] ,
177
173
parser : 'babel-eslint'
178
174
} , {
179
- code : [
180
- '@bar' ,
181
- '@pure' ,
182
- '@foo' ,
183
- 'class DecoratedComponent extends Component {' +
184
- '}'
185
- ] . join ( '\n' ) ,
175
+ code : `
176
+ @bar
177
+ @pure
178
+ @foo
179
+ class DecoratedComponent extends Component {}
180
+ ` ,
186
181
errors : [ {
187
182
message : MESSAGE
188
183
} ] ,
0 commit comments