Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/248933

Change subject: build: Configure jscs and jshint via `npm test`
......................................................................

build: Configure jscs and jshint via `npm test`

...and fix issues spotted.

modules/jquery/ is excluded since those look to be upstream files.

Change-Id: If46b7b76894ed5349aee69f7260f1e93b047c4bd
---
A .jshintignore
M .jshintrc
M Gruntfile.js
M modules/article/ext.proofreadpage.article.js
M modules/index/ext.proofreadpage.index.js
M modules/page/ext.proofreadpage.page.edit.js
M modules/page/ext.proofreadpage.page.navigation.js
M package.json
8 files changed, 149 insertions(+), 111 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/33/248933/1

diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/.jshintrc b/.jshintrc
index 9e26dfe..d3e70a4 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1 +1,21 @@
-{}
\ No newline at end of file
+{
+       // Enforcing
+       "bitwise": true,
+       "eqeqeq": true,
+       "es3": true,
+       "freeze": true,
+       "latedef": true,
+       "noarg": true,
+       "nonew": true,
+       "undef": true,
+       "unused": true,
+
+       // Environment
+       "browser": true,
+
+       "globals": {
+               "mediaWiki": false,
+               "jQuery": false
+       }
+}
+
diff --git a/Gruntfile.js b/Gruntfile.js
index 9c56558..b415568 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -2,6 +2,8 @@
 module.exports = function ( grunt ) {
        grunt.loadNpmTasks( 'grunt-banana-checker' );
        grunt.loadNpmTasks( 'grunt-jsonlint' );
+       grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+       grunt.loadNpmTasks( 'grunt-jscs' );
 
        grunt.initConfig( {
                banana: {
@@ -12,9 +14,22 @@
                                '**/*.json',
                                '!node_modules/**'
                        ]
+               },
+               jshint: {
+                       options: {
+                               jshintrc: true
+                       },
+                       all: [
+                               '*.js',
+                               'modules/**/*.js',
+                               '!modules/jquery/*.js'
+                       ]
+               },
+               jscs: {
+                       src: '<%= jshint.all %>'
                }
        } );
 
-       grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
+       grunt.registerTask( 'test', [ 'jsonlint', 'banana', 'jshint', 'jscs' ] 
);
        grunt.registerTask( 'default', 'test' );
 };
diff --git a/modules/article/ext.proofreadpage.article.js 
b/modules/article/ext.proofreadpage.article.js
index 11c6e50..d3c07cc 100644
--- a/modules/article/ext.proofreadpage.article.js
+++ b/modules/article/ext.proofreadpage.article.js
@@ -1,9 +1,9 @@
 ( function ( mw, $ ) {
        'use strict';
 
-       $( document ).ready( function() {
+       $( document ).ready( function () {
                /* add backlink to index page */
                $( '#ca-nstab-main' ).after( '<li 
id="ca-proofread-source"><span>' + mw.config.get( 'proofreadpage_source_href' ) 
+ '</span></li>' );
        } );
 
-} ( mediaWiki, jQuery ) );
\ No newline at end of file
+}( mediaWiki, jQuery ) );
diff --git a/modules/index/ext.proofreadpage.index.js 
b/modules/index/ext.proofreadpage.index.js
index 46deb64..4610eff 100644
--- a/modules/index/ext.proofreadpage.index.js
+++ b/modules/index/ext.proofreadpage.index.js
@@ -1,11 +1,11 @@
 ( function ( mw, $ ) {
        'use strict';
 
-       $( document ).ready( function() {
+       $( document ).ready( function () {
                // Set up the help system
                $( '.prp-help-field' ).tipsy( {
-                       'gravity': 'nw'
+                       gravity: 'nw'
                } );
        } );
 
-} ( mediaWiki, jQuery ) );
\ No newline at end of file
+}( mediaWiki, jQuery ) );
diff --git a/modules/page/ext.proofreadpage.page.edit.js 
b/modules/page/ext.proofreadpage.page.edit.js
index 5bce78a..0b6e66f 100644
--- a/modules/page/ext.proofreadpage.page.edit.js
+++ b/modules/page/ext.proofreadpage.page.edit.js
@@ -5,24 +5,24 @@
         * Is the layout horizontal (ie is the scan image on top of the edit 
area)
         * @type {boolean}
         */
-       var isLayoutHorizontal = false;
+       var isLayoutHorizontal = false,
 
        /**
         * The scan image
         * @type {jQuery}
         */
-       var $zoomImage;
+       $zoomImage,
 
        /**
         * The edit form
         * @type {jQuery}
         */
