Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Code cleanup #336

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/rules/no-event-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`,
Expand Down
2 changes: 1 addition & 1 deletion test-self/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": "wikimedia/client-es5",
"extends": "wikimedia/client",
"plugins": [ "self" ],
"globals": {
"$": "readonly"
Expand Down
2 changes: 1 addition & 1 deletion test-self/all/constructor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line self/no-jquery-constructor
$( function () {} );
$( () => {} );

// eslint-disable-next-line self/no-jquery-constructor
$( '.selector' );
Expand Down
6 changes: 3 additions & 3 deletions test-self/deprecated-1.8/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test-self/recommended/test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line self/variable-pattern
var foo = $( '.foo' );
const foo = $( '.foo' );
2 changes: 1 addition & 1 deletion test-self/slim/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions tests/rules/no-event-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,7 +77,7 @@ forbidden.forEach( ( method ) => {
docgen: false
}
);
invalid = invalid.concat(
invalid.push(
{
code: '$("div").' + method + '(handler)',
errors: [ error ],
Expand Down Expand Up @@ -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
} );
4 changes: 1 addition & 3 deletions tests/rules/no-load-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
Expand Down
4 changes: 1 addition & 3 deletions tests/rules/no-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() { })',
Expand Down
4 changes: 0 additions & 4 deletions tests/rules/variable-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ ruleTester.run( 'variable-pattern', rule, {
'var $div = $("<div>")',
{
code: 'let $letDiv = $("<div>")',
parserOptions: { ecmaVersion: 2015 },
docgen: false
},
{
code: 'const $constDiv = $("<div>")',
parserOptions: { ecmaVersion: 2015 },
docgen: false
},
{
Expand Down Expand Up @@ -168,13 +166,11 @@ ruleTester.run( 'variable-pattern', rule, {
},
{
code: 'let letDiv = $("<div>")',
parserOptions: { ecmaVersion: 2015 },
docgen: false,
errors: [ error ]
},
{
code: 'const constDiv = $("<div>")',
parserOptions: { ecmaVersion: 2015 },
docgen: false,
errors: [ error ]
},
Expand Down
9 changes: 7 additions & 2 deletions tools/rule-tester.js
Original file line number Diff line number Diff line change
@@ -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;
Loading