jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/355410 )
Change subject: Tools: Use eslint instead of jshint & jscs
......................................................................
Tools: Use eslint instead of jshint & jscs
* Remove jshint & jscs
* Add eslint and eslint-config-wikimedia
* Fix linting errors under resources/
Bug: T149201
Change-Id: I2a71f4e6089a3031ed4ccc444f5d29dfc1d4158f
---
A .eslintrc.json
D .jscsrc
D .jshintignore
D .jshintrc
M Gruntfile.js
M package.json
M resources/ext.quicksurveys.init/init.js
M resources/ext.quicksurveys.lib/lib.js
M resources/ext.quicksurveys.views/ExternalSurvey.js
M resources/ext.quicksurveys.views/QuickSurvey.js
M resources/ext.quicksurveys.views/utils.js
M resources/mediawiki.template.muhogan/init.js
12 files changed, 149 insertions(+), 157 deletions(-)
Approvals:
jenkins-bot: Verified
Jdlrobson: Looks good to me, approved
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..04ce1dc
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,14 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true,
+ "qunit": true
+ },
+ "globals": {
+ "mediaWiki": false,
+ "OO": false
+ },
+ "rules": {
+ }
+}
diff --git a/.jscsrc b/.jscsrc
deleted file mode 100644
index a2d7b13..0000000
--- a/.jscsrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "preset": "wikimedia"
-}
diff --git a/.jshintignore b/.jshintignore
deleted file mode 100644
index 3c3629e..0000000
--- a/.jshintignore
+++ /dev/null
@@ -1 +0,0 @@
-node_modules
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 1bcf554..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "globals": {
- "console": true,
- "jQuery": true,
- "JsDiff": true,
- "Hogan": true,
- "QUnit": true,
- "mw": true,
- "mediaWiki": true,
- "CodeMirror": true,
- "OO": true
- },
-
- "browser": true,
- "curly": true,
- "eqeqeq": true,
- "forin": false,
- "onevar": true,
- "trailing": true,
- "undef" : true,
- "unused": true,
- "supernew": true
-}
diff --git a/Gruntfile.js b/Gruntfile.js
index aa81ab4..85342e3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,8 +1,8 @@
-/*jshint node:true */
+/* eslint-env node */
+
module.exports = function ( grunt ) {
- grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
- grunt.loadNpmTasks( 'grunt-jscs' );
+ grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-stylelint' );
@@ -10,17 +10,11 @@
files: {
js: 'resources/**/*.js'
},
- jshint: {
- options: {
- jshintrc: true
- },
+ eslint: {
all: [
- '.',
- '!node_modules/**'
+ '!node_modules/**',
+ '<%= files.js %>'
]
- },
- jscs: {
- src: '<%= files.js %>'
},
banana: {
all: 'i18n/'
@@ -40,7 +34,7 @@
}
} );
- grunt.registerTask( 'lint', [ 'jshint', 'jscs', 'jsonlint', 'banana',
'stylelint' ] );
+ grunt.registerTask( 'lint', [ 'eslint', 'jsonlint', 'banana',
'stylelint' ] );
grunt.registerTask( 'test', [ 'lint' ] );
grunt.registerTask( 'default', 'test' );
};
diff --git a/package.json b/package.json
index cc231b1..033de20 100644
--- a/package.json
+++ b/package.json
@@ -5,11 +5,12 @@
"test": "grunt test"
},
"devDependencies": {
+ "eslint": "^3.19.0",
+ "eslint-config-wikimedia": "^0.4.0",
"grunt": "0.4.5",
- "grunt-cli": "0.1.13",
"grunt-banana-checker": "0.4.0",
- "grunt-contrib-jshint": "1.0.0",
- "grunt-jscs": "2.8.0",
+ "grunt-cli": "0.1.13",
+ "grunt-eslint": "^19.0.0",
"grunt-jsonlint": "1.0.7",
"grunt-stylelint": "0.6.0",
"stylelint-config-wikimedia": "0.4.1"
diff --git a/resources/ext.quicksurveys.init/init.js
b/resources/ext.quicksurveys.init/init.js
index 4fee33a..e95914d 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -1,4 +1,4 @@
-( function ( $ ) {
+( function ( $, mw ) {
var isMainPage = mw.config.get( 'wgIsMainPage' ),
$bodyContent = $( '#bodyContent' ),
isMobileLayout = window.innerWidth <= 768,
@@ -28,4 +28,4 @@
mw.extQuickSurveys.showSurvey( $bodyContent, isMobileLayout );
}
-}( jQuery ) );
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.quicksurveys.lib/lib.js
b/resources/ext.quicksurveys.lib/lib.js
index 48400b3..3cf11ea 100644
--- a/resources/ext.quicksurveys.lib/lib.js
+++ b/resources/ext.quicksurveys.lib/lib.js
@@ -1,5 +1,4 @@
-// jscs:disable disallowDanglingUnderscores
-( function ( $ ) {
+( function ( $, mw ) {
var survey,
availableSurveys = [],
$window = $( window ),
@@ -105,6 +104,94 @@
}
/**
+ * Return a survey from the available surveys given the survey query
string.
+ * If the query string is 'true' return a random survey.
+ * If the query string is either 'internal-survey-XXX' or
'external-survey-XXX' where
+ * 'XXX' is the survey name, then return the survey with the name XXX.
+ * Return null in the remaining cases.
+ *
+ * @param {string} queryString query string
+ * @param {Array} availableSurveys array of survey objects
+ * @return {Object|null} Survey object or null
+ */
+ function getSurveyFromQueryString( queryString, availableSurveys ) {
+ var surveyIndex,
+ surveyType,
+ surveyName,
+ survey = null;
+
+ // true returns a random survey
+ if ( queryString === 'true' ) {
+ surveyIndex = Math.floor( Math.random() *
availableSurveys.length );
+ survey = availableSurveys[ surveyIndex ];
+ } else if ( queryString.indexOf( 'internal-survey-' ) === 0 ) {
+ surveyType = 'internal';
+ } else if ( queryString.indexOf( 'external-survey-' ) === 0 ) {
+ surveyType = 'external';
+ }
+
+ if ( surveyType ) {
+ surveyName = queryString.split( '-' ).slice( 2 ).join(
'-' );
+ availableSurveys = $.grep( availableSurveys, function (
survey ) {
+ return survey.name === surveyName &&
survey.type === surveyType;
+ } );
+ if ( availableSurveys.length ) {
+ survey = availableSurveys[ 0 ];
+ }
+ }
+
+ return survey;
+ }
+
+ /**
+ * Get the storage key for the given survey.
+ *
+ * @param {Object} survey
+ * @return {string} The survey localStorage key
+ */
+ function getSurveyStorageKey( survey ) {
+ return 'ext-quicksurvey-' + survey.name.replace( / /g, '-' );
+ }
+
+ /**
+ * Get the survey token for the given survey.
+ *
+ * @param {Object} survey
+ * @return {string} The survey token
+ */
+ function getSurveyToken( survey ) {
+ return mw.storage.get( getSurveyStorageKey( survey ) );
+ }
+
+ /**
+ * Get the bucket for the given survey.
+ * Initializes the survey storage with a token
+ *
+ * @param {Object} survey
+ * @return {string} The bucket
+ */
+ function getBucketForSurvey( survey ) {
+ var control = 1 - survey.coverage,
+ a = survey.coverage,
+ storageId = getSurveyStorageKey( survey ),
+ token = getSurveyToken( survey );
+
+ if ( !token ) {
+ // Generate a new token for each survey
+ token = mw.user.generateRandomSessionId();
+ mw.storage.set( storageId, token );
+ }
+ return mw.experiments.getBucket( {
+ name: survey.name,
+ enabled: true,
+ buckets: {
+ control: Number( control ),
+ A: Number( a )
+ }
+ }, token );
+ }
+
+ /**
* Show survey
*
* @param {jQuery.Object} $bodyContent to add the panel
@@ -174,94 +261,10 @@
}
}
- /**
- * Get the bucket for the given survey.
- * Initializes the survey storage with a token
- *
- * @return {string} The bucket
- */
- function getBucketForSurvey( survey ) {
- var control = 1 - survey.coverage,
- a = survey.coverage,
- storageId = getSurveyStorageKey( survey ),
- token = getSurveyToken( survey );
-
- if ( !token ) {
- // Generate a new token for each survey
- token = mw.user.generateRandomSessionId();
- mw.storage.set( storageId, token );
- }
- return mw.experiments.getBucket( {
- name: survey.name,
- enabled: true,
- buckets: {
- control: Number( control ),
- A: Number( a )
- }
- }, token );
- }
-
- /**
- * Get the storage key for the given survey.
-
- * @return {String} The survey localStorage key
- */
- function getSurveyStorageKey( survey ) {
- return 'ext-quicksurvey-' + survey.name.replace( / /g, '-' );
- }
-
- /**
- * Get the survey token for the given survey.
-
- * @returns {String} The survey token
- */
- function getSurveyToken( survey ) {
- return mw.storage.get( getSurveyStorageKey( survey ) );
- }
-
- /**
- * Return a survey from the available surveys given the survey query
string.
- * If the query string is 'true' return a random survey.
- * If the query string is either 'internal-survey-XXX' or
'external-survey-XXX' where
- * 'XXX' is the survey name, then return the survey with the name XXX.
- * Return null in the remaining cases.
- *
- * @param {string} queryString query string
- * @param {Array} availableSurveys array of survey objects
- * @return {Object|null} Survey object or null
- */
- function getSurveyFromQueryString( queryString, availableSurveys ) {
- var surveyIndex,
- surveyType,
- surveyName,
- survey = null;
-
- // true returns a random survey
- if ( queryString === 'true' ) {
- surveyIndex = Math.floor( Math.random() *
availableSurveys.length );
- survey = availableSurveys[ surveyIndex ];
- } else if ( queryString.indexOf( 'internal-survey-' ) === 0 ) {
- surveyType = 'internal';
- } else if ( queryString.indexOf( 'external-survey-' ) === 0 ) {
- surveyType = 'external';
- }
-
- if ( surveyType ) {
- surveyName = queryString.split( '-' ).slice( 2 ).join(
'-' );
- availableSurveys = $.grep( availableSurveys, function (
survey ) {
- return survey.name === surveyName &&
survey.type === surveyType;
- } );
- if ( availableSurveys.length ) {
- survey = availableSurveys[ 0 ];
- }
- }
-
- return survey;
- }
-
mw.extQuickSurveys = {
+ /* eslint-disable-next-line no-underscore-dangle */
_insertPanel: insertPanel,
views: {},
showSurvey: showSurvey
};
-}( jQuery ) );
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.quicksurveys.views/ExternalSurvey.js
b/resources/ext.quicksurveys.views/ExternalSurvey.js
index ba75014..c4fbf88 100644
--- a/resources/ext.quicksurveys.views/ExternalSurvey.js
+++ b/resources/ext.quicksurveys.views/ExternalSurvey.js
@@ -1,9 +1,11 @@
-( function ( $ ) {
+( function ( $, mw ) {
var utils = mw.extQuickSurveys.views.utils,
QuickSurvey = mw.extQuickSurveys.views.QuickSurvey;
/**
* @class ExternalSurvey
+ * @constructor
+ * @param {Object} config
*/
function ExternalSurvey( config ) {
this.initialize( config );
@@ -27,22 +29,22 @@
}
buttons = [
- {
- href: btnHref.toString(),
- target: '_blank',
- label: mw.msg(
'ext-quicksurveys-external-survey-yes-button' ),
- flags: 'constructive',
- data: {
- answer:
'ext-quicksurveys-external-survey-yes-button'
- }
- },
- {
- label: mw.msg(
'ext-quicksurveys-external-survey-no-button' ),
- data: {
- answer:
'ext-quicksurveys-external-survey-no-button'
- }
+ {
+ href: btnHref.toString(),
+ target: '_blank',
+ label: mw.msg(
'ext-quicksurveys-external-survey-yes-button' ),
+ flags: 'constructive',
+ data: {
+ answer:
'ext-quicksurveys-external-survey-yes-button'
}
- ];
+ },
+ {
+ label: mw.msg(
'ext-quicksurveys-external-survey-no-button' ),
+ data: {
+ answer:
'ext-quicksurveys-external-survey-no-button'
+ }
+ }
+ ];
$.each( buttons, function () {
var button = new OO.ui.ButtonWidget( this );
@@ -56,4 +58,4 @@
} );
mw.extQuickSurveys.views.ExternalSurvey = ExternalSurvey;
-}( jQuery ) );
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.quicksurveys.views/QuickSurvey.js
b/resources/ext.quicksurveys.views/QuickSurvey.js
index c8ee89f..26624cc 100644
--- a/resources/ext.quicksurveys.views/QuickSurvey.js
+++ b/resources/ext.quicksurveys.views/QuickSurvey.js
@@ -1,9 +1,12 @@
-( function ( $ ) {
+( function ( $, mw ) {
var utils = mw.extQuickSurveys.views.utils;
/**
* @class QuickSurvey
* @extends OO.ui.StackLayout
+ *
+ * @constructor
+ * @param {Object} config
*/
function QuickSurvey( config ) {
this.initialize( config );
@@ -60,6 +63,7 @@
this.renderButtons();
// setup stack
+ // eslint-disable-next-line dot-notation
QuickSurvey.super.call( this, $.extend( {}, config, {
items: [ this.initialPanel, this.finalPanel ]
} ) );
@@ -105,6 +109,7 @@
* @param {string} widgetName a valid OOJS UI widget
* @param {string} [templatePartialName] name of a registered
template partial
* @param {Object} [options] further options to be passed to
the widget
+ * @return {*} OOUI widget instance
*/
widget: function ( widgetName, templatePartialName, options ) {
var template,
@@ -132,7 +137,7 @@
mobileMode = mw.config.get( 'wgMFMode' );
// On mobile differentiate between minerva stable and
beta by appending 'beta' to 'minerva'
- if ( skin === 'minerva' && mobileMode === 'beta' ) {
+ if ( skin === 'minerva' && mobileMode === 'beta' ) {
skin += mobileMode;
}
@@ -173,4 +178,4 @@
// This always makes me sad... https://phabricator.wikimedia.org/T108655
mw.extQuickSurveys.views.QuickSurvey = QuickSurvey;
-}( jQuery ) );
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.quicksurveys.views/utils.js
b/resources/ext.quicksurveys.views/utils.js
index eb7940c..5bb8b13 100644
--- a/resources/ext.quicksurveys.views/utils.js
+++ b/resources/ext.quicksurveys.views/utils.js
@@ -1,4 +1,4 @@
-( function () {
+( function ( mw ) {
/**
* Extends a class with new methods and member properties.
* FIXME: Talk about upstreaming this to oojs ui as a utility function.
@@ -70,4 +70,4 @@
getEditCountBucket: getEditCountBucket,
getCountryCode: getCountryCode
};
-}( jQuery ) );
+}( mediaWiki ) );
diff --git a/resources/mediawiki.template.muhogan/init.js
b/resources/mediawiki.template.muhogan/init.js
index d00e085..52c891c 100644
--- a/resources/mediawiki.template.muhogan/init.js
+++ b/resources/mediawiki.template.muhogan/init.js
@@ -1,5 +1,5 @@
// Register the Hogan compiler with MediaWiki.
-( function () {
+( function ( mw ) {
var compiler;
/*
* Mustache/Hogan template compiler
@@ -12,4 +12,4 @@
// register hybrid compiler with core
mw.template.registerCompiler( 'muhogan', compiler );
-}() );
+}( mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/355410
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2a71f4e6089a3031ed4ccc444f5d29dfc1d4158f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits