Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16899b8

Browse files
author
Barzilay, Oshri (ob143h)
committedNov 1, 2021
fix tests
1 parent dae95cc commit 16899b8

File tree

3 files changed

+149
-96
lines changed

3 files changed

+149
-96
lines changed
 

‎tests/lib/rules/no-color-literals.js

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const tests = {
3737
export default class MyComponent extends Component {
3838
render() {
3939
const isDanger = true;
40-
return <View
40+
return <View
4141
style={[styles.style1, isDanger ? styles.style1 : styles.style2]}
4242
/>;
4343
}
@@ -57,11 +57,11 @@ const tests = {
5757
export default class MyComponent extends Component {
5858
render() {
5959
const trueColor = '#fff';
60-
const falseColor = '#000'
61-
return <View
62-
style={[style1,
63-
this.state.isDanger && {color: falseColor},
64-
{color: someBoolean ? trueColor : falseColor }]}
60+
const falseColor = '#000'
61+
return <View
62+
style={[style1,
63+
this.state.isDanger && {color: falseColor},
64+
{color: someBoolean ? trueColor : falseColor }]}
6565
/>;
6666
}
6767
}
@@ -79,9 +79,11 @@ const tests = {
7979
}
8080
});
8181
`,
82-
errors: [{
83-
message: 'Color literal: { backgroundColor: \'#FFFFFF\' }',
84-
}],
82+
errors: [
83+
{
84+
message: "Color literal: { backgroundColor: '#FFFFFF' }",
85+
},
86+
],
8587
},
8688
{
8789
code: `
@@ -93,9 +95,11 @@ const tests = {
9395
}
9496
});
9597
`,
96-
errors: [{
97-
message: 'Color literal: { backgroundColor: \'#FFFFFF\' }',
98-
}],
98+
errors: [
99+
{
100+
message: "Color literal: { backgroundColor: '#FFFFFF' }",
101+
},
102+
],
99103
},
100104
{
101105
code: `
@@ -110,9 +114,11 @@ const tests = {
110114
}
111115
});
112116
`,
113-
errors: [{
114-
message: 'Color literal: { fontColor: \'#000\' }',
115-
}],
117+
errors: [
118+
{
119+
message: "Color literal: { fontColor: '#000' }",
120+
},
121+
],
116122
},
117123
{
118124
code: `
@@ -124,24 +130,28 @@ const tests = {
124130
}
125131
});
126132
`,
127-
errors: [{
128-
message: 'Color literal: { backgroundColor: \'#FFFFFF\' }',
129-
}],
133+
errors: [
134+
{
135+
message: "Color literal: { backgroundColor: '#FFFFFF' }",
136+
},
137+
],
130138
},
131139
{
132140
code: `
133141
const Hello = React.createClass({
134142
render: function() {
135-
const someBoolean = false;
143+
const someBoolean = false;
136144
return <Text style={[styles.text, someBoolean && {backgroundColor: '#FFFFFF'}]}>
137145
Hello {this.props.name}
138146
</Text>;
139147
}
140148
});
141149
`,
142-
errors: [{
143-
message: 'Color literal: { backgroundColor: \'#FFFFFF\' }',
144-
}],
150+
errors: [
151+
{
152+
message: "Color literal: { backgroundColor: '#FFFFFF' }",
153+
},
154+
],
145155
},
146156
{
147157
code: `
@@ -156,23 +166,23 @@ const tests = {
156166
});
157167
export default class MyComponent extends Component {
158168
render() {
159-
return <View
160-
style={[style1,
161-
this.state.isDanger && styles.style1,
162-
{backgroundColor: someBoolean ? '#fff' : '#000'}]}
169+
return <View
170+
style={[style1,
171+
this.state.isDanger && styles.style1,
172+
{backgroundColor: someBoolean ? '#fff' : '#000'}]}
163173
/>;
164174
}
165175
}
166176
`,
167177
errors: [
168178
{
169-
message: 'Color literal: { color: \'red\' }',
179+
message: "Color literal: { color: 'red' }",
170180
},
171181
{
172-
message: 'Color literal: { borderBottomColor: \'blue\' }',
182+
message: "Color literal: { borderBottomColor: 'blue' }",
173183
},
174184
{
175-
message: 'Color literal: { backgroundColor: \'someBoolean ? \\\'#fff\\\' : \\\'#000\\\'\' }', //eslint-disable-line
185+
message: `Color literal: { backgroundColor: "someBoolean ? '#fff' : '#000'" }`, //eslint-disable-line
176186
},
177187
],
178188
},

‎tests/lib/rules/no-inline-styles.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const tests = {
5656
});
5757
export default class MyComponent extends Component {
5858
render() {
59-
const trueColor = '#fff'; const falseColor = '#000'
60-
return <View
61-
style={[style1,
62-
this.state.isDanger && styles.style1,
63-
{color: someBoolean ? trueColor : falseColor }]}
59+
const trueColor = '#fff'; const falseColor = '#000'
60+
return <View
61+
style={[style1,
62+
this.state.isDanger && styles.style1,
63+
{color: someBoolean ? trueColor : falseColor }]}
6464
/>;
6565
}
6666
}
@@ -154,7 +154,7 @@ const tests = {
154154
code: `
155155
const Hello = React.createClass({
156156
render: function() {
157-
const someBoolean = false;
157+
const someBoolean = false;
158158
return <Text style={[styles.text, someBoolean && {backgroundColor: '#FFFFFF'}]}>
159159
Hello {this.props.name}
160160
</Text>;
@@ -177,16 +177,16 @@ const tests = {
177177
});
178178
export default class MyComponent extends Component {
179179
render() {
180-
return <View
181-
style={[style1,
182-
this.state.isDanger && styles.style1,
183-
{backgroundColor: someBoolean ? '#fff' : '#000'}]}
180+
return <View
181+
style={[style1,
182+
this.state.isDanger && styles.style1,
183+
{backgroundColor: someBoolean ? '#fff' : '#000'}]}
184184
/>;
185185
}
186186
}
187187
`,
188188
errors: [{
189-
message: 'Inline style: { backgroundColor: \'someBoolean ? \\\'#fff\\\' : \\\'#000\\\'\' }', //eslint-disable-line
189+
message: `Inline style: { backgroundColor: "someBoolean ? '#fff' : '#000'" }`, //eslint-disable-line
190190
}],
191191
},
192192
],

‎tests/lib/rules/no-unused-styles.js

Lines changed: 99 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ require('babel-eslint');
2020

2121
const ruleTester = new RuleTester();
2222
const tests = {
23-
valid: [{
24-
code: `
23+
valid: [
24+
{
25+
code: `
2526
const styles = StyleSheet.create({
2627
name: {}
2728
});
@@ -31,8 +32,22 @@ const tests = {
3132
}
3233
});
3334
`,
34-
}, {
35-
code: `
35+
},
36+
{
37+
code: `
38+
const styles = StyleSheet.create({
39+
name: {}
40+
});
41+
const Hello = React.createClass({
42+
render: function() {
43+
const { name } = styles;
44+
return <Text textStyle={name}>Hello {this.props.name}</Text>;
45+
}
46+
});
47+
`,
48+
},
49+
{
50+
code: `
3651
const Hello = React.createClass({
3752
render: function() {
3853
return <Text textStyle={styles.name}>Hello {this.props.name}</Text>;
@@ -42,8 +57,9 @@ const tests = {
4257
name: {}
4358
});
4459
`,
45-
}, {
46-
code: `
60+
},
61+
{
62+
code: `
4763
const styles = StyleSheet.create({
4864
name: {}
4965
});
@@ -53,8 +69,9 @@ const tests = {
5369
}
5470
});
5571
`,
56-
}, {
57-
code: `
72+
},
73+
{
74+
code: `
5875
const styles = StyleSheet.create({
5976
name: {},
6077
welcome: {}
@@ -70,8 +87,9 @@ const tests = {
7087
}
7188
});
7289
`,
73-
}, {
74-
code: `
90+
},
91+
{
92+
code: `
7593
const styles = StyleSheet.create({
7694
text: {}
7795
})
@@ -84,8 +102,9 @@ const tests = {
84102
}
85103
});
86104
`,
87-
}, {
88-
code: `
105+
},
106+
{
107+
code: `
89108
const styles = StyleSheet.create({
90109
text: {}
91110
})
@@ -105,14 +124,15 @@ const tests = {
105124
}
106125
});
107126
`,
108-
}, {
109-
code: `
127+
},
128+
{
129+
code: `
110130
const styles = StyleSheet.create({
111131
text: {}
112132
});
113133
const Hello = React.createClass({
114134
getInitialState: function() {
115-
return { condition: true, condition2: true };
135+
return { condition: true, condition2: true };
116136
},
117137
render: function() {
118138
return (
@@ -127,15 +147,16 @@ const tests = {
127147
}
128148
});
129149
`,
130-
}, {
131-
code: `
150+
},
151+
{
152+
code: `
132153
const styles = StyleSheet.create({
133154
text: {},
134155
text2: {},
135156
});
136157
const Hello = React.createClass({
137158
getInitialState: function() {
138-
return { condition: true };
159+
return { condition: true };
139160
},
140161
render: function() {
141162
return (
@@ -146,8 +167,9 @@ const tests = {
146167
}
147168
});
148169
`,
149-
}, {
150-
code: `
170+
},
171+
{
172+
code: `
151173
const styles = StyleSheet.create({
152174
style1: {
153175
color: 'red',
@@ -165,17 +187,19 @@ const tests = {
165187
}
166188
}
167189
`,
168-
}, {
169-
code: `
190+
},
191+
{
192+
code: `
170193
const styles = StyleSheet.create({
171194
text: {}
172195
})
173196
`,
174-
}, {
175-
code: `
197+
},
198+
{
199+
code: `
176200
const Hello = React.createClass({
177201
getInitialState: function() {
178-
return { condition: true };
202+
return { condition: true };
179203
},
180204
render: function() {
181205
const myStyle = this.state.condition ? styles.text : styles.text2;
@@ -191,8 +215,9 @@ const tests = {
191215
text2: {},
192216
});
193217
`,
194-
}, {
195-
code: `
218+
},
219+
{
220+
code: `
196221
const additionalStyles = {};
197222
const styles = StyleSheet.create({
198223
name: {},
@@ -204,8 +229,9 @@ const tests = {
204229
}
205230
});
206231
`,
207-
}, {
208-
code: `
232+
},
233+
{
234+
code: `
209235
const styles = OtherStyleSheet.create({
210236
name: {},
211237
});
@@ -215,10 +241,12 @@ const tests = {
215241
}
216242
});
217243
`,
218-
}],
244+
},
245+
],
219246

220-
invalid: [{
221-
code: `
247+
invalid: [
248+
{
249+
code: `
222250
const styles = StyleSheet.create({
223251
text: {}
224252
})
@@ -228,11 +256,14 @@ const tests = {
228256
}
229257
});
230258
`,
231-
errors: [{
232-
message: 'Unused style detected: styles.text',
233-
}],
234-
}, {
235-
code: `
259+
errors: [
260+
{
261+
message: 'Unused style detected: styles.text',
262+
},
263+
],
264+
},
265+
{
266+
code: `
236267
const styles = StyleSheet.create({
237268
foo: {},
238269
bar: {},
@@ -243,11 +274,14 @@ const tests = {
243274
}
244275
}
245276
`,
246-
errors: [{
247-
message: 'Unused style detected: styles.bar',
248-
}],
249-
}, {
250-
code: `
277+
errors: [
278+
{
279+
message: 'Unused style detected: styles.bar',
280+
},
281+
],
282+
},
283+
{
284+
code: `
251285
const styles = StyleSheet.create({
252286
foo: {},
253287
bar: {},
@@ -258,11 +292,14 @@ const tests = {
258292
}
259293
}
260294
`,
261-
errors: [{
262-
message: 'Unused style detected: styles.bar',
263-
}],
264-
}, {
265-
code: `
295+
errors: [
296+
{
297+
message: 'Unused style detected: styles.bar',
298+
},
299+
],
300+
},
301+
{
302+
code: `
266303
const styles = OtherStyleSheet.create({
267304
foo: {},
268305
bar: {},
@@ -273,20 +310,26 @@ const tests = {
273310
}
274311
}
275312
`,
276-
errors: [{
277-
message: 'Unused style detected: styles.bar',
278-
}],
279-
}, {
280-
code: `
313+
errors: [
314+
{
315+
message: 'Unused style detected: styles.bar',
316+
},
317+
],
318+
},
319+
{
320+
code: `
281321
const styles = StyleSheet.create({
282322
text: {}
283323
})
284324
const Hello = () => (<><Text style={styles.b}>Hello</Text></>);
285325
`,
286-
errors: [{
287-
message: 'Unused style detected: styles.text',
288-
}],
289-
}],
326+
errors: [
327+
{
328+
message: 'Unused style detected: styles.text',
329+
},
330+
],
331+
},
332+
],
290333
};
291334

292335
const config = {

0 commit comments

Comments
 (0)
Please sign in to comment.