diff --git a/src/rules/no-event-shorthand.js b/src/rules/no-event-shorthand.js index 635fa5d6..b01e4b61 100644 --- a/src/rules/no-event-shorthand.js +++ b/src/rules/no-event-shorthand.js @@ -44,8 +44,9 @@ const rule = utils.createCollectionMethodRule( 'mousemove', 'mouseout', 'mouseover', - 'mouseup' - ].concat( ajaxEvents ), + 'mouseup', + ...ajaxEvents + ], ( node ) => node === true ? 'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' : `Prefer .on or .trigger to .${ node.callee.property.name }`, diff --git a/test-self/.eslintrc.json b/test-self/.eslintrc.json index e8463e30..1e431483 100644 --- a/test-self/.eslintrc.json +++ b/test-self/.eslintrc.json @@ -1,6 +1,6 @@ { "root": true, - "extends": "wikimedia/client-es5", + "extends": "wikimedia/client", "plugins": [ "self" ], "globals": { "$": "readonly" diff --git a/test-self/all/constructor.js b/test-self/all/constructor.js index 26d917b1..85589a29 100644 --- a/test-self/all/constructor.js +++ b/test-self/all/constructor.js @@ -1,5 +1,5 @@ // eslint-disable-next-line self/no-jquery-constructor -$( function () {} ); +$( () => {} ); // eslint-disable-next-line self/no-jquery-constructor $( '.selector' ); diff --git a/test-self/deprecated-1.8/test.js b/test-self/deprecated-1.8/test.js index bdc3f2d1..4a5c3918 100644 --- a/test-self/deprecated-1.8/test.js +++ b/test-self/deprecated-1.8/test.js @@ -27,16 +27,16 @@ $x.andSelf(); $x.error( fn ); // eslint-disable-next-line self/no-load-shorthand -$x.load( function () {} ); +$x.load( () => {} ); // eslint-disable-next-line self/no-on-ready -$( document ).on( 'ready', function () {} ); +$( document ).on( 'ready', () => {} ); // eslint-disable-next-line self/no-size $x.size(); // eslint-disable-next-line self/no-unload-shorthand -$x.unload( function () {} ); +$x.unload( () => {} ); /* 1.7 */ // eslint-disable-next-line self/no-live diff --git a/test-self/recommended/test.js b/test-self/recommended/test.js index 0093745b..9f927bde 100644 --- a/test-self/recommended/test.js +++ b/test-self/recommended/test.js @@ -1,2 +1,2 @@ // eslint-disable-next-line self/variable-pattern -var foo = $( '.foo' ); +const foo = $( '.foo' ); diff --git a/test-self/slim/test.js b/test-self/slim/test.js index 32c8c38d..819ca723 100644 --- a/test-self/slim/test.js +++ b/test-self/slim/test.js @@ -12,7 +12,7 @@ $x.slideDown(); // eslint-disable-next-line self/no-ajax $.get( 'url' ); // eslint-disable-next-line self/no-ajax-events -$x.on( 'ajaxComplete', function () {} ); +$x.on( 'ajaxComplete', () => {} ); // eslint-disable-next-line self/no-load $x.load(); // eslint-disable-next-line self/no-parse-xml diff --git a/tests/rules/no-event-shorthand.js b/tests/rules/no-event-shorthand.js index 935d5263..9866f7b4 100644 --- a/tests/rules/no-event-shorthand.js +++ b/tests/rules/no-event-shorthand.js @@ -41,14 +41,15 @@ const forbidden = [ 'mousemove', 'mouseout', 'mouseover', - 'mouseup' -].concat( ajaxEvents ); -let valid = []; -let invalid = []; + 'mouseup', + ...ajaxEvents +]; +const valid = []; +const invalid = []; forbidden.forEach( ( method ) => { const error = 'Prefer .on or .trigger to .' + method; - valid = valid.concat( + valid.push( { code: method + '()', docgen: false @@ -76,7 +77,7 @@ forbidden.forEach( ( method ) => { docgen: false } ); - invalid = invalid.concat( + invalid.push( { code: '$("div").' + method + '(handler)', errors: [ error ], @@ -107,19 +108,19 @@ forbidden.forEach( ( method ) => { } ); } ); +valid.push( + // Don't conflict with Ajax load + '$div.load( "url", handler )', + ...ajaxEvents.map( ( eventName ) => ( { + code: '$div.' + eventName + '()', + options: [ { allowAjaxEvents: true } ] + } ) ), + ...ajaxEvents.map( ( eventName ) => ( { + code: '$div.on("' + eventName + '", fn)', + options: [ { allowAjaxEvents: true } ] + } ) ) +); ruleTester.run( 'no-event-shorthand', rule, { - valid: valid.concat( [ - // Don't conflict with Ajax load - '$div.load( "url", handler )' - ] ).concat( - ajaxEvents.map( ( eventName ) => ( { - code: '$div.' + eventName + '()', - options: [ { allowAjaxEvents: true } ] - } ) ), - ajaxEvents.map( ( eventName ) => ( { - code: '$div.on("' + eventName + '", fn)', - options: [ { allowAjaxEvents: true } ] - } ) ) - ), + valid, invalid } ); diff --git a/tests/rules/no-load-shorthand.js b/tests/rules/no-load-shorthand.js index 0cba14a4..6718b752 100644 --- a/tests/rules/no-load-shorthand.js +++ b/tests/rules/no-load-shorthand.js @@ -5,9 +5,7 @@ const RuleTester = require( '../../tools/rule-tester' ); const error = 'Prefer .on or .trigger to .load'; -const ruleTester = new RuleTester( { - parserOptions: { ecmaVersion: 2015 } -} ); +const ruleTester = new RuleTester(); ruleTester.run( 'no-load-shorthand', rule, { valid: [ 'load()', diff --git a/tests/rules/no-ready.js b/tests/rules/no-ready.js index 0fa00b13..50a3e2c8 100644 --- a/tests/rules/no-ready.js +++ b/tests/rules/no-ready.js @@ -5,9 +5,7 @@ const RuleTester = require( '../../tools/rule-tester' ); const error = '.ready is not allowed'; -const ruleTester = new RuleTester( { - parserOptions: { ecmaVersion: 2015 } -} ); +const ruleTester = new RuleTester(); ruleTester.run( 'no-ready', rule, { valid: [ 'ready(function() { })', diff --git a/tests/rules/variable-pattern.js b/tests/rules/variable-pattern.js index bf658429..f33c4249 100644 --- a/tests/rules/variable-pattern.js +++ b/tests/rules/variable-pattern.js @@ -14,12 +14,10 @@ ruleTester.run( 'variable-pattern', rule, { 'var $div = $("
")', { code: 'let $letDiv = $("
")', - parserOptions: { ecmaVersion: 2015 }, docgen: false }, { code: 'const $constDiv = $("
")', - parserOptions: { ecmaVersion: 2015 }, docgen: false }, { @@ -168,13 +166,11 @@ ruleTester.run( 'variable-pattern', rule, { }, { code: 'let letDiv = $("
")', - parserOptions: { ecmaVersion: 2015 }, docgen: false, errors: [ error ] }, { code: 'const constDiv = $("
")', - parserOptions: { ecmaVersion: 2015 }, docgen: false, errors: [ error ] }, diff --git a/tools/rule-tester.js b/tools/rule-tester.js index 2730ca60..03bf546d 100644 --- a/tools/rule-tester.js +++ b/tools/rule-tester.js @@ -1,4 +1,9 @@ 'use strict'; -// TODO: This no longer overrides RuleTester so can be deleted and replaced -module.exports = require( 'eslint-docgen' ).RuleTester; +const RuleTester = require( 'eslint-docgen' ).RuleTester; + +RuleTester.setDefaultConfig( { + parserOptions: { ecmaVersion: 2015 } +} ); + +module.exports = RuleTester;