Fix eslint warnings and switch to error code
authorjdlrobson <jdlrobson@gmail.com>
Tue, 14 Aug 2018 22:50:41 +0000 (15:50 -0700)
committerjdlrobson <jdlrobson@gmail.com>
Tue, 14 Aug 2018 23:13:44 +0000 (16:13 -0700)
Follow up to I4552191f639b1022cb085ef5eb4abda835c2d91c

* Add eslint-ignores to various files
* Correct various uses of isFunction, trim, map, grep
where easy fix is available
* Switch from eslint warning to error

Bug: T200877
Change-Id: I8420db21e548772332e51769aa8ec92d5958715f

18 files changed:
.eslintrc.json
resources/src/jquery/jquery.lengthLimit.js
resources/src/jquery/jquery.suggestions.js
resources/src/mediawiki.confirmCloseWindow.js
resources/src/mediawiki.htmlform/autocomplete.js
resources/src/mediawiki.inspect.js
resources/src/mediawiki.jqueryMsg/mediawiki.jqueryMsg.js
resources/src/mediawiki.legacy/protect.js
resources/src/mediawiki.searchSuggest/searchSuggest.js
resources/src/mediawiki.special.apisandbox/apisandbox.js
resources/src/mediawiki.userSuggest.js
resources/src/mediawiki.widgets.datetime/DateTimeFormatter.js
resources/src/mediawiki.widgets.datetime/DiscordianDateTimeFormatter.js
resources/src/mediawiki.widgets.datetime/ProlepticGregorianDateTimeFormatter.js
resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js

