jenkins-bot has submitted this change and it was merged.
Change subject: Add jscs and jshint tasks to the Gruntfile
......................................................................
Add jscs and jshint tasks to the Gruntfile
Adds the jscs and jshint packages for development and their tasks in
Grunt. Also fixes all the code convention errors.
Change-Id: If1c9dfdbe22d4912d78b6a51b1292866970a85cc
---
A .jscsrc
M Gruntfile.js
M package.json
M resources/ext.popups.core.js
M resources/ext.popups.disablenavpop.js
M resources/ext.popups.logger.js
M resources/ext.popups.renderer.article.js
M resources/ext.popups.renderer.js
M resources/ext.popups.settings.js
M tests/qunit/ext.popups.core.test.js
M tests/qunit/ext.popups.renderer.article.test.js
11 files changed, 103 insertions(+), 86 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.jscsrc b/.jscsrc
new file mode 100644
index 0000000..a031ea4
--- /dev/null
+++ b/.jscsrc
@@ -0,0 +1,3 @@
+{
+ "preset": "wikimedia"
+}
\ No newline at end of file
diff --git a/Gruntfile.js b/Gruntfile.js
index 9c56558..2b95ad9 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,11 +1,22 @@
/*jshint node:true */
module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-banana-checker' );
+ grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+ grunt.loadNpmTasks( 'grunt-jscs' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.initConfig( {
banana: {
all: 'i18n/'
+ },
+ jscs: {
+ src: 'resources/*.js'
+ },
+ jshint: {
+ options: {
+ jshintrc: true
+ },
+ all: [ 'resources/*.js' ]
},
jsonlint: {
all: [
@@ -15,6 +26,6 @@
}
} );
- 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 063f93f..589eed3 100644
--- a/package.json
+++ b/package.json
@@ -6,8 +6,10 @@
},
"devDependencies": {
"grunt": "0.4.5",
- "grunt-cli": "0.1.13",
"grunt-banana-checker": "0.2.2",
+ "grunt-cli": "0.1.13",
+ "grunt-contrib-jshint": "0.11.2",
+ "grunt-jscs": "2.1.0",
"grunt-jsonlint": "1.0.4"
}
}
diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index f29c52e..2b2ce8d 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -15,7 +15,7 @@
* Set to false on Internet Explorer because adding SVGs
* through JavaScript in IE is failing. Thus, falling back to PNGs
*
- * @property {Boolean} supportsSVG
+ * @property {boolean} supportsSVG
*/
mw.popups.supportsSVG = ( $.client.profile().name === 'msie' ) ?
false :
@@ -29,7 +29,7 @@
/**
* Whether the page is being scrolled.
- * @property {Boolean} scrolled
+ * @property {boolean} scrolled
*/
mw.popups.scrolled = false;
@@ -90,7 +90,7 @@
mw.popups.$popup = $( '<div>' )
.attr( {
'class': 'mwe-popups',
- 'role': 'tooltip',
+ role: 'tooltip',
'aria-hidden': 'true'
} )
.appendTo( document.body );
@@ -186,7 +186,7 @@
titleRegex = new RegExp( mw.RegExp.escape(
mw.config.get( 'wgArticlePath' ) )
.replace( '\\$1', '(.+)' ) );
matches = titleRegex.exec( linkHref.path );
- return matches ? decodeURIComponent( matches[1] ) :
undefined;
+ return matches ? decodeURIComponent( matches[ 1 ] ) :
undefined;
}
};
@@ -198,7 +198,7 @@
mw.popups.selectPopupElements = function () {
var contentNamespaces = mw.config.get( 'wgContentNamespaces' );
return mw.popups.$content
- .find( 'a[href][title]:not(' +
mw.popups.IGNORE_CLASSES.join(', ') + ')' )
+ .find( 'a[href][title]:not(' +
mw.popups.IGNORE_CLASSES.join( ', ' ) + ')' )
.filter( function () {
var title,
titleText = mw.popups.getTitle(
this.href );
@@ -211,9 +211,10 @@
} );
};
- mw.hook( 'wikipage.content').add( function ( $content ) {
+ mw.hook( 'wikipage.content' ).add( function ( $content ) {
+ var $elements;
mw.popups.$content = $content;
- var $elements = mw.popups.selectPopupElements();
+ $elements = mw.popups.selectPopupElements();
if ( mw.popups.enabled ) {
mw.popups.removeTooltips( $elements );
@@ -222,21 +223,22 @@
// Events are logged even when Hovercards are disabled
// See T88166 for details
$elements.on( 'click', function ( event ) {
+ var $this, href, action, logEvent, logPromise;
+
if ( mw.popups.logger === undefined ) {
return true;
}
- var
- $this = $( this ),
- href = $this.attr( 'href' ),
- action = mw.popups.logger.getAction(
event ),
- logEvent = {
- pageTitleHover: $this.attr(
'title' ),
- pageTitleSource: mw.config.get(
'wgTitle' ),
- popupEnabled: mw.popups.enabled,
- action: action
- },
- logPromise = mw.popups.logger.log(
logEvent );
+ $this = $( this );
+ href = $this.attr( 'href' );
+ action = mw.popups.logger.getAction( event );
+ logEvent = {
+ pageTitleHover: $this.attr( 'title' ),
+ pageTitleSource: mw.config.get(
'wgTitle' ),
+ popupEnabled: mw.popups.enabled,
+ action: action
+ };
+ logPromise = mw.popups.logger.log( logEvent );
if ( action === 'opened in same tab' ) {
event.preventDefault();
@@ -256,4 +258,4 @@
}
} );
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/resources/ext.popups.disablenavpop.js
b/resources/ext.popups.disablenavpop.js
index a51b47b..d85787c 100644
--- a/resources/ext.popups.disablenavpop.js
+++ b/resources/ext.popups.disablenavpop.js
@@ -19,4 +19,4 @@
pg.fn.disablePopups();
}
};
-} ( jQuery, mediaWiki ) );
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.popups.logger.js b/resources/ext.popups.logger.js
index 81a26d4..a01dd55 100644
--- a/resources/ext.popups.logger.js
+++ b/resources/ext.popups.logger.js
@@ -54,9 +54,9 @@
delete event.time;
}
- return mw.eventLog.logEvent( 'Popups', event );
+ return mw.eventLog.logEvent( 'Popups', event );
};
mw.popups.logger = logger;
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/resources/ext.popups.renderer.article.js
b/resources/ext.popups.renderer.article.js
index 5be74c8..4562c77 100644
--- a/resources/ext.popups.renderer.article.js
+++ b/resources/ext.popups.renderer.article.js
@@ -25,7 +25,6 @@
pokeySize: 8 // Height of the triangle used to point at the link
};
-
/**
* Survey link, if any, for this renderer
* @property surveyLink
@@ -73,15 +72,15 @@
if (
!re.query ||
!re.query.pages ||
- !re.query.pages[0].extract ||
- re.query.pages[0].extract === ''
+ !re.query.pages[ 0 ].extract ||
+ re.query.pages[ 0 ].extract === ''
) {
deferred.reject();
return;
}
mw.popups.render.cache[ href ] = {};
- mw.popups.render.cache[ href ].popup =
article.createPopup( re.query.pages[0], href );
+ mw.popups.render.cache[ href ].popup =
article.createPopup( re.query.pages[ 0 ], href );
mw.popups.render.cache[ href ].getOffset =
article.getOffset;
mw.popups.render.cache[ href ].getClasses =
article.getClasses;
mw.popups.render.cache[ href ].process =
article.processPopup;
@@ -99,7 +98,7 @@
*
* @method createPopup
* @param {Object} page Information about the linked page
- * @param {String} href
+ * @param {string} href
* @return {jQuery}
*/
article.createPopup = function ( page, href ) {
@@ -113,7 +112,7 @@
thumbnail = page.thumbnail,
tall = thumbnail && thumbnail.height > thumbnail.width,
$thumbnail = article.createThumbnail( thumbnail, tall ),
- timestamp = new Date( page.revisions[0].timestamp ),
+ timestamp = new Date( page.revisions[ 0 ].timestamp ),
timediff = new Date() - timestamp,
oneDay = 1000 * 60 * 60 * 24,
timestampclass = ( timediff < oneDay ) ?
@@ -138,7 +137,6 @@
$timestamp.append( $surveyImage );
}
-
if ( $thumbnail.prop( 'tagName' ) !== 'SPAN' ) {
$thumbnail = $( '<a>' )
.addClass( 'mwe-popups-discreet' )
@@ -151,9 +149,9 @@
$div = $( '<div>' ).append( $thumbnail, $contentbox, $timestamp
);
mw.popups.render.cache[ href ].settings = {
- 'title': page.title,
- 'tall': ( tall === undefined ) ? false : tall,
- 'thumbnail': ( thumbnail === undefined ) ? false :
thumbnail
+ title: page.title,
+ tall: ( tall === undefined ) ? false : tall,
+ thumbnail: ( thumbnail === undefined ) ? false :
thumbnail
};
return $div;
@@ -164,21 +162,20 @@
* and making the title in the extract bold.
*
* @method getProcessedElements
- * @param {String} extract Should be unescaped
- * @param {String} title Should be unescaped
+ * @param {string} extract Should be unescaped
+ * @param {string} title Should be unescaped
* @return {Array} of elements to appended
*/
article.getProcessedElements = function ( extract, title ) {
- title = title.replace( /([.?*+^$[\]\\(){}|-])/g, '\\$1' ); //
Escape RegExp elements
-
var elements = [],
- regExp = new RegExp( '(^|\\s)(' + title + ')(|$)', 'ig'
),
+ escapedTitle = title.replace( /([.?*+^$[\]\\(){}|-])/g,
'\\$1' ), // Escape RegExp elements
+ regExp = new RegExp( '(^|\\s)(' + escapedTitle +
')(|$)', 'ig' ),
boldIdentifier = '<bi-' + Math.random() + '>',
snip = '<snip-' + Math.random() + '>';
// Remove text in parentheses along with the parentheses
extract = article.removeParensFromText( extract );
- extract = extract.replace(/\s+/g, ' '); // Remove extra white
spaces
+ extract = extract.replace( /\s+/g, ' ' ); // Remove extra white
spaces
// Make title bold in the extract text
// As the extract is html escaped there can be no such string
in it
@@ -203,8 +200,8 @@
* remove extra spaces.
*
* @method removeParensFromText
- * @param {String} string
- * @return {String}
+ * @param {string} string
+ * @return {string}
*/
article.removeParensFromText = function ( string ) {
var
@@ -213,7 +210,7 @@
level = 0,
i = 0;
- for( i; i < string.length; i++ ) {
+ for ( i; i < string.length; i++ ) {
ch = string.charAt( i );
if ( ch === ')' && level === 0 ) {
@@ -244,7 +241,7 @@
* to `img` tag, thus an `svg:image` is required.
*
* @method createSVGTag
- * @param {String} tag
+ * @param {string} tag
* @return {Object}
*/
article.createSVGTag = function ( tag ) {
@@ -330,15 +327,15 @@
* Returns the `svg:image` object for thumbnail
*
* @method createSvgImageThumbnail
- * @param {String} className
- * @param {String} url
- * @param {Number} x
- * @param {Number} y
- * @param {Number} thumbnailWidth
- * @param {Number} thumbnailHeight
- * @param {Number} width
- * @param {Number} height
- * @param {String} clipPath
+ * @param {string} className
+ * @param {string} url
+ * @param {number} x
+ * @param {number} y
+ * @param {number} thumbnailWidth
+ * @param {number} thumbnailHeight
+ * @param {number} width
+ * @param {number} height
+ * @param {string} clipPath
* @return {jQuery}
*/
article.createSvgImageThumbnail = function (
@@ -373,8 +370,8 @@
* Returns the `img` object for thumbnail
*
* @method createImgThumbnail
- * @param {String} className
- * @param {String} url
+ * @param {string} className
+ * @param {string} url
* @return {jQuery}
*/
article.createImgThumbnail = function ( className, url ) {
@@ -516,7 +513,7 @@
} );
if ( !flippedY && !tall && cache.settings.thumbnail.height <
article.SIZES.landscapeImage.h ) {
- $( '.mwe-popups-extract').css(
+ $( '.mwe-popups-extract' ).css(
'margin-top',
cache.settings.thumbnail.height -
article.SIZES.pokeySize
);
@@ -560,4 +557,4 @@
mw.popups.render.article = article;
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/resources/ext.popups.renderer.js b/resources/ext.popups.renderer.js
index bfcd0c4..3eb0c8a 100644
--- a/resources/ext.popups.renderer.js
+++ b/resources/ext.popups.renderer.js
@@ -67,7 +67,7 @@
// anchor tag. In such a case, the timer to close the box is
cleared.
if (
mw.popups.render.currentLink &&
- mw.popups.render.currentLink[0] === link[0]
+ mw.popups.render.currentLink[ 0 ] === link[ 0 ]
) {
if ( mw.popups.render.closeTimer ) {
mw.popups.render.closeTimer.abort();
@@ -195,6 +195,8 @@
* @method closePopup
*/
mw.popups.render.closePopup = function () {
+ var fadeInClass, fadeOutClass;
+
if ( mw.popups.render.currentLink === undefined ) {
return false;
}
@@ -205,8 +207,6 @@
}
$( mw.popups.render.currentLink ).off( 'mouseleave blur',
mw.popups.render.leaveActive );
-
- var fadeInClass, fadeOutClass;
fadeInClass = ( mw.popups.$popup.hasClass(
'mwe-popups-fade-in-up' ) ) ?
'mwe-popups-fade-in-up' :
@@ -242,7 +242,7 @@
* to perform the equivalent of `clearTimeout()`
*
* @method wait
- * @param {Number} ms Milliseconds to wait
+ * @param {number} ms Milliseconds to wait
* @return {jQuery.Promise}
*/
mw.popups.render.wait = function ( ms ) {
@@ -315,4 +315,4 @@
mw.popups.render.closeTimer = undefined;
};
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/resources/ext.popups.settings.js b/resources/ext.popups.settings.js
index 25ae18f..bc873a2 100644
--- a/resources/ext.popups.settings.js
+++ b/resources/ext.popups.settings.js
@@ -60,17 +60,17 @@
$form = $( '<form>' ).append( $radioGroup, $actions ),
$main = $( '<main>' ).attr( 'id',
'mwe-popups-settings-form' ).append( $description, $form ),
options = {
- 'simple': [
+ simple: [
mw.message(
'popups-settings-option-simple' ).text(),
mw.message(
'popups-settings-option-simple-description' ).text(),
'images/hovercard.svg'
],
- 'advanced': [
+ advanced: [
mw.message(
'popups-settings-option-advanced' ).text(),
mw.message(
'popups-settings-option-advanced-description' ).text(),
'images/navpop.svg'
],
- 'off': [
+ off: [
mw.message(
'popups-settings-option-off' ).text(),
mw.message(
'popups-settings-option-off-description' ).text()
]
@@ -101,8 +101,9 @@
* Renders an option with its input[type='radio'], label and image
*
* @method renderOption
+ * @param {string} id
* @param {Array} content
- * @param {Boolean} checked
+ * @param {boolean} checked
* @return {jQuery} The paragraph that holds the above mentioned
elements
*/
settings.renderOption = function ( id, content, checked ) {
@@ -126,7 +127,7 @@
$input.prop( 'checked', true );
}
- if ( content.length === 3) {
+ if ( content.length === 3 ) {
$p.append(
$( '<img>' ).attr( 'src', mw.config.get(
'wgExtensionAssetsPath' ) + '/Popups/resources/' + content[ 2 ] )
);
@@ -141,7 +142,7 @@
* @method save
*/
settings.save = function () {
- var v =
$('input[name=mwe-popups-setting]:checked','#mwe-popups-settings').val();
+ var v = $( 'input[name=mwe-popups-setting]:checked',
'#mwe-popups-settings' ).val();
if ( v === 'simple' ) {
$.jStorage.set( 'mwe-popups-enabled', 'true' );
location.reload();
@@ -199,21 +200,22 @@
* @method addFooterLink
*/
settings.addFooterLink = function () {
+ var $setting, $footer;
+
if ( mw.popups.enabled ) {
return false;
}
- var
- $setting = $( '<li>' ).append(
- $( '<a>' )
- .attr( 'href', '#' )
- .text( mw.message(
'popups-settings-enable' ).text() )
- .click( function ( e ) {
- settings.open();
- e.preventDefault();
- } )
- ),
- $footer = $( '#footer-places, #f-list' );
+ $setting = $( '<li>' ).append(
+ $( '<a>' )
+ .attr( 'href', '#' )
+ .text( mw.message( 'popups-settings-enable'
).text() )
+ .click( function ( e ) {
+ settings.open();
+ e.preventDefault();
+ } )
+ );
+ $footer = $( '#footer-places, #f-list' );
// From
https://en.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.js
if ( $footer.length === 0 ) {
@@ -223,11 +225,11 @@
};
$( function () {
- if( !mw.popups.enabled ) {
+ if ( !mw.popups.enabled ) {
settings.addFooterLink();
}
} );
mw.popups.settings = settings;
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/tests/qunit/ext.popups.core.test.js
b/tests/qunit/ext.popups.core.test.js
index cd82edd..a006e7b 100644
--- a/tests/qunit/ext.popups.core.test.js
+++ b/tests/qunit/ext.popups.core.test.js
@@ -27,10 +27,10 @@
];
for ( i = 0; i < cases.length; i++ ) {
- expected = cases[i][1];
- actual = mw.popups.getTitle( cases[i][0] );
+ expected = cases[ i ][ 1 ];
+ actual = mw.popups.getTitle( cases[ i ][ 0 ] );
assert.equal( actual, expected );
}
} );
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
diff --git a/tests/qunit/ext.popups.renderer.article.test.js
b/tests/qunit/ext.popups.renderer.article.test.js
index 6c735f0..e2f40b0 100644
--- a/tests/qunit/ext.popups.renderer.article.test.js
+++ b/tests/qunit/ext.popups.renderer.article.test.js
@@ -5,7 +5,7 @@
QUnit.test( 'render.article.getProcessedElements', function ( assert ) {
QUnit.expect( 13 );
- function test ( extract, title, expected, msg ) {
+ function test( extract, title, expected, msg ) {
var $div = $( '<div>' ).append(
mw.popups.render.article.getProcessedElements(
extract, title )
);
@@ -92,4 +92,4 @@
} );
-} ) ( jQuery, mediaWiki );
+} )( jQuery, mediaWiki );
--
To view, visit https://gerrit.wikimedia.org/r/233927
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1c9dfdbe22d4912d78b6a51b1292866970a85cc
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
Gerrit-Reviewer: Bartosz DziewoĆski <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits