From f7c7b84589a6f3af1a6862688b67b1d1969777e0 Mon Sep 17 00:00:00 2001 From: petarpetkovic Date: Sat, 25 Aug 2018 00:37:07 +0200 Subject: [PATCH] Remove jQuery.inArray usages Replace jQuery.inArray with Array.prototype.indexOf. Also enforce this via eslint rule. Bug: T200877 Change-Id: Idbd06e6a1681300c4ab9142c7b57e4376f474041 --- .eslintrc.json | 5 +++++ resources/src/mediawiki.Title/Title.js | 2 +- resources/src/mediawiki.legacy/protect.js | 8 +++++++- resources/src/mediawiki.special.apisandbox/apisandbox.js | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index da5d409765..fbf2a5a309 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,6 +18,11 @@ "property": "map", "message": "Please use Array.prototype.map instead" }, + { + "object": "$", + "property": "inArray", + "message": "Please use Array.prototype.indexOf instead" + }, { "object": "$", "property": "isArray", diff --git a/resources/src/mediawiki.Title/Title.js b/resources/src/mediawiki.Title/Title.js index 1d0aa6732f..4491634e41 100644 --- a/resources/src/mediawiki.Title/Title.js +++ b/resources/src/mediawiki.Title/Title.js @@ -792,7 +792,7 @@ */ getName: function () { if ( - $.inArray( this.namespace, mw.config.get( 'wgCaseSensitiveNamespaces' ) ) !== -1 || + mw.config.get( 'wgCaseSensitiveNamespaces' ).indexOf( this.namespace ) !== -1 || !this.title.length ) { return this.title; diff --git a/resources/src/mediawiki.legacy/protect.js b/resources/src/mediawiki.legacy/protect.js index cb4edc128c..676ddb0e60 100644 --- a/resources/src/mediawiki.legacy/protect.js +++ b/resources/src/mediawiki.legacy/protect.js @@ -82,7 +82,13 @@ * @return {boolean} */ isCascadeableLevel: function ( level ) { - return $.inArray( level, mw.config.get( 'wgCascadeableLevels' ) ) !== -1; + var cascadeableLevels = mw.config.get( 'wgCascadeableLevels' ); + + if ( !Array.isArray( cascadeableLevels ) ) { + return false; + } + + return cascadeableLevels.indexOf( level ) !== -1; }, /** diff --git a/resources/src/mediawiki.special.apisandbox/apisandbox.js b/resources/src/mediawiki.special.apisandbox/apisandbox.js index 52abb30264..beac624ee9 100644 --- a/resources/src/mediawiki.special.apisandbox/apisandbox.js +++ b/resources/src/mediawiki.special.apisandbox/apisandbox.js @@ -1996,7 +1996,7 @@ return widget.apiCheckValid(); } ); $.when.apply( $, promises ).then( function () { - that.apiIsValid = $.inArray( false, arguments ) === -1; + that.apiIsValid = Array.prototype.indexOf.call( arguments, false ) === -1; if ( that.getOutlineItem() ) { that.getOutlineItem().setIcon( that.apiIsValid || suppressErrors ? null : 'alert' ); that.getOutlineItem().setIconTitle( -- 2.20.1