jenkins-bot has submitted this change and it was merged.

Change subject: build: Enable jshint and jscs jobs in npm, and make pass
......................................................................


build: Enable jshint and jscs jobs in npm, and make pass

Files in mediawiki.libs.recorderjs were left unchanged.

Bug: T56907
Change-Id: I1b10e3d53121dae709dd4ef0abe7a265426a98bf
---
A .jscsrc
A .jshintignore
A .jshintrc
M Gruntfile.js
M package.json
M resources/ext.pronunciationRecording.fileDetails.js
M resources/ext.pronunciationRecording.pronunciationRecorder.js
M resources/ext.pronunciationRecording.specialPage.js
8 files changed, 136 insertions(+), 92 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.jscsrc b/.jscsrc
new file mode 100644
index 0000000..9d22e3f
--- /dev/null
+++ b/.jscsrc
@@ -0,0 +1,3 @@
+{
+       "preset": "wikimedia"
+}
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..a1581ce
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1,2 @@
+resources/mediawiki.libs.recorderjs
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..b44b4e7
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,25 @@
+{
+       // Enforcing
+       "bitwise": true,
+       "eqeqeq": true,
+       "freeze": true,
+       "latedef": true,
+       "noarg": true,
+       "nonew": true,
+       "undef": true,
+       "unused": true,
+       "strict": false,
+
+       // Relaxing
+       "es5": false,
+
+       // Environment
+       "browser": true,
+       "jquery": true,
+
+       "globals": {
+               "mediaWiki": false,
+               "Recorder": false,
+               "AudioContext": false
+       }
+}
diff --git a/Gruntfile.js b/Gruntfile.js
index d2885f6..456e3ef 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -7,10 +7,25 @@
 /*jshint node:true */
 module.exports = function ( grunt ) {
        grunt.loadNpmTasks( 'grunt-banana-checker' );
+       grunt.loadNpmTasks( 'grunt-contrib-jshint' );
        grunt.loadNpmTasks( 'grunt-contrib-watch' );
+       grunt.loadNpmTasks( 'grunt-jscs' );
        grunt.loadNpmTasks( 'grunt-jsonlint' );
 
        grunt.initConfig( {
+               jshint: {
+                       options: {
+                               jshintrc: true
+                       },
+                       all: [
+                               '*.js',
+                               '{.docs,build}/**/*.js',
+                               'resources/*.js'
+                       ]
+               },
+               jscs: {
+                       src: '<%= jshint.all %>'
+               },
                jsonlint: {
                        all: 'i18n/*.json'
                },
@@ -19,12 +34,14 @@
                },
                watch: {
                        files: [
+                               '.{jscsrc,jshintignore,jshintrc}',
+                               '<%= jshint.all %>',
                                '<%= jsonlint.all %>'
                        ],
                        tasks: 'test'
                }
        } );
 
-       grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
+       grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] 
);
        grunt.registerTask( 'default', 'test' );
 };
diff --git a/package.json b/package.json
index 4e040f5..f43a534 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,9 @@
   "devDependencies": {
     "grunt": "0.4.5",
     "grunt-banana-checker": "0.2.2",
+    "grunt-contrib-jshint": "0.11.2",
     "grunt-contrib-watch": "0.6.1",
+    "grunt-jscs": "2.1.0",
     "grunt-jsonlint": "1.0.4"
   }
 }
