Skip to content

Commit b948c64

Browse files
authored
Merge pull request #1423 from jseminck/template-literal
Refactor a bunch of tests to use template literal syntax instead of [].join(
2 parents 1f14fad + fa4e2a8 commit b948c64

31 files changed

+3001
-3058
lines changed

tests/lib/rules/boolean-prop-naming.js

+201-205
Large diffs are not rendered by default.

tests/lib/rules/display-name.js

+378-378
Large diffs are not rendered by default.

tests/lib/rules/forbid-foreign-prop-types.js

+50-50
Original file line numberDiff line numberDiff line change
@@ -53,88 +53,88 @@ ruleTester.run('forbid-foreign-prop-types', rule, {
5353
}],
5454

5555
invalid: [{
56-
code: [
57-
'var Foo = createReactClass({',
58-
' propTypes: Bar.propTypes,',
59-
' render: function() {',
60-
' return <Foo className="bar" />;',
61-
' }',
62-
'});'
63-
].join('\n'),
56+
code: `
57+
var Foo = createReactClass({
58+
propTypes: Bar.propTypes,
59+
render: function() {
60+
return <Foo className="bar" />;
61+
}
62+
});
63+
`,
6464
errors: [{
6565
message: ERROR_MESSAGE,
6666
type: 'Identifier'
6767
}]
6868
},
6969
{
70-
code: [
71-
'var Foo = createReactClass({',
72-
' propTypes: Bar["propTypes"],',
73-
' render: function() {',
74-
' return <Foo className="bar" />;',
75-
' }',
76-
'});'
77-
].join('\n'),
70+
code: `
71+
var Foo = createReactClass({
72+
propTypes: Bar["propTypes"],
73+
render: function() {
74+
return <Foo className="bar" />;
75+
}
76+
});
77+
`,
7878
errors: [{
7979
message: ERROR_MESSAGE,
8080
type: 'Literal'
8181
}]
8282
},
8383
{
84-
code: [
85-
'var { propTypes } = SomeComponent',
86-
'var Foo = createReactClass({',
87-
' propTypes,',
88-
' render: function() {',
89-
' return <Foo className="bar" />;',
90-
' }',
91-
'});'
92-
].join('\n'),
84+
code: `
85+
var { propTypes } = SomeComponent
86+
var Foo = createReactClass({
87+
propTypes,
88+
render: function() {
89+
return <Foo className="bar" />;
90+
}
91+
});
92+
`,
9393
errors: [{
9494
message: ERROR_MESSAGE,
9595
type: 'Property'
9696
}]
9797
},
9898
{
99-
code: [
100-
'var { propTypes: things, ...foo } = SomeComponent',
101-
'var Foo = createReactClass({',
102-
' propTypes,',
103-
' render: function() {',
104-
' return <Foo className="bar" />;',
105-
' }',
106-
'});'
107-
].join('\n'),
99+
code: `
100+
var { propTypes: things, ...foo } = SomeComponent
101+
var Foo = createReactClass({
102+
propTypes,
103+
render: function() {
104+
return <Foo className="bar" />;
105+
}
106+
});
107+
`,
108108
parser: 'babel-eslint',
109109
errors: [{
110110
message: ERROR_MESSAGE,
111111
type: 'Property'
112112
}]
113113
},
114114
{
115-
code: [
116-
'class MyComponent extends React.Component {',
117-
' static fooBar = {',
118-
' baz: Qux.propTypes.baz',
119-
' };',
120-
'}'
121-
].join('\n'),
115+
code: `
116+
class MyComponent extends React.Component {
117+
static fooBar = {
118+
baz: Qux.propTypes.baz
119+
};
120+
}
121+
`,
122122
parser: 'babel-eslint',
123123
errors: [{
124124
message: ERROR_MESSAGE,
125125
type: 'Identifier'
126126
}]
127127
},
128128
{
129-
code: [
130-
'var { propTypes: typesOfProps } = SomeComponent',
131-
'var Foo = createReactClass({',
132-
' propTypes: typesOfProps,',
133-
' render: function() {',
134-
' return <Foo className="bar" />;',
135-
' }',
136-
'});'
137-
].join('\n'),
129+
code: `
130+
var { propTypes: typesOfProps } = SomeComponent
131+
var Foo = createReactClass({
132+
propTypes: typesOfProps,
133+
render: function() {
134+
return <Foo className="bar" />;
135+
}
136+
});
137+
`,
138138
errors: [{
139139
message: ERROR_MESSAGE,
140140
type: 'Property'

tests/lib/rules/jsx-closing-tag-location.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,39 @@ const MESSAGE_OWN_LINE = [{message: 'Closing tag of a multiline JSX expression m
2727
const ruleTester = new RuleTester({parserOptions});
2828
ruleTester.run('jsx-closing-tag-location', rule, {
2929
valid: [{
30-
code: [
31-
'<App>',
32-
' foo',
33-
'</App>'
34-
].join('\n')
30+
code: `
31+
<App>
32+
foo
33+
</App>
34+
`
3535
}, {
36-
code: [
37-
'<App>foo</App>'
38-
].join('\n')
36+
code: `
37+
<App>foo</App>
38+
`
3939
}],
4040

4141
invalid: [{
42-
code: [
43-
'<App>',
44-
' foo',
45-
' </App>'
46-
].join('\n'),
47-
output: [
48-
'<App>',
49-
' foo',
50-
'</App>'
51-
].join('\n'),
42+
code: `
43+
<App>
44+
foo
45+
</App>
46+
`,
47+
output: `
48+
<App>
49+
foo
50+
</App>
51+
`,
5252
errors: MESSAGE_MATCH_INDENTATION
5353
}, {
54-
code: [
55-
'<App>',
56-
' foo</App>'
57-
].join('\n'),
58-
output: [
59-
'<App>',
60-
' foo',
61-
'</App>'
62-
].join('\n'),
54+
code: `
55+
<App>
56+
foo</App>
57+
`,
58+
output: `
59+
<App>
60+
foo
61+
</App>
62+
`,
6363
errors: MESSAGE_OWN_LINE
6464
}]
6565
});

tests/lib/rules/jsx-handler-names.js

+21-63
Original file line numberDiff line numberDiff line change
@@ -27,105 +27,63 @@ const parserOptions = {
2727
const ruleTester = new RuleTester({parserOptions});
2828
ruleTester.run('jsx-handler-names', rule, {
2929
valid: [{
30-
code: [
31-
'<TestComponent onChange={this.handleChange} />'
32-
].join('\n')
30+
code: '<TestComponent onChange={this.handleChange} />'
3331
}, {
34-
code: [
35-
'<TestComponent onChange={this.props.onChange} />'
36-
].join('\n')
32+
code: '<TestComponent onChange={this.props.onChange} />'
3733
}, {
38-
code: [
39-
'<TestComponent onChange={this.props.onFoo} />'
40-
].join('\n')
34+
code: '<TestComponent onChange={this.props.onFoo} />'
4135
}, {
42-
code: [
43-
'<TestComponent isSelected={this.props.isSelected} />'
44-
].join('\n')
36+
code: '<TestComponent isSelected={this.props.isSelected} />'
4537
}, {
46-
code: [
47-
'<TestComponent shouldDisplay={this.state.shouldDisplay} />'
48-
].join('\n')
38+
code: '<TestComponent shouldDisplay={this.state.shouldDisplay} />'
4939
}, {
50-
code: [
51-
'<TestComponent shouldDisplay={arr[0].prop} />'
52-
].join('\n')
40+
code: '<TestComponent shouldDisplay={arr[0].prop} />'
5341
}, {
54-
code: [
55-
'<TestComponent onChange={props.onChange} />'
56-
].join('\n')
42+
code: '<TestComponent onChange={props.onChange} />'
5743
}, {
58-
code: [
59-
'<TestComponent ref={this.handleRef} />'
60-
].join('\n')
44+
code: '<TestComponent ref={this.handleRef} />'
6145
}, {
62-
code: [
63-
'<TestComponent ref={this.somethingRef} />'
64-
].join('\n')
46+
code: '<TestComponent ref={this.somethingRef} />'
6547
}, {
66-
code: [
67-
'<TestComponent test={this.props.content} />'
68-
].join('\n'),
48+
code: '<TestComponent test={this.props.content} />',
6949
options: [{
7050
eventHandlerPrefix: 'on',
7151
eventHandlerPropPrefix: 'on'
7252
}]
7353
}, {
74-
code: [
75-
'<TestComponent onChange={props::handleChange} />'
76-
].join('\n'),
54+
code: '<TestComponent onChange={props::handleChange} />',
7755
parser: 'babel-eslint'
7856
}, {
79-
code: [
80-
'<TestComponent onChange={::props.onChange} />'
81-
].join('\n'),
57+
code: '<TestComponent onChange={::props.onChange} />',
8258
parser: 'babel-eslint'
8359
}, {
84-
code: [
85-
'<TestComponent onChange={props.foo::handleChange} />'
86-
].join('\n'),
60+
code: '<TestComponent onChange={props.foo::handleChange} />',
8761
parser: 'babel-eslint'
8862
}, {
89-
code: [
90-
'<TestComponent only={this.only} />'
91-
].join('\n')
63+
code: '<TestComponent only={this.only} />'
9264
}],
9365

9466
invalid: [{
95-
code: [
96-
'<TestComponent onChange={this.doSomethingOnChange} />'
97-
].join('\n'),
67+
code: '<TestComponent onChange={this.doSomethingOnChange} />',
9868
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
9969
}, {
100-
code: [
101-
'<TestComponent onChange={this.handlerChange} />'
102-
].join('\n'),
70+
code: '<TestComponent onChange={this.handlerChange} />',
10371
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
10472
}, {
105-
code: [
106-
'<TestComponent only={this.handleChange} />'
107-
].join('\n'),
73+
code: '<TestComponent only={this.handleChange} />',
10874
errors: [{message: 'Prop key for handleChange must begin with \'on\''}]
10975
}, {
110-
code: [
111-
'<TestComponent handleChange={this.handleChange} />'
112-
].join('\n'),
76+
code: '<TestComponent handleChange={this.handleChange} />',
11377
errors: [{message: 'Prop key for handleChange must begin with \'on\''}]
11478
}, {
115-
code: [
116-
'<TestComponent onChange={this.onChange} />'
117-
].join('\n'),
79+
code: '<TestComponent onChange={this.onChange} />',
11880
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
11981
}, {
120-
code: [
121-
'<TestComponent onChange={props::onChange} />'
122-
].join('\n'),
82+
code: '<TestComponent onChange={props::onChange} />',
12383
parser: 'babel-eslint',
12484
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
12585
}, {
126-
code: [
127-
'<TestComponent onChange={props.foo::onChange} />'
128-
].join('\n'),
86+
code: '<TestComponent onChange={props.foo::onChange} />',
12987
parser: 'babel-eslint',
13088
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
13189
}]

0 commit comments

Comments
 (0)