-       var $editForm;
+       $editForm;
 
        /**
         * Show or hide header and footer areas
         *
-        * @param speed string speed of the toggle. May be 'fast', 'slow' or 
undefined
+        * @param {string} speed string speed of the toggle. May be 'fast', 
'slow' or undefined
         */
        function toggleHeaders( speed ) {
                $editForm.find( '.prp-page-edit-header' ).toggle( speed );
@@ -34,13 +34,13 @@
         * Put the scan image on top or on the left of the edit area
         */
        function toggleLayout() {
-               if( $zoomImage.data( 'prpZoom' ) ) {
+               if ( $zoomImage.data( 'prpZoom' ) ) {
                        $zoomImage.prpZoom( 'destroy' );
                }
 
                var $container = $zoomImage.parent();
 
-               if( isLayoutHorizontal ) {
+               if ( isLayoutHorizontal ) {
                        $container.appendTo( $editForm.find( 
'.prp-page-container' ) );
 
                        $container.css( {
@@ -79,10 +79,10 @@
         * Apply user preferences
         */
        function setupPreferences() {
-               if( !mw.user.options.get( 'proofreadpage-showheaders' ) ) {
+               if ( !mw.user.options.get( 'proofreadpage-showheaders' ) ) {
                        toggleHeaders();
                }
-               if( mw.user.options.get( 'proofreadpage-horizontal-layout' ) ) {
+               if ( mw.user.options.get( 'proofreadpage-horizontal-layout' ) ) 
{
                        toggleLayout();
                }
        }
@@ -91,10 +91,10 @@
         * Init the automatic fill of the summary input box
         */
        function setupPageQuality() {
-               $( 'input[name="wpQuality"]' ).click( function() {
-                       var $summary = $( '#wpSummary' );
-                       var pageQuality = mw.message( 'proofreadpage_quality' + 
this.value + '_category').plain();
-                       var summary = $summary.val().replace( /\/\*.*\*\/\s?/, 
'' );
+               $( 'input[name="wpQuality"]' ).click( function () {
+                       var $summary = $( '#wpSummary' ),
+                               pageQuality = mw.message( 
'proofreadpage_quality' + this.value + '_category' ).plain(),
+                               summary = $summary.val().replace( 
/\/\*.*\*\/\s?/, '' );
                        $summary.val( '/* ' + pageQuality + ' */ ' + summary );
                } );
        }
@@ -103,81 +103,81 @@
         * Add some buttons to the toolbar
         */
        function addButtons() {
-               var iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + 
'/ProofreadPage/modules/page/images/';
-               var tools = {
-                       zoom: {
-                               labelMsg: 'proofreadpage-group-zoom',
-                               tools: {
-                                       'zoom-in': {
-                                               labelMsg: 
'proofreadpage-button-zoom-in-label',
-                                               type: 'button',
-                                               icon: iconPath + 
'wikieditor-zoom-in.png',
-                                               oldIcon: iconPath + 
'Button_zoom_in.png',
-                                               action: {
-                                                       type: 'callback',
-                                                       execute: function() {
-                                                               
$zoomImage.prpZoom( 'zoomIn' );
+               var iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + 
'/ProofreadPage/modules/page/images/',
+                       tools = {
+                               zoom: {
+                                       labelMsg: 'proofreadpage-group-zoom',
+                                       tools: {
+                                               'zoom-in': {
+                                                       labelMsg: 
'proofreadpage-button-zoom-in-label',
+                                                       type: 'button',
+                                                       icon: iconPath + 
'wikieditor-zoom-in.png',
+                                                       oldIcon: iconPath + 
'Button_zoom_in.png',
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
function () {
+                                                                       
$zoomImage.prpZoom( 'zoomIn' );
+                                                               }
+                                                       }
+                                               },
+                                               'zoom-out': {
+                                                       labelMsg: 
'proofreadpage-button-zoom-out-label',
+                                                       type: 'button',
+                                                       icon: iconPath + 
'wikieditor-zoom-out.png',
+                                                       oldIcon: iconPath + 
'Button_zoom_out.png',
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
function () {
+                                                                       
$zoomImage.prpZoom( 'zoomOut' );
+                                                               }
+                                                       }
+                                               },
+                                               'reset-zoom': {
+                                                       labelMsg: 
'proofreadpage-button-reset-zoom-label',
+                                                       type: 'button',
+                                                       icon: iconPath + 
'wikieditor-zoom-reset.png',
+                                                       oldIcon: iconPath + 
'Button_examine.png',
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
function () {
+                                                                       
$zoomImage.prpZoom( 'reset' );
+                                                               }
                                                        }
                                                }
-                                       },
-                                       'zoom-out': {
-                                               labelMsg: 
'proofreadpage-button-zoom-out-label',
-                                               type: 'button',
-                                               icon: iconPath + 
'wikieditor-zoom-out.png',
-                                               oldIcon: iconPath + 
'Button_zoom_out.png',
-                                               action: {
-                                                       type: 'callback',
-                                                       execute: function() {
-                                                               
$zoomImage.prpZoom( 'zoomOut' );
+                                       }
+                               },
+                               other: {
+                                       labelMsg: 'proofreadpage-group-other',
+                                       tools: {
+                                               'toggle-visibility': {
+                                                       labelMsg: 
'proofreadpage-button-toggle-visibility-label',
+                                                       type: 'button',
+                                                       icon: iconPath + 
'wikieditor-visibility.png',
+                                                       oldIcon: iconPath + 
'Button_category_plus.png',
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
function () {
+                                                                       
toggleHeaders( 'fast' );
+                                                               }
                                                        }
-                                               }
-                                       },
-                                       'reset-zoom': {
-                                               labelMsg: 
'proofreadpage-button-reset-zoom-label',
-                                               type: 'button',
-                                               icon: iconPath + 
'wikieditor-zoom-reset.png',
-                                               oldIcon: iconPath + 
'Button_examine.png',
-                                               action: {
-                                                       type: 'callback',
-                                                       execute: function() {
-                                                               
$zoomImage.prpZoom( 'reset' );
+                                               },
+                                               'toggle-layout': {
+                                                       labelMsg: 
'proofreadpage-button-toggle-layout-label',
+                                                       type: 'button',
+                                                       icon: iconPath + 
'wikieditor-layout.png',
+                                                       oldIcon: iconPath + 
'Button_multicol.png',
+                                                       action: {
+                                                               type: 
'callback',
+                                                               execute: 
toggleLayout
                                                        }
                                                }
                                        }
                                }
                        },
-                       other: {
-                               labelMsg: 'proofreadpage-group-other',
-                               tools: {
-                                       'toggle-visibility': {
-                                               labelMsg: 
'proofreadpage-button-toggle-visibility-label',
-                                               type: 'button',
-                                               icon: iconPath + 
'wikieditor-visibility.png',
-                                               oldIcon: iconPath + 
'Button_category_plus.png',
-                                               action: {
-                                                       type: 'callback',
-                                                       execute: function() {
-                                                               toggleHeaders( 
'fast' );
-                                                       }
-                                               }
-                                       },
-                                       'toggle-layout': {
-                                               labelMsg: 
'proofreadpage-button-toggle-layout-label',
-                                               type: 'button',
-                                               icon: iconPath + 
'wikieditor-layout.png',
-                                               oldIcon: iconPath + 
'Button_multicol.png',
-                                               action: {
-                                                       type: 'callback',
-                                                       execute: toggleLayout
-                                               }
-                                       }
-                               }
-                       }
-               };
+                       $edit = $( '#wpTextbox1' );
 
-               var $edit = $( '#wpTextbox1' );
-               if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { //"== 1" 
in order to disallow both 0 and "0"
-                       mw.loader.using( 'ext.wikiEditor.toolbar', function() {
+               if ( mw.user.options.get( 'usebetatoolbar' ) === 1 ) {
+                       mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $edit.wikiEditor( 'addToToolbar', {
                                        sections: {
                                                'proofreadpage-tools': {
@@ -188,12 +188,12 @@
                                        }
                                } );
                        } );
-               } else if ( mw.user.options.get( 'showtoolbar' ) == 1 ) {
-                       mw.loader.using( 'mediawiki.action.edit', function() {
+               } else if ( mw.user.options.get( 'showtoolbar' ) === 1 ) {
+                       mw.loader.using( 'mediawiki.action.edit', function () {
                                var $toolbar = $( '#toolbar' );
 
-                               $.each( tools, function( group, list ) {
-                                       $.each( list.tools, function( id, def ) 
{
+                               $.each( tools, function ( group, list ) {
+                                       $.each( list.tools, function ( id, def 
) {
                                                $( '<img>' )
                                                        .attr( {
                                                                width: 23,
@@ -201,7 +201,7 @@
                                                                src: 
def.oldIcon,
                                                                alt: mw.msg( 
def.labelMsg ),
                                                                title: mw.msg( 
def.labelMsg ),
-                                                               'class': 
'mw-toolbar-editbutton' //quotes needed for IE
+                                                               'class': 
'mw-toolbar-editbutton' // quotes needed for IE
                                                        } )
                                                        .click( 
def.action.execute )
                                                        .appendTo( $toolbar );
@@ -216,18 +216,18 @@
         */
        function setupWikiEditor() {
                // Ignore "showtoolbar", for consistency with the default 
behavior (bug 30795)
-               if( !mw.user.options.get( 'usebetatoolbar' ) ) {
+               if ( !mw.user.options.get( 'usebetatoolbar' ) ) {
                        return;
                }
-               mw.loader.using( 'ext.wikiEditor', function() {
+               mw.loader.using( 'ext.wikiEditor', function () {
                        $editForm.find( '.prp-page-edit-body' ).append( $( 
'#wpTextbox1' ) );
                        $editForm.find( '.editOptions' ).before( 
$editForm.find( '.wikiEditor-ui' ) );
                        $editForm.find( '.wikiEditor-ui-text' ).append( 
$editForm.find( '.prp-page-container' ) );
                } );
 
                // load the "dialogs" module of WikiEditor if enabled , bug: 
72960
-               if( mw.user.options.get( 'usebetatoolbar-cgd' ) ) {
-                       mw.loader.load('ext.wikiEditor.dialogs');
+               if ( mw.user.options.get( 'usebetatoolbar-cgd' ) ) {
+                       mw.loader.load( 'ext.wikiEditor.dialogs' );
                }
                // TODO: other modules of WikiEditor may miss, see bug 72960.
        }
@@ -236,10 +236,10 @@
         * Init global variables of the script
         */
        function initEnvironment() {
-               if( $editForm === undefined ) {
+               if ( $editForm === undefined ) {
                        $editForm = $( '#editform' );
                }
-               if( $zoomImage === undefined ) {
+               if ( $zoomImage === undefined ) {
                        $zoomImage = $editForm.find( '.prp-page-image img' );
                }
        }
@@ -248,12 +248,12 @@
         * Init the zoom system
         */
        function initZoom() {
-               mw.loader.using( 'jquery.prpZoom', function() {
+               mw.loader.using( 'jquery.prpZoom', function () {
                        $zoomImage.prpZoom();
                } );
        }
 
-       $( document ).ready( function() {
+       $( document ).ready( function () {
                initEnvironment();
                setupWikiEditor();
                setupPreferences();
@@ -261,10 +261,10 @@
                addButtons();
        } );
 
-       //zoom should be init after the page is rendered
-       $( window ).load( function() {
+       // zoom should be init after the page is rendered
+       $( window ).load( function () {
                initEnvironment();
                initZoom();
        } );
 
-} ( mediaWiki, jQuery ) );
+}( mediaWiki, jQuery ) );
diff --git a/modules/page/ext.proofreadpage.page.navigation.js 
b/modules/page/ext.proofreadpage.page.navigation.js
index 73741cd..12d44ea 100644
--- a/modules/page/ext.proofreadpage.page.navigation.js
+++ b/modules/page/ext.proofreadpage.page.navigation.js
@@ -4,10 +4,10 @@
        /**
         * Get the selector for the main tabs container
         *
-        * @return string
+        * @return {string}
         */
        function getTabsContainerSelector() {
-               switch( mw.config.get( 'skin' ) ) {
+               switch ( mw.config.get( 'skin' ) ) {
                        case 'vector':
                                return '#p-namespaces ul';
                        case 'monobook':
@@ -22,21 +22,21 @@
         * Improve the tabs presentation
         */
        function initTabs() {
-               //Move prev and next links
+               // Move prev and next links
                $( getTabsContainerSelector() )
-                       .prepend( $( '#ca-proofreadPageNextLink') )
-                       .prepend( $( '#ca-proofreadPagePrevLink') );
+                       .prepend( $( '#ca-proofreadPageNextLink' ) )
+                       .prepend( $( '#ca-proofreadPagePrevLink' ) );
 
-               //add title attribute to links move to icon
+               // add title attribute to links move to icon
                var tabsToIcon = [ 'proofreadPagePrevLink', 
'proofreadPageNextLink', 'proofreadPageIndexLink' ];
-               $.each( tabsToIcon, function( i, id ) {
+               $.each( tabsToIcon, function ( i, id ) {
                        var $link = $( '#ca-' + id + '.icon a' );
                        $link.attr( 'title', $link.text() );
                } );
        }
 
-       $( document ).ready( function() {
+       $( document ).ready( function () {
                initTabs();
        } );
 
-} ( mediaWiki, jQuery ) );
\ No newline at end of file
+}( mediaWiki, jQuery ) );
diff --git a/package.json b/package.json
index 0bf6c86..449e9d7 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,8 @@
     "grunt": "0.4.5",
     "grunt-cli": "0.1.13",
     "grunt-banana-checker": "0.4.0",
-    "grunt-jsonlint": "1.0.5"
+    "grunt-jsonlint": "1.0.5",
+    "grunt-contrib-jshint": "0.11.3",
+    "grunt-jscs": "2.1.0"
   }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/248933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If46b7b76894ed5349aee69f7260f1e93b047c4bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to