Santhosh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/323790
Change subject: Replace jshint, jscs, jsbeautifyrc by eslint
......................................................................
Replace jshint, jscs, jsbeautifyrc by eslint
Change-Id: Id821b8cebc4d0b43d50aaa0ec46bab9f9538b0d4
---
A .eslintrc.json
D .jsbeautifyrc
D .jscs.json
D .jscsrc
D .jshintignore
D .jshintrc
M Gruntfile.js
M modules/dashboard/ext.cx.recommendtool.client.js
M modules/dashboard/ext.cx.suggestionlist.js
M modules/dashboard/ext.cx.translationlist.js
M modules/editor/ext.cx.editor.js
M modules/entrypoint/ext.cx.contributions.js
M modules/entrypoint/ext.cx.entrypoint.js
M modules/eventlogging/ext.cx.eventlogging.js
M modules/publish/ext.cx.publish.dialog.js
M modules/publish/ext.cx.publish.js
M modules/publish/ext.cx.wikibase.link.js
M modules/source/ext.cx.source.js
M modules/source/ext.cx.source.selector.js
M modules/widgets/overlay/ext.cx.overlay.js
M package.json
21 files changed, 138 insertions(+), 117 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/90/323790/1
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..ecc2e04
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,18 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true,
+ "qunit": true
+ },
+ "globals": {
+ "mediaWiki": false,
+ "moment": false,
+ "EasyDeflate": false,
+ "OO": false
+ },
+ "rules": {
+ "dot-notation": 0,
+ "wrap-iife": 0
+ }
+}
diff --git a/.jsbeautifyrc b/.jsbeautifyrc
deleted file mode 100644
index cfa5b27..0000000
--- a/.jsbeautifyrc
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "preserve_newlines": true,
- "jslint_happy": true,
- "keep_array_indentation": true,
- "space_before_conditional": true,
- "max_preserve_newlines": 10,
- "brace_style": "collapse",
- "keep_function_indentation": false,
- "break_chained_methods": false,
- "eval_code": false,
- "unescape_strings": false,
- "wrap_line_length": 0,
- "space_in_paren": true,
- "git_happy": true,
- "indent_with_tabs": true,
- "end_with_newline": true
-}
diff --git a/.jscs.json b/.jscs.json
deleted file mode 100644
index 9d22e3f..0000000
--- a/.jscs.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "preset": "wikimedia"
-}
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 18be9f9..0000000
--- a/.jshintignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# upstream libs
-lib/*
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index dc06253..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "bitwise": true,
- "curly": true,
- "eqeqeq": true,
- "forin": false,
- "freeze": true,
- "latedef": true,
- "noarg": true,
- "nonew": true,
- "strict": true,
- "undef": true,
- "unused": true,
- "browser": true,
- "predef": [
- "EasyDeflate",
- "mediaWiki",
- "jQuery",
- "QUnit",
- "moment",
- "OO"
- ]
-}
diff --git a/Gruntfile.js b/Gruntfile.js
index e46e25b..cec6620 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,25 +1,38 @@
-/*jshint node:true */
+/* eslint-env node */
module.exports = function ( grunt ) {
'use strict';
+
var conf = grunt.file.readJSON( 'extension.json' );
- grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+ grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
- grunt.loadNpmTasks( 'grunt-jscs' );
+ grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.initConfig( {
- jshint: {
- options: {
- jshintrc: true
+ eslint: {
+ fix: {
+ options: {
+ fix: true
+ },
+ src: '<%= eslint.main %>'
},
- all: [
+ main: [
'**/*.js',
'!lib/**',
'!node_modules/**'
]
},
- jscs: {
- src: '<%= jshint.all %>'
+ stylelint: {
+ options: {
+ syntax: 'less'
+ },
+ src: [
+ '**/*.css',
+ '**/*.less',
+ '!lib/**',
+ '!node_modules/**',
+ '!vendor/**'
+ ]
},
banana: conf.MessagesDirs,
jsonlint: {
@@ -30,6 +43,6 @@
}
} );
- grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ]
);
+ grunt.registerTask( 'test', [ 'eslint:main', 'stylelint', 'jsonlint',
'banana' ] );
grunt.registerTask( 'default', 'test' );
};
diff --git a/modules/dashboard/ext.cx.recommendtool.client.js
b/modules/dashboard/ext.cx.recommendtool.client.js
index e0fe815..ad73ddd 100644
--- a/modules/dashboard/ext.cx.recommendtool.client.js
+++ b/modules/dashboard/ext.cx.recommendtool.client.js
@@ -16,6 +16,8 @@
* RecommendTool
*
* @class
+ * @param {string} from Source language
+ * @param {string} to target language
*/
function RecommendTool( from, to ) {
this.sourceLanguage = from;
@@ -121,5 +123,5 @@
};
};
- mw.cx.recommendtool = RecommendTool;
+ mw.cx.Recommendtool = RecommendTool;
}( jQuery, mediaWiki ) );
diff --git a/modules/dashboard/ext.cx.suggestionlist.js
b/modules/dashboard/ext.cx.suggestionlist.js
index 829ef5b..d8efdb1 100644
--- a/modules/dashboard/ext.cx.suggestionlist.js
+++ b/modules/dashboard/ext.cx.suggestionlist.js
@@ -207,7 +207,7 @@
api = new mw.Api();
if ( list.id === 'trex' ) {
- this.recommendtool = this.recommendtool || new
mw.cx.recommendtool(
+ this.recommendtool = this.recommendtool || new
mw.cx.Recommendtool(
this.filters.sourceLanguage,
this.filters.targetLanguage
);
@@ -360,6 +360,10 @@
} );
};
+ function listCompare( listA, listB ) {
+ return listOrder[ listA.type ] > listOrder[ listB.type ];
+ }
+
/**
* List all suggestions.
*
@@ -424,6 +428,7 @@
/**
* Build the DOM for suggestion item
*
+ * @param {Object} suggestion
* @return {jQuery}
*/
CXSuggestionList.prototype.buildSuggestionItem = function ( suggestion
) {
@@ -792,10 +797,6 @@
CXSuggestionList.prototype.sortLists = function ( lists ) {
return Object.keys( lists ).sort( listCompare );
};
-
- function listCompare( listA, listB ) {
- return listOrder[ listA.type ] > listOrder[ listB.type ];
- }
/**
* Make the list expandable and collapsable.
diff --git a/modules/dashboard/ext.cx.translationlist.js
b/modules/dashboard/ext.cx.translationlist.js
index 95881f6..a42afb6 100644
--- a/modules/dashboard/ext.cx.translationlist.js
+++ b/modules/dashboard/ext.cx.translationlist.js
@@ -12,6 +12,9 @@
* CXTranslationList
*
* @class
+ * @param {jQuery} $container
+ * @param {string} type
+ * @param {Object} siteMapper
*/
function CXTranslationList( $container, type, siteMapper ) {
this.$container = $container;
@@ -203,6 +206,7 @@
* Go to translation view
*
* @param {Object} translation
+ * @return {boolean}
*/
CXTranslationList.prototype.continueTranslation = function (
translation ) {
if ( translation.status === 'deleted' ) {
@@ -225,13 +229,15 @@
/**
* List all translations.
+ *
+ * @param {Object[]} translations
*/
CXTranslationList.prototype.renderTranslations = function (
translations ) {
var i, translation, progress, $translation,
$lastUpdated, $image, $progressbar,
sourceDir, targetDir, $targetTitle,
$translationLink,
- $sourceLanguage, $targetLanguage, $languageContainer,
$status,
+ $sourceLanguage, $targetLanguage, $languageContainer,
$actionsTrigger, $deleteTranslation, $menu,
$menuContainer,
$continueTranslation,
$titleLanguageBlock,
@@ -311,10 +317,6 @@
$languageContainer = $( '<div>' )
.addClass( 'cx-tlitem__languages' )
.append( $sourceLanguage, $targetLanguage );
-
- $status = $( '<div>' )
- .addClass( 'status status-' +
translation.status )
- .text( mw.msg( 'cx-translation-status-' +
translation.status ) );
$actionsTrigger = $( '<div>' )
.addClass( 'cx-tlitem__actions__trigger' );
@@ -459,7 +461,7 @@
deferred = $.Deferred();
- overlay = new mw.cx.widgets.overlay();
+ overlay = new mw.cx.widgets.Overlay();
if ( this.$confirmationDialog ) {
$cancelButton = this.$confirmationDialog.find(
'.cx-draft-discard-dialog__cancel' );
diff --git a/modules/editor/ext.cx.editor.js b/modules/editor/ext.cx.editor.js
index bf1d086..9838220 100644
--- a/modules/editor/ext.cx.editor.js
+++ b/modules/editor/ext.cx.editor.js
@@ -13,6 +13,7 @@
/**
* CXSectionEditor - Editor for each sections in the translation
*
+ * @param {Element} element
* @class
*/
function CXSectionEditor( element ) {
@@ -50,6 +51,8 @@
/**
* Paste handler. Adapts pasted text.
+ * @param {Event} e
+ * @return {boolean}
*/
CXSectionEditor.prototype.pasteHandler = function ( e ) {
// Enforce plain text pasting
@@ -62,6 +65,8 @@
/**
* Drop handler. Adapts pasted text.
+ * @param {Event} e
+ * @return {boolean}
*/
CXSectionEditor.prototype.dropHandler = function ( e ) {
var text = e.originalEvent.dataTransfer.getData( 'text' ) ||
@@ -112,6 +117,7 @@
* The CXSectionEditor plugin.
* Sets common properties on all editable elements
* in the translation column.
+ * @return {jQuery}
*/
$.fn.cxEditor = function () {
return this.each( function () {
diff --git a/modules/entrypoint/ext.cx.contributions.js
b/modules/entrypoint/ext.cx.contributions.js
index 7092d9d..71224c7 100644
--- a/modules/entrypoint/ext.cx.contributions.js
+++ b/modules/entrypoint/ext.cx.contributions.js
@@ -11,6 +11,7 @@
/**
* @class
+ * @param {Element} element
*/
function CXContributions( element ) {
this.$element = $( element );
@@ -61,19 +62,19 @@
return [
{
text: mw.msg( 'cx-contributions-new-article' ),
- class: 'cx-contributions-new-article',
+ 'class': 'cx-contributions-new-article',
url: mw.util.getUrl( 'Special:WantedPages' ),
tooltip: mw.msg(
'cx-contributions-new-article-tooltip' )
},
{
text: mw.msg( 'cx-contributions-upload' ),
- class: 'cx-contributions-upload',
+ 'class': 'cx-contributions-upload',
url:
'https://commons.wikimedia.org/wiki/Special:UploadWizard',
tooltip: mw.msg(
'cx-contributions-upload-tooltip' )
},
{
text: mw.msg( 'cx-contributions-translation' ),
- class: 'cx-contributions-translation ' + (
isNewToCX() ? 'cx-contributions-new' : '' ),
+ 'class': 'cx-contributions-translation ' + (
isNewToCX() ? 'cx-contributions-new' : '' ),
url: mw.util.getUrl(
'Special:ContentTranslation', {
campaign: entrypointName
} ),
@@ -84,6 +85,8 @@
/**
* CXContributions entry point plugin
+ * @param {Object} options
+ * @return {jQuery}
*/
$.fn.cxContributions = function ( options ) {
return this.each( function () {
diff --git a/modules/entrypoint/ext.cx.entrypoint.js
b/modules/entrypoint/ext.cx.entrypoint.js
index 19516cd..c41031c 100644
--- a/modules/entrypoint/ext.cx.entrypoint.js
+++ b/modules/entrypoint/ext.cx.entrypoint.js
@@ -12,6 +12,8 @@
/**
* @class
+ * @param {jQuery} $trigger
+ * @param {Object} options
*/
function CXEntryPoint( $trigger, options ) {
this.$trigger = $( $trigger );
@@ -180,6 +182,8 @@
/**
* CXEntryPoint plugin
+ * @param {Object} options
+ * @return {jQuery}
*/
$.fn.cxEntryPoint = function ( options ) {
return this.each( function () {
diff --git a/modules/eventlogging/ext.cx.eventlogging.js
b/modules/eventlogging/ext.cx.eventlogging.js
index 4f827d3..9df5708 100644
--- a/modules/eventlogging/ext.cx.eventlogging.js
+++ b/modules/eventlogging/ext.cx.eventlogging.js
@@ -244,7 +244,7 @@
};
$( function () {
- /*jshint -W031*/
+ /* eslint no-new:off */
new ContentTranslationEventLogging();
} );
}( jQuery, mediaWiki ) );
diff --git a/modules/publish/ext.cx.publish.dialog.js
b/modules/publish/ext.cx.publish.dialog.js
index ad505dd..3d28ec4 100644
--- a/modules/publish/ext.cx.publish.dialog.js
+++ b/modules/publish/ext.cx.publish.dialog.js
@@ -14,6 +14,7 @@
* Handles show the publishing options dialog.
*
* @class
+ * @param {Element} trigger
*/
function CXPublishingDialog( trigger ) {
this.$trigger = $( trigger );
@@ -42,9 +43,8 @@
* @param {string} title The title of the existing article
*/
CXPublishingDialog.prototype.render = function ( title ) {
- var $buttons, username, namespace;
+ var $buttons, namespace;
- username = mw.user.getName();
namespace = mw.config.get(
'wgContentTranslationTargetNamespace' );
this.$dialog = $( '<div>' )
@@ -156,6 +156,7 @@
/**
* CXPublishingDialog Plugin
+ * @return {jQuery}
*/
$.fn.cxPublishingDialog = function () {
return this.each( function () {
diff --git a/modules/publish/ext.cx.publish.js
b/modules/publish/ext.cx.publish.js
index 07c63cc..7eda0ff 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -12,6 +12,8 @@
* Handles the actual submission to the MediaWiki via the API,
including captchas.
*
* @class
+ * @param {Element} trigger
+ * @param {Object} siteMapper
*/
function CXPublish( trigger, siteMapper ) {
this.trigger = trigger;
@@ -125,6 +127,25 @@
};
/**
+ * Increase the version number of a title starting with 1.
+ *
+ * @param {string} title The title to increase the version on.
+ * @return {string}
+ */
+ function increaseVersion( title ) {
+ var match, version;
+
+ match = title.match( /^.*\((\d+)\)$/ );
+ if ( match ) {
+ version = parseInt( match[ 1 ], 10 ) + 1;
+
+ return title.replace( /\(\d+\)$/, '(' + version + ')' );
+ }
+
+ return title + ' (1)';
+ }
+
+ /**
* Generate an alternate title in case of title collision.
*
* @param {string} title The title
@@ -174,25 +195,6 @@
} );
} );
};
-
- /**
- * Increase the version number of a title starting with 1.
- *
- * @param {string} title The title to increase the version on.
- * @return {string}
- */
- function increaseVersion( title ) {
- var match, version;
-
- match = title.match( /^.*\((\d+)\)$/ );
- if ( match ) {
- version = parseInt( match[ 1 ], 10 ) + 1;
-
- return title.replace( /\(\d+\)$/, '(' + version + ')' );
- }
-
- return title + ' (1)';
- }
/**
* Get categories for the current translation pair.
@@ -312,7 +314,7 @@
/**
* Prepare the translated content for publishing by removing unwanted
parts.
- *
+ * @param {jQuery} $content
* @return {string} processed html
*/
CXPublish.prototype.prepareTranslationForPublish = function ( $content
) {
diff --git a/modules/publish/ext.cx.wikibase.link.js
b/modules/publish/ext.cx.wikibase.link.js
index 02af16c..a2b6117 100644
--- a/modules/publish/ext.cx.wikibase.link.js
+++ b/modules/publish/ext.cx.wikibase.link.js
@@ -11,6 +11,10 @@
/**
* Link the source and target articles in the Wikibase repo
+ * @param {string} sourceLanguage
+ * @param {string} targetLanguage
+ * @param {string} sourceTitle
+ * @param {string} targetTitle
*/
var addWikibaseLink = function ( sourceLanguage, targetLanguage,
sourceTitle, targetTitle ) {
var title, sourceApi;
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 4c0fa28..0568e62 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -13,6 +13,9 @@
/**
* ContentTranslationSource
*
+ * @param {Element} element
+ * @param {Object} siteMapper
+ * @param {Object} options
* @class
*/
function ContentTranslationSource( element, siteMapper, options ) {
@@ -172,6 +175,16 @@
this.showLoadingIndicator();
};
+ /**
+ * Remove the leading ./ added by parsoid.
+ *
+ * @param {string} href Link target
+ * @return {string} Cleaned up href
+ */
+ function cleanupLinkHref( href ) {
+ return href && href.replace( /^\.*\//, '' );
+ }
+
ContentTranslationSource.prototype.load = function ( content ) {
var self = this;
@@ -200,16 +213,6 @@
mw.hook( 'mw.cx.source.ready' ).fire();
} );
};
-
- /**
- * Remove the leading ./ added by parsoid.
- *
- * @param {string} href Link target
- * @return {string} Cleaned up href
- */
- function cleanupLinkHref( href ) {
- return href && href.replace( /^\.*\//, '' );
- }
ContentTranslationSource.prototype.showLoadingIndicator = function () {
var $loadingIndicator,
diff --git a/modules/source/ext.cx.source.selector.js
b/modules/source/ext.cx.source.selector.js
index f84da9d..163d89b 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -14,9 +14,12 @@
* CXSourceSelector
*
* @class
+ * @param {Element} trigger
+ * @param {Object} siteMapper
+ * @param {Object} options
*/
- function CXSourceSelector( $trigger, siteMapper, options ) {
- this.$trigger = $( $trigger );
+ function CXSourceSelector( trigger, siteMapper, options ) {
+ this.$trigger = $( trigger );
this.options = $.extend( {}, options );
this.siteMapper = siteMapper;
@@ -55,7 +58,7 @@
* Return the appropriate menuWidth parameter for a given language
count.
*
* @param {number} languagesCount Number of languages
- * return {string} wide, medium or narrow
+ * @return {string} wide, medium or narrow
*/
function getUlsMenuWidth( languagesCount ) {
if ( languagesCount <= 12 ) {
@@ -348,6 +351,7 @@
/**
* Handles Enter (Return) keypress.
+ * @param {Event} e
*/
CXSourceSelector.prototype.enterKeyHandler = function ( e ) {
if ( e.which === 13 ) {
@@ -577,7 +581,7 @@
} );
if ( !this.overlay ) {
- this.overlay = new mw.cx.widgets.overlay();
+ this.overlay = new mw.cx.widgets.Overlay();
}
this.overlay.show();
@@ -858,6 +862,8 @@
/**
* CXEntryPoint Plugin
+ * @param {Object} options
+ * @return {jQuery}
*/
$.fn.cxSourceSelector = function ( options ) {
return this.each( function () {
diff --git a/modules/widgets/overlay/ext.cx.overlay.js
b/modules/widgets/overlay/ext.cx.overlay.js
index 2909530..6376146 100644
--- a/modules/widgets/overlay/ext.cx.overlay.js
+++ b/modules/widgets/overlay/ext.cx.overlay.js
@@ -9,6 +9,8 @@
/**
* An overlay UI for the page.
+ * @param {Element} element
+ * @param {Object} options
*/
function CXOverlay( element, options ) {
this.$container = $( element || 'body' );
@@ -48,7 +50,7 @@
this.$container.removeClass( 'cx-noscroll' );
};
- mw.cx.widgets.overlay = CXOverlay;
+ mw.cx.widgets.Overlay = CXOverlay;
$.fn.cxoverlay = function ( option ) {
return this.each( function () {
@@ -57,7 +59,7 @@
options = typeof option === 'object' && option;
if ( !data ) {
- $this.data( 'cxoverlay', ( data = new
mw.cx.widgets.overlay( this, options ) ) );
+ $this.data( 'cxoverlay', ( data = new
mw.cx.widgets.Overlay( this, options ) ) );
}
if ( typeof option === 'string' ) {
diff --git a/package.json b/package.json
index 1087c8a..ec4d980 100644
--- a/package.json
+++ b/package.json
@@ -4,11 +4,12 @@
"test": "grunt test"
},
"devDependencies": {
- "grunt": "0.4.5",
- "grunt-cli": "0.1.13",
- "grunt-contrib-jshint": "0.11.3",
- "grunt-banana-checker": "0.4.0",
- "grunt-jscs": "2.3.0",
- "grunt-jsonlint": "1.0.7"
+ "grunt": "1.0.1",
+ "eslint-config-wikimedia": "0.3.0",
+ "grunt-banana-checker": "0.5.0",
+ "grunt-eslint": "19.0.0",
+ "grunt-jsonlint": "1.0.8",
+ "grunt-stylelint": "0.6.0",
+ "stylelint-config-wikimedia": "0.3.0"
}
}
--
To view, visit https://gerrit.wikimedia.org/r/323790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id821b8cebc4d0b43d50aaa0ec46bab9f9538b0d4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits