Remove jQuery.inArray usages
authorpetarpetkovic <ppetkovic@wikimedia.org>
Fri, 24 Aug 2018 22:37:07 +0000 (00:37 +0200)
committerpetarpetkovic <ppetkovic@wikimedia.org>
Mon, 3 Sep 2018 11:19:14 +0000 (13:19 +0200)
Replace jQuery.inArray with Array.prototype.indexOf.

Also enforce this via eslint rule.

Bug: T200877
Change-Id: Idbd06e6a1681300c4ab9142c7b57e4376f474041

.eslintrc.json
resources/src/mediawiki.Title/Title.js
resources/src/mediawiki.legacy/protect.js
resources/src/mediawiki.special.apisandbox/apisandbox.js

index da5d409..fbf2a5a 100644 (file)
                                "property": "map",
                                "message": "Please use Array.prototype.map instead"
                        },
+                       {
+                               "object": "$",
+                               "property": "inArray",
+                               "message": "Please use Array.prototype.indexOf instead"
+                       },
                        {
                                "object": "$",
                                "property": "isArray",
index 1d0aa67..4491634 100644 (file)
                 */
                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;
index cb4edc1..676ddb0 100644 (file)
                 * @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;
                },
 
                /**
index 52abb30..beac624 100644 (file)
                                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(