Skip to content

Commit fefbd36

Browse files
edg2sjdforrester
andauthored
Tests: Code cleanup (#336)
* Tests: Use ES6 in test-self/ * Tests: Use ES6 for RuleTester by default * Tests: Avoid Array#concat --------- Co-authored-by: James D. Forrester <[email protected]>
1 parent 1d557ed commit fefbd36

File tree

11 files changed

+39
-40
lines changed

11 files changed

+39
-40
lines changed

src/rules/no-event-shorthand.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ const rule = utils.createCollectionMethodRule(
4444
'mousemove',
4545
'mouseout',
4646
'mouseover',
47-
'mouseup'
48-
].concat( ajaxEvents ),
47+
'mouseup',
48+
...ajaxEvents
49+
],
4950
( node ) => node === true ?
5051
'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' :
5152
`Prefer .on or .trigger to .${ node.callee.property.name }`,

test-self/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"extends": "wikimedia/client-es5",
3+
"extends": "wikimedia/client",
44
"plugins": [ "self" ],
55
"globals": {
66
"$": "readonly"

test-self/all/constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line self/no-jquery-constructor
2-
$( function () {} );
2+
$( () => {} );
33

44
// eslint-disable-next-line self/no-jquery-constructor
55
$( '.selector' );

test-self/deprecated-1.8/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ $x.andSelf();
2727
$x.error( fn );
2828

2929
// eslint-disable-next-line self/no-load-shorthand
30-
$x.load( function () {} );
30+
$x.load( () => {} );
3131

3232
// eslint-disable-next-line self/no-on-ready
33-
$( document ).on( 'ready', function () {} );
33+
$( document ).on( 'ready', () => {} );
3434

3535
// eslint-disable-next-line self/no-size
3636
$x.size();
3737

3838
// eslint-disable-next-line self/no-unload-shorthand
39-
$x.unload( function () {} );
39+
$x.unload( () => {} );
4040

4141
/* 1.7 */
4242
// eslint-disable-next-line self/no-live

test-self/recommended/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// eslint-disable-next-line self/variable-pattern
2-
var foo = $( '.foo' );
2+
const foo = $( '.foo' );

test-self/slim/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $x.slideDown();
1212
// eslint-disable-next-line self/no-ajax
1313
$.get( 'url' );
1414
// eslint-disable-next-line self/no-ajax-events
15-
$x.on( 'ajaxComplete', function () {} );
15+
$x.on( 'ajaxComplete', () => {} );
1616
// eslint-disable-next-line self/no-load
1717
$x.load();
1818
// eslint-disable-next-line self/no-parse-xml

tests/rules/no-event-shorthand.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ const forbidden = [
4141
'mousemove',
4242
'mouseout',
4343
'mouseover',
44-
'mouseup'
45-
].concat( ajaxEvents );
46-
let valid = [];
47-
let invalid = [];
44+
'mouseup',
45+
...ajaxEvents
46+
];
47+
const valid = [];
48+
const invalid = [];
4849

4950
forbidden.forEach( ( method ) => {
5051
const error = 'Prefer .on or .trigger to .' + method;
51-
valid = valid.concat(
52+
valid.push(
5253
{
5354
code: method + '()',
5455
docgen: false
@@ -76,7 +77,7 @@ forbidden.forEach( ( method ) => {
7677
docgen: false
7778
}
7879
);
79-
invalid = invalid.concat(
80+
invalid.push(
8081
{
8182
code: '$("div").' + method + '(handler)',
8283
errors: [ error ],
@@ -107,19 +108,19 @@ forbidden.forEach( ( method ) => {
107108
}
108109
);
109110
} );
111+
valid.push(
112+
// Don't conflict with Ajax load
113+
'$div.load( "url", handler )',
114+
...ajaxEvents.map( ( eventName ) => ( {
115+
code: '$div.' + eventName + '()',
116+
options: [ { allowAjaxEvents: true } ]
117+
} ) ),
118+
...ajaxEvents.map( ( eventName ) => ( {
119+
code: '$div.on("' + eventName + '", fn)',
120+
options: [ { allowAjaxEvents: true } ]
121+
} ) )
122+
);
110123
ruleTester.run( 'no-event-shorthand', rule, {
111-
valid: valid.concat( [
112-
// Don't conflict with Ajax load
113-
'$div.load( "url", handler )'
114-
] ).concat(
115-
ajaxEvents.map( ( eventName ) => ( {
116-
code: '$div.' + eventName + '()',
117-
options: [ { allowAjaxEvents: true } ]
118-
} ) ),
119-
ajaxEvents.map( ( eventName ) => ( {
120-
code: '$div.on("' + eventName + '", fn)',
121-
options: [ { allowAjaxEvents: true } ]
122-
} ) )
123-
),
124+
valid,
124125
invalid
125126
} );

tests/rules/no-load-shorthand.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const RuleTester = require( '../../tools/rule-tester' );
55

66
const error = 'Prefer .on or .trigger to .load';
77

8-
const ruleTester = new RuleTester( {
9-
parserOptions: { ecmaVersion: 2015 }
10-
} );
8+
const ruleTester = new RuleTester();
119
ruleTester.run( 'no-load-shorthand', rule, {
1210
valid: [
1311
'load()',

tests/rules/no-ready.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const RuleTester = require( '../../tools/rule-tester' );
55

66
const error = '.ready is not allowed';
77

8-
const ruleTester = new RuleTester( {
9-
parserOptions: { ecmaVersion: 2015 }
10-
} );
8+
const ruleTester = new RuleTester();
119
ruleTester.run( 'no-ready', rule, {
1210
valid: [
1311
'ready(function() { })',

tests/rules/variable-pattern.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ ruleTester.run( 'variable-pattern', rule, {
1414
'var $div = $("<div>")',
1515
{
1616
code: 'let $letDiv = $("<div>")',
17-
parserOptions: { ecmaVersion: 2015 },
1817
docgen: false
1918
},
2019
{
2120
code: 'const $constDiv = $("<div>")',
22-
parserOptions: { ecmaVersion: 2015 },
2321
docgen: false
2422
},
2523
{
@@ -168,13 +166,11 @@ ruleTester.run( 'variable-pattern', rule, {
168166
},
169167
{
170168
code: 'let letDiv = $("<div>")',
171-
parserOptions: { ecmaVersion: 2015 },
172169
docgen: false,
173170
errors: [ error ]
174171
},
175172
{
176173
code: 'const constDiv = $("<div>")',
177-
parserOptions: { ecmaVersion: 2015 },
178174
docgen: false,
179175
errors: [ error ]
180176
},

0 commit comments

Comments
 (0)