Hygiene: restrict use of $.each and fix offenders

Bug: T190142
Change-Id: I5da7a4a1ffe14647ec70b10b3a7ab9b935c5ca84
This commit is contained in:
jdlrobson 2018-03-20 11:03:13 -07:00 committed by Stephen Niedzielski
parent 18f5c3d060
commit 3245a2ac6e
6 changed files with 11 additions and 4 deletions

View file

@ -18,6 +18,13 @@
"ReduxThunk": false "ReduxThunk": false
}, },
"rules": { "rules": {
"no-restricted-properties": [2,
{
"object": "$",
"property": "each",
"message": "Please use Array.forEach"
}
],
"dot-notation": [ 2, { "allowKeywords": true } ], "dot-notation": [ 2, { "allowKeywords": true } ],
"no-use-before-define": 0, "no-use-before-define": 0,
"no-var": 2, "no-var": 2,

Binary file not shown.

Binary file not shown.

View file

@ -57,7 +57,7 @@ function makeTitleInExtractBold( extract, title ) {
); );
extract = extract.split( snip ); extract = extract.split( snip );
$.each( extract, ( index, part ) => { extract.forEach( part => {
if ( part.indexOf( boldIdentifier ) === 0 ) { if ( part.indexOf( boldIdentifier ) === 0 ) {
elements.push( $( '<b>' ) elements.push( $( '<b>' )
.text( part.substring( boldIdentifier.length ) ) ); .text( part.substring( boldIdentifier.length ) ) );

View file

@ -562,7 +562,7 @@ export function layoutPreview(
export function getClosestYPosition( y, rects, isTop ) { export function getClosestYPosition( y, rects, isTop ) {
let minY = null, result; let minY = null, result;
$.each( rects, ( i, rect ) => { Array.prototype.slice.call( rects ).forEach( rect => {
const deltaY = Math.abs( y - rect.top + y - rect.bottom ); const deltaY = Math.abs( y - rect.top + y - rect.bottom );
if ( minY === null || minY > deltaY ) { if ( minY === null || minY > deltaY ) {

View file

@ -130,13 +130,13 @@ QUnit.test( 'MediaWiki API gateway is correctly extracting the page data from th
assert.expect( errorCases.length + successCases.length ); assert.expect( errorCases.length + successCases.length );
$.each( errorCases, ( _, data ) => { errorCases.forEach( data => {
assert.throws( () => { assert.throws( () => {
gateway.extractPageFromResponse( data ); gateway.extractPageFromResponse( data );
} ); } );
} ); } );
$.each( successCases, ( _, data ) => { successCases.forEach( data => {
assert.deepEqual( assert.deepEqual(
gateway.extractPageFromResponse( data[ 0 ] ), gateway.extractPageFromResponse( data[ 0 ] ),
data[ 1 ] data[ 1 ]