Nikerabbit has uploaded a new change for review. https://gerrit.wikimedia.org/r/321661
Change subject: build: Replace jscs+jshint with eslint ...................................................................... build: Replace jscs+jshint with eslint Change-Id: If9456ec3b2fe25eb0a3158c00efd1db97fa8630d --- A .eslintrc.json D .jscsrc D .jshintignore D .jshintrc M Gruntfile.js M package.json M resources/js/ext.translate.dropdownmenu.js M resources/js/ext.translate.editor.helpers.js M resources/js/ext.translate.editor.js M resources/js/ext.translate.groupselector.js M resources/js/ext.translate.messagetable.js M resources/js/ext.translate.multiselectautocomplete.js M resources/js/ext.translate.pagemode.js M resources/js/ext.translate.proofread.js M resources/js/ext.translate.quickedit.js M resources/js/ext.translate.special.aggregategroups.js M resources/js/ext.translate.special.importtranslations.js M resources/js/ext.translate.special.managetranslatorsandbox.js M resources/js/ext.translate.special.pagemigration.js M resources/js/ext.translate.special.pagepreparation.js M resources/js/ext.translate.special.searchtranslations.js M resources/js/ext.translate.special.translate.js M resources/js/ext.translate.translationstashstorage.js M resources/js/jquery.ajaxdispatcher.js M resources/js/jquery.textchange.js M tests/qunit/ext.translate.special.pagemigration.test.js 26 files changed, 143 insertions(+), 91 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/61/321661/1 diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..a449bc1 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "extends": "wikimedia", + "env": { + "browser": true, + "jquery": true, + "qunit": true + }, + "globals": { + "mediaWiki": false, + "OO": false + }, + "rules": { + "no-use-before-define": 0 + } +} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 9d22e3f..0000000 --- a/.jscsrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preset": "wikimedia" -} diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index 5c58acc..0000000 --- a/.jshintignore +++ /dev/null @@ -1,6 +0,0 @@ -extensions/ -node_modules/ -vendor/ - -# upstream libs -resources/js/jquery.autosize.js diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 8b924e5..0000000 --- a/.jshintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "bitwise": true, - "curly": true, - "eqeqeq": true, - "forin": false, - "freeze": true, - "latedef": "nofunc", - "noarg": true, - "nonew": true, - "onevar": true, - "strict": true, - "undef": true, - "unused": true, - "browser": true, - "predef": [ - "mediaWiki", - "jQuery", - "QUnit", - "autosize", - "OO" - ] -} diff --git a/Gruntfile.js b/Gruntfile.js index 32fd3a8..3b4e637 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,26 +1,25 @@ -/*jshint node:true */ +/* eslint-env node */ module.exports = function ( grunt ) { 'use strict'; - grunt.loadNpmTasks( 'grunt-contrib-jshint' ); - grunt.loadNpmTasks( 'grunt-jscs' ); + grunt.loadNpmTasks( 'grunt-eslint' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-banana-checker' ); grunt.initConfig( { - jshint: { - options: { - jshintrc: true + eslint: { + fix: { + options: { + fix: true + }, + src: '<%= eslint.main %>' }, - all: [ + main: [ '**/*.js', '!node_modules/**', '!extensions/**', '!resources/js/jquery.autosize.js' ] - }, - jscs: { - src: '<%= jshint.all %>' }, jsonlint: { all: [ @@ -40,6 +39,6 @@ } } ); - grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] ); + grunt.registerTask( 'test', [ 'eslint:main', 'jsonlint', 'banana' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/package.json b/package.json index 3d08967..cd0894c 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,10 @@ "test": "grunt test" }, "devDependencies": { - "grunt": "0.4.5", - "grunt-cli": "0.1.13", - "grunt-contrib-jshint": "1.0.0", - "grunt-jscs": "2.8.0", - "grunt-jsonlint": "1.0.7", + "eslint-config-wikimedia": "0.2.0", + "grunt": "1.0.1", + "grunt-eslint": "19.0.0", + "grunt-jsonlint": "1.1.0", "grunt-banana-checker": "0.5.0" } } diff --git a/resources/js/ext.translate.dropdownmenu.js b/resources/js/ext.translate.dropdownmenu.js index 0b1eb02..7e4859c 100644 --- a/resources/js/ext.translate.dropdownmenu.js +++ b/resources/js/ext.translate.dropdownmenu.js @@ -9,4 +9,4 @@ } } ); } ); -} )( jQuery ); +}( jQuery ) ); diff --git a/resources/js/ext.translate.editor.helpers.js b/resources/js/ext.translate.editor.helpers.js index 3c5727b..5c3ef11 100644 --- a/resources/js/ext.translate.editor.helpers.js +++ b/resources/js/ext.translate.editor.helpers.js @@ -49,6 +49,8 @@ /** * Save the documentation + * + * @return {jQuery.Promise} */ saveDocumentation: function () { var translateEditor = this, @@ -210,15 +212,12 @@ * @param {Array} translations An inotherlanguages array as returned by the translation helpers API. */ showAssistantLanguages: function ( translations ) { - var translateEditor = this, - $translationTextarea; + var translateEditor = this; if ( translations.error ) { // Do not proceed if errored/unsupported return; } - - $translationTextarea = this.$editor.find( '.tux-textarea-translation' ); $.each( translations, function ( index ) { var $otherLanguage, langAttr, diff --git a/resources/js/ext.translate.editor.js b/resources/js/ext.translate.editor.js index 9913684..f2b5809 100644 --- a/resources/js/ext.translate.editor.js +++ b/resources/js/ext.translate.editor.js @@ -1,3 +1,5 @@ +/* global autosize */ + ( function ( $, mw, autosize ) { 'use strict'; @@ -309,7 +311,9 @@ // Skip if the message is hidden. For example in a filter result. if ( $next.length && $next.hasClass( 'hide' ) ) { this.$editTrigger = $next; - return this.next(); + this.next(); + + return; } // If this is the last message, just hide it @@ -1246,6 +1250,8 @@ /** * Makes the textare large enough for insertables and positions the insertables. + * + * @param {jQuery} $textarea Text area. */ resizeInsertables: function ( $textarea ) { var $buttonArea, buttonAreaHeight; diff --git a/resources/js/ext.translate.groupselector.js b/resources/js/ext.translate.groupselector.js index 8abf3be..066a9a0 100644 --- a/resources/js/ext.translate.groupselector.js +++ b/resources/js/ext.translate.groupselector.js @@ -6,11 +6,20 @@ /** * options * - position: accepts same values as jquery.ui.position - * - onSelect: callback with message group id when selected - * - language: language for statistics. + * - onSelect: + * - language: * - preventSelector: boolean to load but not show the group selector. * - recent: list of recent group ids * groups: list of message group ids + * + * @param {Element} element + * @param {Object} options + * @param {Object} [options.position] Accepts same values as jquery.ui.position. + * @param {Function} [options.onSelect] Callback with message group id when selected. + * @param {string} options.language Language code for statistics. + * @param {boolean} [options.preventSelector] Whether not to show the group selector. + * @param {string[]} [options.recent] List of recent message group ids. + * @param {string[]} [groups] List of message group ids to show. */ function TranslateMessageGroupSelector( element, options, groups ) { this.$trigger = $( element ); @@ -139,6 +148,8 @@ /** * Hide the selector + * + * @param {Event} e */ hide: function ( e ) { // Do not hide if the trigger is clicked diff --git a/resources/js/ext.translate.messagetable.js b/resources/js/ext.translate.messagetable.js index 5c9aab3..d294463 100644 --- a/resources/js/ext.translate.messagetable.js +++ b/resources/js/ext.translate.messagetable.js @@ -115,6 +115,11 @@ this.loading = false; }, + /** + * Adds a new message using current mode. + * + * @param {Object} message + */ add: function ( message ) { // Prepare the message for display mw.translateHooks.run( 'formatMessageBeforeTable', message ); @@ -130,6 +135,8 @@ /** * Add a message to the message table for translation. + * + * @param {Object} message */ addTranslate: function ( message ) { var $message, @@ -228,6 +235,8 @@ /** * Add a message to the message table for proofreading. + * + * @param {Object} message */ addProofread: function ( message ) { var $message, $icon, module; @@ -284,6 +293,11 @@ } ); }, + /** + * Add a message to the message table for wiki page mode. + * + * @param {Object} message + */ addPageModeMessage: function ( message ) { var $message; @@ -546,6 +560,8 @@ /** * Enables own message hiding in proofread mode. + * + * @param {boolean} enabled */ setHideOwnInProofreading: function ( enabled ) { if ( enabled ) { diff --git a/resources/js/ext.translate.multiselectautocomplete.js b/resources/js/ext.translate.multiselectautocomplete.js index beb715b..3859b14 100644 --- a/resources/js/ext.translate.multiselectautocomplete.js +++ b/resources/js/ext.translate.multiselectautocomplete.js @@ -9,7 +9,7 @@ jQuery( function ( $ ) { 'use strict'; - // jscs:disable disallowDanglingUnderscores + /* eslint no-underscore-dangle: 0 */ $.widget( 'ui.multiselectautocomplete', { options: { diff --git a/resources/js/ext.translate.pagemode.js b/resources/js/ext.translate.pagemode.js index 8f665a3..41eb7fd 100644 --- a/resources/js/ext.translate.pagemode.js +++ b/resources/js/ext.translate.pagemode.js @@ -14,6 +14,12 @@ * sourcelangcode: 'en', // Mandatory source language code * targetlangcode: 'hi' // Mandatory target language code * } ); + * + * @param {Element} element + * @param {Object} options + * @param {Object} options.message + * @param {string} options.sourcelangcode Language code. + * @param {string} options.targetlangcode Language code. */ function PageMode( element, options ) { this.$message = $( element ); diff --git a/resources/js/ext.translate.proofread.js b/resources/js/ext.translate.proofread.js index be16b9a..97ed1cd 100644 --- a/resources/js/ext.translate.proofread.js +++ b/resources/js/ext.translate.proofread.js @@ -1,4 +1,4 @@ -/*global alert: false*/ +/* global alert: false*/ ( function ( $, mw ) { 'use strict'; @@ -15,6 +15,12 @@ * sourcelangcode: 'en', // Mandatory source language code * targetlangcode: 'hi' // Mandatory target language code * } ); + * + * @param {Element} element + * @param {Object} options + * @param {Object} options.message + * @param {string} options.sourcelangcode Language code. + * @param {string} options.targetlangcode Language code. */ function Proofread( element, options ) { this.$message = $( element ); diff --git a/resources/js/ext.translate.quickedit.js b/resources/js/ext.translate.quickedit.js index e6a3b01..1be5f2f 100644 --- a/resources/js/ext.translate.quickedit.js +++ b/resources/js/ext.translate.quickedit.js @@ -16,6 +16,8 @@ * @license GPL-2.0+ */ +/* global autosize */ + ( function ( $, mw, autosize ) { 'use strict'; var dialogwidth = false, @@ -45,6 +47,9 @@ /** * This is JS port same method of TranslateUtils.php + * + * @param {string} text + * @return {string} Safe HTML. */ function convertWhiteSpaceToHTML( text ) { return mw.html.escape( text ) @@ -54,7 +59,12 @@ .replace( /\n/g, '<br />' ); } - function addAccessKeys( dialog ) { + /** + * Adds access keys to some buttons. + * + * @param {jQuery} $dialog + */ + function addAccessKeys( $dialog ) { var buttons = { a: '.mw-translate-save', s: '.mw-translate-next', @@ -70,7 +80,7 @@ .removeAttr( 'accesskey' ) .attr( 'title', '' ); - dialog.find( selector ) + $dialog.find( selector ) .val( function ( i, b ) { return b + ' (_)'.replace( '_', key ); } ) @@ -400,4 +410,4 @@ } ); $( document ).ready( mw.translate.init ); -} )( jQuery, mediaWiki, autosize ); +}( jQuery, mediaWiki, autosize ) ); diff --git a/resources/js/ext.translate.special.aggregategroups.js b/resources/js/ext.translate.special.aggregategroups.js index 701f32b..b1bca16 100644 --- a/resources/js/ext.translate.special.aggregategroups.js +++ b/resources/js/ext.translate.special.aggregategroups.js @@ -1,4 +1,4 @@ -/*global alert:false */ +/* global alert:false */ ( function ( $, mw ) { 'use strict'; @@ -116,7 +116,7 @@ function editGroup( event ) { var $target = $( event.target ), $parent = $target.closest( '.mw-tpa-group' ), - aggregateGroupId = $parent.data( 'groupid' ), + aggregateGroupId = $parent.data( 'groupid' ), $displayGroup = $parent.children( '.tp-display-group' ), $editGroup = $parent.children( '.tp-edit-group' ), successFunction, diff --git a/resources/js/ext.translate.special.importtranslations.js b/resources/js/ext.translate.special.importtranslations.js index d916fcc..519c448 100644 --- a/resources/js/ext.translate.special.importtranslations.js +++ b/resources/js/ext.translate.special.importtranslations.js @@ -9,7 +9,7 @@ } } - $( document ).ready( function ( ) { + $( document ).ready( function () { var $input = $( '#mw-translate-up-local-input' ); $input.on( 'change', function () { buttoner( $input ); diff --git a/resources/js/ext.translate.special.managetranslatorsandbox.js b/resources/js/ext.translate.special.managetranslatorsandbox.js index a38a3dc..5ea2ab3 100644 --- a/resources/js/ext.translate.special.managetranslatorsandbox.js +++ b/resources/js/ext.translate.special.managetranslatorsandbox.js @@ -70,11 +70,9 @@ * @param {Object} request The request data set from backend on request items */ function displayRequestDetails( request ) { - var storage, reminders, + var storage, $reminderStatus = $( '<span>' ).addClass( 'reminder-status' ), $detailsPane = $( '.details.pane' ); - - reminders = request.reminders ? request.reminders.split( '|' ) : []; if ( request.reminderscount ) { $reminderStatus.text( mw.msg( @@ -631,7 +629,7 @@ $.fn.languageFilter = function () { return this.each( function () { - if ( !$.data( this, 'LanguageFilter' ) ) { + if ( !$.data( this, 'LanguageFilter' ) ) { $.data( this, 'LanguageFilter', new LanguageFilter( this ) ); } } ); @@ -703,7 +701,7 @@ $.fn.translatorSearch = function () { return this.each( function () { - if ( !$.data( this, 'TranslatorSearch' ) ) { + if ( !$.data( this, 'TranslatorSearch' ) ) { $.data( this, 'TranslatorSearch', new TranslatorSearch( this ) ); } } ); @@ -737,9 +735,9 @@ $requestCheckboxes.on( 'click change', requestSelectHandler ); // Handle clicks on request rows. - $requestRows.on( 'click', onSelectRequest ); + $requestRows.on( 'click', onSelectRequest ); - $( '.older-requests-indicator' ).on( 'click', oldRequestSelector ); + $( '.older-requests-indicator' ).on( 'click', oldRequestSelector ); if ( $requestRows.length ) { $requestRows.first().click(); diff --git a/resources/js/ext.translate.special.pagemigration.js b/resources/js/ext.translate.special.pagemigration.js index 9bb771d..7845947 100644 --- a/resources/js/ext.translate.special.pagemigration.js +++ b/resources/js/ext.translate.special.pagemigration.js @@ -10,6 +10,8 @@ * and identifiers from left hand side blocks. Create pages only if * content is not empty. * + * @param {number} i Array index to sourceUnits. + * @param {string} content * @return {Function} Returns a function which returns a jQuery.Promise */ function createTranslationPage( i, content ) { @@ -254,7 +256,7 @@ * Split headers from remaining text in each translation unit if present. * * @param {Array} translations Array of initial units obtained on splitting - * @return {string[]} translationUnits Array having the headers split into new unit + * @return {string[]} Array having the headers split into new unit */ function splitHeaders( translations ) { return $.map( translations, function ( elem ) { @@ -267,7 +269,8 @@ * Get the index of next translation unit containing h2 header. * * @param {number} startIndex Index to start the scan from - * @return {number} i Index of the next unit found, -1 if not + * @param {string[]} translationUnits Segmented units. + * @return {number} Index of the next unit found, -1 if not. */ function getHeaderUnit( startIndex, translationUnits ) { var i, regex; @@ -284,6 +287,10 @@ * Align h2 headers in the order they appear. * Assumption: The source headers and translation headers appear in * the same order. + * + * @param {Object[]} sourceUnits + * @param {string[]} translationUnits + * @return {string[]} */ function alignHeaders( sourceUnits, translationUnits ) { var i, regex, tIndex = 0, @@ -372,6 +379,8 @@ /** * Handler for add new unit icon ('+') click event. Adds a translation unit * below the current unit. + * + * @param {Event} event */ function addHandler( event ) { var nextRow, text, newUnit, targetUnit; @@ -392,6 +401,8 @@ /** * Handler for delete icon ('-') click event. Deletes the unit and shifts * the units up by one. + * + * @param {Event} event */ function deleteHandler( event ) { var sourceText, rowUnit; @@ -409,6 +420,8 @@ /** * Handler for swap icon click event. Swaps the text in the current unit * with the text in the unit below. + * + * @param {Event} event */ function swapHandler( event ) { var rowUnit, tempText, nextVal; @@ -423,7 +436,7 @@ * Handler for 'Import' button click event. Imports source and translation * units and displays them. * - * @param {jQuery.event} e + * @param {Event} e */ function importHandler( e ) { var pageTitle, slashPos, titleObj, @@ -465,17 +478,17 @@ $.when( getSourceUnits( pageName ), getFuzzyTimestamp( pageTitle ) ) .then( function ( sourceUnits, fuzzyTimestamp ) { - noOfSourceUnits = sourceUnits.length; - splitTranslationPage( fuzzyTimestamp, pageTitle ).done( function ( translations ) { - var translationUnits = splitHeaders( translations ); - translationUnits = alignHeaders( sourceUnits, translationUnits ); - noOfTranslationUnits = translationUnits.length; - displayUnits( sourceUnits, translationUnits ); - $( '#action-save, #action-cancel' ).removeClass( 'hide' ); - $( '#action-import' ).addClass( 'hide' ); - messageBox.text( mw.msg( 'pm-on-import-message-text' ) ).show( 'fast' ); + noOfSourceUnits = sourceUnits.length; + splitTranslationPage( fuzzyTimestamp, pageTitle ).done( function ( translations ) { + var translationUnits = splitHeaders( translations ); + translationUnits = alignHeaders( sourceUnits, translationUnits ); + noOfTranslationUnits = translationUnits.length; + displayUnits( sourceUnits, translationUnits ); + $( '#action-save, #action-cancel' ).removeClass( 'hide' ); + $( '#action-import' ).addClass( 'hide' ); + messageBox.text( mw.msg( 'pm-on-import-message-text' ) ).show( 'fast' ); + } ); } ); - } ); } /** diff --git a/resources/js/ext.translate.special.pagepreparation.js b/resources/js/ext.translate.special.pagepreparation.js index 1f66ee7..8562555 100644 --- a/resources/js/ext.translate.special.pagepreparation.js +++ b/resources/js/ext.translate.special.pagepreparation.js @@ -369,11 +369,10 @@ } ); $( '#action-save' ).click( function () { - var serverName, pageName, + var pageName, pageUrl = ''; pageName = $.trim( $input.val() ); - serverName = mw.config.get( 'wgServerName' ); savePage( pageName, pageContent ).done( function () { pageUrl = mw.Title.newFromText( pageName ).getUrl( { action: 'edit' } ); $( '.messageDiv' ).html( mw.message( 'pp-save-message', pageUrl ).parse() ).show(); diff --git a/resources/js/ext.translate.special.searchtranslations.js b/resources/js/ext.translate.special.searchtranslations.js index 560e249..848697f 100644 --- a/resources/js/ext.translate.special.searchtranslations.js +++ b/resources/js/ext.translate.special.searchtranslations.js @@ -246,7 +246,7 @@ if ( parentGrouppath !== undefined ) { grouppath = parentGrouppath + '|' + groupId; } else { - grouppath = groupId; + grouppath = groupId; } uri.extend( { group: groupId, grouppath: grouppath } ); diff --git a/resources/js/ext.translate.special.translate.js b/resources/js/ext.translate.special.translate.js index 62436b8..22be123 100644 --- a/resources/js/ext.translate.special.translate.js +++ b/resources/js/ext.translate.special.translate.js @@ -104,7 +104,7 @@ realFilters.push( filter ); } - return realFilters.join( '|' ); + return realFilters.join( '|' ); } function checkDirty() { @@ -125,6 +125,10 @@ /** * Updates all group specific stuff on the page. + * + * @param {Object} state Information about current group and language. + * @param {string} state.group Message group id. + * @param {string} state.language Language. */ function updateGroupInformation( state ) { var props = 'id|priority|prioritylangs|priorityforce|description'; diff --git a/resources/js/ext.translate.translationstashstorage.js b/resources/js/ext.translate.translationstashstorage.js index 0e2ac6e..8ce5875 100644 --- a/resources/js/ext.translate.translationstashstorage.js +++ b/resources/js/ext.translate.translationstashstorage.js @@ -37,6 +37,7 @@ /** * Get the current users translations. * + * @param {string} user User name * @return {jQuery.Promise} */ getUserTranslations: function ( user ) { diff --git a/resources/js/jquery.ajaxdispatcher.js b/resources/js/jquery.ajaxdispatcher.js index fcdeb41..d237a76 100644 --- a/resources/js/jquery.ajaxdispatcher.js +++ b/resources/js/jquery.ajaxdispatcher.js @@ -7,6 +7,7 @@ * @author Niklas Laxström * * @param {callable[]} list List of callbacks returning promises. + * @param {number} maxRetries Maximum number of times a failed promise is retried. * @return {jQuery.Promise} */ function ajaxDispatcher( list, maxRetries ) { diff --git a/resources/js/jquery.textchange.js b/resources/js/jquery.textchange.js index dcf7ef0..047d8ce 100644 --- a/resources/js/jquery.textchange.js +++ b/resources/js/jquery.textchange.js @@ -41,4 +41,4 @@ } }; -} )( jQuery ); +}( jQuery ) ); diff --git a/tests/qunit/ext.translate.special.pagemigration.test.js b/tests/qunit/ext.translate.special.pagemigration.test.js index 724202a..b3146cf 100644 --- a/tests/qunit/ext.translate.special.pagemigration.test.js +++ b/tests/qunit/ext.translate.special.pagemigration.test.js @@ -83,9 +83,9 @@ QUnit.expect( 2 ); - sourceUnits = [ { identifier: '1',definition: 'abc' }, { identifier: '2',definition: '==123==' }, - { identifier: '3',definition: 'pqr' }, { identifier: '4',definition: 'xyz' }, - { identifier: '5',definition: 'mno' }, { identifier: '6',definition: '==456==' } ]; + sourceUnits = [ { identifier: '1', definition: 'abc' }, { identifier: '2', definition: '==123==' }, + { identifier: '3', definition: 'pqr' }, { identifier: '4', definition: 'xyz' }, + { identifier: '5', definition: 'mno' }, { identifier: '6', definition: '==456==' } ]; translationUnits1 = [ '==123==', 'pqr', '==456==' ]; -- To view, visit https://gerrit.wikimedia.org/r/321661 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If9456ec3b2fe25eb0a3158c00efd1db97fa8630d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits