Fix eslint warnings and switch to error code
[lhc/web/wiklou.git] / resources / src / mediawiki.inspect.js
index cf94083..cec537f 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Tools for inspecting page composition and performance.
+ * The mediawiki.inspect module.
  *
  * @author Ori Livneh
  * @since 1.22
@@ -9,7 +9,19 @@
 
 ( function ( mw, $ ) {
 
-       var inspect,
+       // mw.inspect is a singleton class with static methods
+       // that itself can also be invoked as a function (mediawiki.base/mw#inspect).
+       // In JavaScript, that is implemented by starting with a function,
+       // and subsequently setting additional properties on the function object.
+
+       /**
+        * Tools for inspecting page composition and performance.
+        *
+        * @class mw.inspect
+        * @singleton
+        */
+
+       var inspect = mw.inspect,
                byteLength = require( 'mediawiki.String' ).byteLength,
                hasOwn = Object.prototype.hasOwnProperty;
 
                return bytes.toFixed( i > 0 ? 1 : 0 ) + units[ i ];
        }
 
-       /**
-        * @class mw.inspect
-        * @singleton
-        */
-       inspect = {};
-
        /**
         * Return a map of all dependency relationships between loaded modules.
         *
                        Object.keys( inspect.reports );
 
                reports.forEach( function ( name ) {
+                       if ( console.group ) {
+                               console.group( 'mw.inspect ' + name + ' report' );
+                       } else {
+                               console.log( 'mw.inspect ' + name + ' report' );
+                       }
                        inspect.dumpTable( inspect.reports[ name ]() );
+                       if ( console.group ) {
+                               console.groupEnd( 'mw.inspect ' + name + ' report' );
+                       }
                } );
        };
 
                        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;
                        }
 
                mw.log( 'mw.inspect: reports are not available in debug mode.' );
        }
 
-       mw.inspect = inspect;
-
 }( mediaWiki, jQuery ) );