diff --git a/resources/ext.pronunciationRecording.fileDetails.js 
b/resources/ext.pronunciationRecording.fileDetails.js
index 91862de..a05b523 100644
--- a/resources/ext.pronunciationRecording.fileDetails.js
+++ b/resources/ext.pronunciationRecording.fileDetails.js
@@ -1,36 +1,34 @@
-( function ( mw, $ ) {
-       mw.PronunciationRecorderFileDetails = function( word, username, 
lang_code ) {
-               var description, date_obj, fulldate, source, author, 
permission, category, lang_subst = "{{subst:#language:" + lang_code + "|en}}";
-               date_obj = new Date();
-               description = "Pronunciation of the term '" + word + "' in " + 
lang_subst;
+( function ( mw ) {
+       mw.PronunciationRecorderFileDetails = function ( word, username, 
langCode ) {
+               var description, dateObj, fulldate, source, author, permission, 
category, langSubst = '{{subst:#language:' + langCode + '|en}}';
+               dateObj = new Date();
+               description = 'Pronunciation of the term \'' + word + '\' in ' 
+ langSubst;
 
                function pad( param ) {
-                       if( param < 10 ) {
+                       if ( param < 10 ) {
                                return '0' + param;
                        } else {
                                return param;
                        }
                }
 
-               fulldate = date_obj.getFullYear() + "-" + pad( 
date_obj.getMonth() + 1 ) + "-" + pad( date_obj.getDate() );
+               fulldate = dateObj.getFullYear() + '-' + pad( 
dateObj.getMonth() + 1 ) + '-' + pad( dateObj.getDate() );
                source = '{{Created with PronunciationRecording}}';
                author = '[[User:' + username + '|' + username + ']]';
                permission = '{{Cc-by-sa-3.0}}';
-               category = '[[Category:' + lang_subst + ' pronunciation|' + 
word + ']]';
+               category = '[[Category:' + langSubst + ' pronunciation|' + word 
+ ']]';
 
                return {
-                       generateWikiText: function()
-                       {
+                       generateWikiText: function () {
                                var wikitext = '{{Information\n |description = 
' + description + '\n |date = ' + fulldate + '\n |source = ' + source + '\n 
|author = ' + author + '\n |permission = ' + permission + '\n}}\n' + category;
                                return wikitext;
                        },
 
-                       generateFileName: function()
-                       {
-                               var filename = lang_code + '-' + word + '.wav';
+                       generateFileName: function () {
+                               var filename = langCode + '-' + word + '.wav';
                                return filename;
 
                        }
-               }
-       }
-} ( mediaWiki, jQuery ) );
+               };
+       };
+}( mediaWiki, jQuery ) );
diff --git a/resources/ext.pronunciationRecording.pronunciationRecorder.js 
b/resources/ext.pronunciationRecording.pronunciationRecorder.js
index a010d18..4a50520 100644
--- a/resources/ext.pronunciationRecording.pronunciationRecorder.js
+++ b/resources/ext.pronunciationRecording.pronunciationRecorder.js
@@ -1,13 +1,14 @@
 ( function ( mw, $ ) {
-       mw.PronunciationRecorder = function( ) {
+       mw.PronunciationRecorder = function ( ) {
 
                var audioContext, recorder, uploadHandler, uploadWizardUpload, 
cachedBlob,
                        userAgent = mw.message( 'pronunciationrecording-title' 
).text();
 
                function startUserMedia( stream ) {
-                       $( ".mw-pronunciationrecording-record" 
).removeAttr('disabled');
-                       $( ".mw-pronunciationrecording-message" ).empty();
-                       var input = audioContext.createMediaStreamSource( 
stream );
+                       var input;
+                       $( '.mw-pronunciationrecording-record' ).removeAttr( 
'disabled' );
+                       $( '.mw-pronunciationrecording-message' ).empty();
+                       input = audioContext.createMediaStreamSource( stream );
                        mw.log( 'Media Stream created' );
                        try {
                                // This call may fail if not all APIs necessary 
are supported.
@@ -19,12 +20,11 @@
                        }
                }
                function getBlob( callback ) {
-                       if( cachedBlob ) {
+                       if ( cachedBlob ) {
                                callback( cachedBlob );
-                       }
-                       else {
+                       } else {
                                recorder.exportWAV(
-                                       function( blob ) {
+                                       function ( blob ) {
                                                cachedBlob = blob;
                                                callback( cachedBlob );
                                        }
@@ -32,7 +32,7 @@
                        }
                }
 
-               function errorCallBack( e ) {
+               function errorCallBack() {
                        mw.log( 'No live audio input' );
                }
 
@@ -41,18 +41,15 @@
                                action: 'upload',
                                filekey: uploadWizardUpload.fileKey,
                                filename: fileDetails.generateFileName(),
-                               comment: "User created page with " + userAgent,
-                               text : fileDetails.generateWikiText()
+                               comment: 'User created page with ' + userAgent,
+                               text: fileDetails.generateWikiText()
                        };
 
                        function publishOk( response ) {
-                               if( response.upload.result == "Success" )
-                               {
+                               if ( response.upload.result === 'Success' ) {
                                        ok();
                                        mw.log( 'Upload published successfully' 
);
-                               }
-                               else
-                               {
+                               } else {
                                        publishFail();
                                }
                        }
@@ -70,13 +67,13 @@
                        window.AudioContext = window.AudioContext || 
window.webkitAudioContext;
                        navigator.getUserMedia = ( navigator.getUserMedia || 
navigator.webkitGetUserMedia || navigator.mozGetUserMedia || 
navigator.msGetUserMedia );
                        window.URL = window.URL || window.webkitURL;
-                       if ( window.AudioContext ){
+                       if ( window.AudioContext ) {
                                mw.log( 'Audio Context set up' );
                        } else {
                                mw.log( 'WebAudio API is not supported for this 
browser' );
                        }
-                       audioContext = new AudioContext;
-                       if ( navigator.getUserMedia ){
+                       audioContext = new AudioContext();
+                       if ( navigator.getUserMedia ) {
                                mw.log( 'getUserMedia is supported' );
                        } else {
                                mw.log( 'getUserMedia is not supported' );
@@ -85,10 +82,10 @@
                        mw.log( 'WebAudio API is not supported for this 
browser' );
                        throw e;
                }
-               navigator.getUserMedia( {audio: true}, startUserMedia, 
errorCallBack );
+               navigator.getUserMedia( { audio: true }, startUserMedia, 
errorCallBack );
 
                return {
-                       startRecording: function() {
+                       startRecording: function () {
                                if ( !recorder ) {
                                        return mw.log( 'Requested recording 
despite recorder was not initialized.' );
                                }
@@ -97,29 +94,30 @@
                                recorder.record();
                        },
 
-                       stopRecording: function() {
+                       stopRecording: function () {
                                recorder.stop();
                        },
 
-                       createSource: function( callback ) {
+                       createSource: function () {
                                if ( recorder ) {
                                        getBlob(
                                                // this is the asynchronous 
callback that's called when exportWAV finishes encoding
-                                               function( blob ) {
-                                                       var message = $( 
'<br><audio controls class="mw-pronunciationrecording-preview-audio"><source 
src="' + URL.createObjectURL( blob )  + '" type="audio/wav"></audio>' );
-                                                       var upload = $( 
'<br><button class="mw-pronunciationrecording-upload">' + 
mw.message('pronunciationrecording-toolbar-upload-label').escaped() + 
'</button>' );
-                                                       $( 
".mw-pronunciationrecording-preview-div" ).empty();
-                                                       upload.prependTo( 
".mw-pronunciationrecording-preview-div" );
-                                                       message.prependTo( 
".mw-pronunciationrecording-preview-div" );
+                                               function ( blob ) {
+                                                       var message, upload;
+                                                       message = $( 
'<br><audio controls class="mw-pronunciationrecording-preview-audio"><source 
src="' + URL.createObjectURL( blob )  + '" type="audio/wav"></audio>' );
+                                                       upload = $( 
'<br><button class="mw-pronunciationrecording-upload">' + mw.message( 
'pronunciationrecording-toolbar-upload-label' ).escaped() + '</button>' );
+                                                       $( 
'.mw-pronunciationrecording-preview-div' ).empty();
+                                                       upload.prependTo( 
'.mw-pronunciationrecording-preview-div' );
+                                                       message.prependTo( 
'.mw-pronunciationrecording-preview-div' );
                                                }
                                        );
                                }
                        },
 
-                       startUploading: function( ok, error, fileDetails ) {
-                               var config, api, uploadWizard, filesDiv;
-                               config = { 'enableFormData' : true };
-                               filesDiv = document.createElement( "div" );
+                       startUploading: function ( ok, error, fileDetails ) {
+                               var config, uploadWizard, filesDiv;
+                               config = { 'enableFormData': true };
+                               filesDiv = document.createElement( 'div' );
                                uploadWizard = new mw.UploadWizard( config );
                                uploadWizardUpload = new mw.UploadWizardUpload( 
uploadWizard, filesDiv );
 
@@ -133,12 +131,12 @@
                                        populate: $.noop
                                };
                                getBlob(
-                                       function( blob ) {
+                                       function ( blob ) {
                                                uploadWizardUpload.file = blob;
                                                uploadWizardUpload.file.name = 
'upload.wav';
                                                uploadHandler = 
uploadWizardUpload.getUploadHandler();
                                                uploadHandler.start();
-                                               $.subscribeReady( 'thumbnails.' 
+ uploadWizardUpload.index, function() {
+                                               $.subscribeReady( 'thumbnails.' 
+ uploadWizardUpload.index, function () {
                                                        publishUpload( ok, 
error, fileDetails );
                                                } );
                                        }
@@ -146,4 +144,4 @@
                        }
                };
        };
-} ( mediaWiki, jQuery ) );
+}( mediaWiki, jQuery ) );
diff --git a/resources/ext.pronunciationRecording.specialPage.js 
b/resources/ext.pronunciationRecording.specialPage.js
index 4e5d991..2f4a7ac 100644
--- a/resources/ext.pronunciationRecording.specialPage.js
+++ b/resources/ext.pronunciationRecording.specialPage.js
@@ -1,52 +1,51 @@
 ( function ( mw, $ ) {
-       $( document ).ready( function() {
+       $( document ).ready( function () {
+               var pronunciationRecorder;
                try {
-                       var pronunciationRecorder = new 
mw.PronunciationRecorder( );
-                       $( ".mw-pronunciationrecording-message" ).text( 
mw.message( 'pronunciationrecording-mic-access-notify' ).text() );
-                       $( ".mw-pronunciationrecording-record" ).on("click", 
function() {
-                               $( ".mw-pronunciationrecording-record" 
).attr('disabled','disabled');
-                               $( ".mw-pronunciationrecording-stop" 
).removeAttr('disabled');
-                               $( ".mw-pronunciationrecording-message" ).text( 
mw.message( 'pronunciationrecording-recording-notify' ).text() );
+                       pronunciationRecorder = new mw.PronunciationRecorder( );
+                       $( '.mw-pronunciationrecording-message' ).text( 
mw.message( 'pronunciationrecording-mic-access-notify' ).text() );
+                       $( '.mw-pronunciationrecording-record' ).on( 'click', 
function () {
+                               $( '.mw-pronunciationrecording-record' ).attr( 
'disabled', 'disabled' );
+                               $( '.mw-pronunciationrecording-stop' 
).removeAttr( 'disabled' );
+                               $( '.mw-pronunciationrecording-message' ).text( 
mw.message( 'pronunciationrecording-recording-notify' ).text() );
                                pronunciationRecorder.startRecording();
-                       });
-                       $( ".mw-pronunciationrecording-stop" ).on("click", 
function() {
-                               $( ".mw-pronunciationrecording-message" 
).empty();
-                               $( ".mw-pronunciationrecording-stop" 
).attr('disabled','disabled');
-                               $( ".mw-pronunciationrecording-clear" 
).removeAttr('disabled');
+                       } );
+                       $( '.mw-pronunciationrecording-stop' ).on( 'click', 
function () {
+                               $( '.mw-pronunciationrecording-message' 
).empty();
+                               $( '.mw-pronunciationrecording-stop' ).attr( 
'disabled', 'disabled' );
+                               $( '.mw-pronunciationrecording-clear' 
).removeAttr( 'disabled' );
                                pronunciationRecorder.stopRecording();
                                pronunciationRecorder.createSource();
-                       });
-                       $( ".mw-pronunciationrecording-clear" ).on("click", 
function() {
-                               $( ".mw-pronunciationrecording-record" 
).removeAttr('disabled');
-                               $( ".mw-pronunciationrecording-preview-audio" 
).remove();
-                               $( ".mw-pronunciationrecording-upload" 
).remove();
-                               $( ".mw-pronunciationrecording-message" 
).empty();
-                       });
-                       $( document ).on( "click", 
".mw-pronunciationrecording-upload", function() {
-                               var pronunciationRecorderFileDetails, word, 
username, lang_code;
-                               word = $( 
".mw-pronunciationrecording-information-word" ).val();
-                               lang_code = $( 
".mw-pronunciationrecording-information-language" ).val();
+                       } );
+                       $( '.mw-pronunciationrecording-clear' ).on( 'click', 
function () {
+                               $( '.mw-pronunciationrecording-record' 
).removeAttr( 'disabled' );
+                               $( '.mw-pronunciationrecording-preview-audio' 
).remove();
+                               $( '.mw-pronunciationrecording-upload' 
).remove();
+                               $( '.mw-pronunciationrecording-message' 
).empty();
+                       } );
+                       $( document ).on( 'click', 
'.mw-pronunciationrecording-upload', function () {
+                               var pronunciationRecorderFileDetails, word, 
username, langCode;
+                               word = $( 
'.mw-pronunciationrecording-information-word' ).val();
+                               langCode = $( 
'.mw-pronunciationrecording-information-language' ).val();
                                username = mw.user.getName();
-                               pronunciationRecorderFileDetails = new 
mw.PronunciationRecorderFileDetails( word, username, lang_code );
-                               $( ".mw-pronunciationrecording-upload" 
).attr('disabled','disabled');
-                               pronunciationRecorder.startUploading( 
function() {
+                               pronunciationRecorderFileDetails = new 
mw.PronunciationRecorderFileDetails( word, username, langCode );
+                               $( '.mw-pronunciationrecording-upload' ).attr( 
'disabled', 'disabled' );
+                               pronunciationRecorder.startUploading( function 
() {
                                        var name, $fileLink;
                                        name = 'File:' + 
pronunciationRecorderFileDetails.generateFileName() ;
                                        $fileLink = $( '<a>' );
-                                       $fileLink.attr( "href", 
mw.util.wikiGetlink( name ) );
+                                       $fileLink.attr( 'href', 
mw.util.wikiGetlink( name ) );
                                        $fileLink.text( name );
-                                       $( ".mw-pronunciationrecording-message" 
).text( mw.message( 'pronunciationrecording-upload-publish-succeeded' ).text() 
);
-                                       $( ".mw-pronunciationrecording-message" 
).append( " " );
-                                       $( ".mw-pronunciationrecording-message" 
).append( $fileLink );
-                               }, function() {
-                                       $( ".mw-pronunciationrecording-message" 
).text( mw.message( 'pronunciationrecording-upload-publish-failed' ).text() );
+                                       $( '.mw-pronunciationrecording-message' 
).text( mw.message( 'pronunciationrecording-upload-publish-succeeded' ).text() 
);
+                                       $( '.mw-pronunciationrecording-message' 
).append( ' ' );
+                                       $( '.mw-pronunciationrecording-message' 
).append( $fileLink );
+                               }, function () {
+                                       $( '.mw-pronunciationrecording-message' 
).text( mw.message( 'pronunciationrecording-upload-publish-failed' ).text() );
                                }, pronunciationRecorderFileDetails );
-                       });
-                       $( ".mw-pronunciationrecording-toolbar" ).show();
-               }
-               catch ( e )
-               {
-                       $( ".mw-pronunciationrecording-message" ).text( 
mw.message( 'pronunciationrecording-webaudio-not-supported' ).text() );
+                       } );
+                       $( '.mw-pronunciationrecording-toolbar' ).show();
+               } catch ( e ) {
+                       $( '.mw-pronunciationrecording-message' ).text( 
mw.message( 'pronunciationrecording-webaudio-not-supported' ).text() );
                }
        } );
-} ( mediaWiki, jQuery ) );
+}( mediaWiki, jQuery ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1b10e3d53121dae709dd4ef0abe7a265426a98bf
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/PronunciationRecording
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Rillke <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to