resourceloader: Configure eslint to disallow $ and require inside startup
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 8 Sep 2018 21:41:02 +0000 (22:41 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 8 Sep 2018 22:02:03 +0000 (23:02 +0100)
Would help statically detect accidental use of jQuery ($) before
it is defined within startup. It would also let ESLint in my editor
catch the issue I keep running into where I use a local variable
called 'module' in mediawiki.js before it is defined, which it
doesn't detect because 'module' is whitelisted in the project's
main .eslintrc file. None of the predefined globals for regular
modules are available inside the startup module.

Follows-up dec800968.

Bug: T192623
Change-Id: Icc102d59fff8eb7cd3f4d55f5c8b64866f2bc8af

resources/src/startup/.eslintrc.json [new file with mode: 0644]
resources/src/startup/mediawiki.log.js
resources/src/startup/mediawiki.requestIdleCallback.js
resources/src/startup/profiler.js
resources/src/startup/startup.js

diff --git a/resources/src/startup/.eslintrc.json b/resources/src/startup/.eslintrc.json
new file mode 100644 (file)
index 0000000..c085e60
--- /dev/null
@@ -0,0 +1,10 @@
+{
+       "root": true,
+       "extends": "wikimedia",
+       "env": {
+               "browser": true
+       },
+       "rules": {
+               "max-len": 0
+       }
+}
index af59c7f..9283b16 100644 (file)
@@ -7,7 +7,7 @@
  * @author Trevor Parscal <tparscal@wikimedia.org>
  */
 ( function () {
-       /* global console */
+       /* global console, mw */
        /* eslint-disable no-console */
        var original = mw.log;
 
index 9f8c598..afb4737 100644 (file)
@@ -1,3 +1,4 @@
+/* global mw */
 ( function () {
        var maxBusy = 50;
 
@@ -44,7 +45,8 @@
         *  by that time.
         */
        mw.requestIdleCallback = window.requestIdleCallback ?
-               window.requestIdleCallback.bind( window ) : // Bind because it throws TypeError if context is not window
+               // Bind because it throws TypeError if context is not window
+               window.requestIdleCallback.bind( window ) :
                mw.requestIdleCallbackInternal;
        // Note: Polyfill was previously disabled due to
        // https://bugs.chromium.org/p/chromium/issues/detail?id=647870
index 588750c..5e9b6ab 100644 (file)
@@ -4,6 +4,7 @@
  * @author Timo Tijhof
  * @since 1.32
  */
+/* global mw */
 ( function () {
        'use strict';
 
index 8e75535..5483ad2 100644 (file)
@@ -110,6 +110,7 @@ if ( !isCompatible() ) {
         * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
         */
        ( function () {
+               /* global mw */
                mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
 
                $CODE.registrations();