index e24fa83..da5d409 100644 (file)
@@ -12,7 +12,7 @@
        },
        "rules": {
                "no-restricted-properties": [
-                       1,
+                       2,
                        {
                                "object": "$",
                                "property": "map",
index 186ad17..3823395 100644 (file)
 
                // If the first argument is the function,
                // set filterFn to the first argument's value and ignore the second argument.
-               if ( $.isFunction( limit ) ) {
+               if ( typeof limit === 'function' ) {
                        filterFn = limit;
                        limit = undefined;
                // Either way, verify it is a function so we don't have to call
                // isFunction again after this.
-               } else if ( !filterFn || !$.isFunction( filterFn ) ) {
+               } else if ( !filterFn || typeof filterFn !== 'function' ) {
                        filterFn = undefined;
                }
 
index 39c601f..663950a 100644 (file)
                        if ( context.data.timerID !== null ) {
                                clearTimeout( context.data.timerID );
                        }
-                       if ( $.isFunction( context.config.cancel ) ) {
+                       if ( typeof context.config.cancel === 'function' ) {
                                context.config.cancel.call( context.data.$textbox );
                        }
                },
index ee3bac2..4510b2c 100644 (file)
@@ -47,7 +47,7 @@
                        showEventName += '.' + options.namespace;
                }
 
-               if ( $.isFunction( options.message ) ) {
+               if ( typeof options.message === 'function' ) {
                        message = options.message();
                } else {
                        message = options.message;
index 8157975..2f62371 100644 (file)
@@ -12,7 +12,7 @@
                                        fetch: function ( val ) {
                                                var $el = $( this );
                                                $el.suggestions( 'suggestions',
-                                                       $.grep( $el.data( 'autocomplete' ), function ( v ) {
+                                                       $el.data( 'autocomplete' ).filter( function ( v ) {
                                                                return v.indexOf( val ) === 0;
                                                        } )
                                                );
index b30a30e..cec537f 100644 (file)
                        var module = mw.loader.moduleRegistry[ moduleName ];
 
                        // Grep module's JavaScript
-                       if ( $.isFunction( module.script ) && pattern.test( module.script.toString() ) ) {
+                       if ( typeof module.script === 'function' && pattern.test( module.script.toString() ) ) {
                                return true;
                        }
 
index 437800a..74fb7d6 100644 (file)
@@ -1,3 +1,4 @@
+/* eslint-disable no-restricted-properties */
 /*!
 * Experimental advanced wikitext parser-emitter.
 * See: https://www.mediawiki.org/wiki/Extension:UploadWizard/MessageParser for docs
index b96bebc..cb4edc1 100644 (file)
@@ -1,3 +1,4 @@
+/* eslint-disable no-restricted-properties */
 ( function ( mw, $ ) {
        var ProtectionForm,
                reasonCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ),
index e7859cf..bd94f29 100644 (file)
@@ -1,3 +1,4 @@
+/* eslint-disable no-restricted-properties */
 /*!
  * Add search suggestions to the search form.
  */
index 7c0d232..52abb30 100644 (file)
@@ -1,3 +1,4 @@
+/* eslint-disable no-restricted-properties */
 ( function ( $, mw, OO ) {
        'use strict';
        var ApiSandbox, Util, WidgetMethods, Validators,
index 99e9dbe..43f0552 100644 (file)
@@ -19,7 +19,7 @@
                                auprefix: userInput[ 0 ].toUpperCase() + userInput.slice( 1 ),
                                aulimit: maxRows
                        } ).done( function ( data ) {
-                               var users = $.map( data.query.allusers, function ( userObj ) {
+                               var users = data.query.allusers.map( function ( userObj ) {
                                        return userObj.name;
                                } );
                                response( users );
index 6ee9595..44a7d61 100644 (file)
                                // Workaround T97096 by setting uselang=content
                                uselang: 'content'
                        } ).then( function ( data ) {
-                               return $.map( data.query.interwikimap, function ( interwiki ) {
+                               return data.query.interwikimap.map( function ( interwiki ) {
                                        return interwiki.prefix;
                                } );
                        } );
index 50fd581..e4cf446 100644 (file)
        QUnit.test( 'Match PHP parser', function ( assert ) {
                var tasks;
                mw.messages.set( mw.libs.phpParserData.messages );
-               tasks = $.map( mw.libs.phpParserData.tests, function ( test ) {
+               tasks = mw.libs.phpParserData.tests.map( function ( test ) {
                        var done = assert.async();
                        return function ( next, abort ) {
                                getMwLanguage( test.lang )
index 8a5e68a..f0a3543 100644 (file)
@@ -1,4 +1,4 @@
-( function ( mw, $ ) {
+( function ( mw ) {
        QUnit.module( 'mediawiki.user', QUnit.newMwEnvironment( {
                setup: function () {
                        this.server = this.sandbox.useFakeServer();
@@ -69,7 +69,7 @@
 
                result = mw.user.generateRandomSessionId();
                assert.strictEqual( typeof result, 'string', 'type' );
-               assert.strictEqual( $.trim( result ), result, 'no whitespace at beginning or end' );
+               assert.strictEqual( result.trim(), result, 'no whitespace at beginning or end' );
                assert.strictEqual( result.length, 16, 'size' );
 
                result2 = mw.user.generateRandomSessionId();
@@ -90,7 +90,7 @@
 
                result = mw.user.generateRandomSessionId();
                assert.strictEqual( typeof result, 'string', 'type' );
-               assert.strictEqual( $.trim( result ), result, 'no whitespace at beginning or end' );
+               assert.strictEqual( result.trim(), result, 'no whitespace at beginning or end' );
                assert.strictEqual( result.length, 16, 'size' );
 
                result2 = mw.user.generateRandomSessionId();
                var result = mw.user.sessionId(),
                        result2 = mw.user.sessionId();
                assert.strictEqual( typeof result, 'string', 'type' );
-               assert.strictEqual( $.trim( result ), result, 'no leading or trailing whitespace' );
+               assert.strictEqual( result.trim(), result, 'no leading or trailing whitespace' );
                assert.strictEqual( result2, result, 'retained' );
        } );
-}( mediaWiki, jQuery ) );
+}( mediaWiki ) );