mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-24 07:23:41 +00:00
Add eslint, to be used instead of jscs and/or jshint
First I jumped on replacing both jscs and jshint with eslint but it might be premature decision. Although linting with eslint is possible (like in there is wikimedia config for eslint) it is still not clear should it But in case the change happens we will be ready. Apart from config stuff this changes few bits spotted by eslint: improves some indentation, removes weird spaces, completes some doc blocks, changes IIFE forms in tests. These changes do not seem controversial. Change-Id: I9f8bf0f5745da8e662685f4cd879ea4baa609c01
This commit is contained in:
parent
b411c98225
commit
8e7fe2434d
13
.eslintrc
Normal file
13
.eslintrc
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"extends": "wikimedia",
|
||||
|
||||
"env": {
|
||||
"browser": true,
|
||||
"jquery": true,
|
||||
"qunit": true
|
||||
},
|
||||
"globals": {
|
||||
"mediaWiki": false,
|
||||
"OO": false
|
||||
}
|
||||
}
|
12
Gruntfile.js
12
Gruntfile.js
|
@ -1,12 +1,20 @@
|
|||
/*jshint node:true */
|
||||
/* jshint node:true */
|
||||
module.exports = function ( grunt ) {
|
||||
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
||||
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
|
||||
grunt.loadNpmTasks( 'grunt-eslint' );
|
||||
grunt.loadNpmTasks( 'grunt-jscs' );
|
||||
grunt.loadNpmTasks( 'grunt-jsonlint' );
|
||||
grunt.loadNpmTasks( 'grunt-stylelint' );
|
||||
|
||||
grunt.initConfig( {
|
||||
eslint: {
|
||||
all: [
|
||||
'*.js',
|
||||
'tests/**/*.js',
|
||||
'modules/**/*.js'
|
||||
]
|
||||
},
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: true
|
||||
|
@ -38,6 +46,6 @@ module.exports = function ( grunt ) {
|
|||
}
|
||||
} );
|
||||
|
||||
grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'stylelint', 'banana' ] );
|
||||
grunt.registerTask( 'test', [ 'eslint', 'jshint', 'jscs', 'jsonlint', 'stylelint', 'banana' ] );
|
||||
grunt.registerTask( 'default', 'test' );
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* @param {number} [options.startId] Start ID
|
||||
* @param {number} [options.endId] End ID
|
||||
* @param {Object} [options.knownUserGenders] Known user genders
|
||||
* @return {jQuery.Promise}
|
||||
*/
|
||||
fetchRevisionData: function ( pageName, options ) {
|
||||
var xhr, userXhr,
|
||||
|
@ -31,9 +32,11 @@
|
|||
xhr = this.fetchRevisions( pageName, options )
|
||||
.done( function ( data ) {
|
||||
var revs = data.query.pages[ 0 ].revisions,
|
||||
/*jshint -W024 */
|
||||
/* eslint-disable dot-notation */
|
||||
/* jshint -W024 */
|
||||
revContinue = data.continue,
|
||||
/*jshint +W024 */
|
||||
/* jshint +W024 */
|
||||
/* eslint-enable dot-notation */
|
||||
genderData = options.knownUserGenders || {},
|
||||
userNames;
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@
|
|||
* @param {number} revId1
|
||||
* @param {number} revId2
|
||||
* @param {SliderView} sliderView
|
||||
* @return {Object}
|
||||
*/
|
||||
getStateObject: function ( revId1, revId2, sliderView ) {
|
||||
return {
|
||||
|
@ -136,6 +137,7 @@
|
|||
*
|
||||
* @param {number} revId1
|
||||
* @param {number} revId2
|
||||
* @return {string}
|
||||
*/
|
||||
getStateUrl: function ( revId1, revId2 ) {
|
||||
var url = mw.util.wikiScript( 'index' ) + '?diff=' + Math.max( revId1, revId2 ) + '&oldid=' + Math.min( revId1, revId2 ),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
( function ( mw, $ ) {
|
||||
/* eslint-disable dot-notation */
|
||||
// JSHint does not like OOJS' usage of "static" and "super"
|
||||
/*jshint -W024 */
|
||||
/* jshint -W024 */
|
||||
|
||||
/**
|
||||
* Module containing the RevisionSlider tutorial
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
( function ( mw, $ ) {
|
||||
/*global moment:false */
|
||||
/* global moment:false */
|
||||
/**
|
||||
* @param {Object} data - Containing keys `id`, `size`, `comment`, `parsedcomment`, `timestamp`, `user` and `minor`
|
||||
* @constructor
|
||||
|
|
|
@ -170,8 +170,8 @@
|
|||
pointerContainerStyle = { right: pointerContainerPosition + 'px', width: pointerContainerWidth + 'px' };
|
||||
}
|
||||
$slider.css( {
|
||||
width: ( containerWidth + this.containerMargin ) + 'px'
|
||||
} )
|
||||
width: ( containerWidth + this.containerMargin ) + 'px'
|
||||
} )
|
||||
.append(
|
||||
this.backwardArrowButton.$element,
|
||||
$( '<div>' )
|
||||
|
@ -283,6 +283,8 @@
|
|||
* applied (blue border) which is not what is wanted. And generally setting a focus on disabled
|
||||
* buttons does not seem right in case of RevisionSlider's arrow buttons.
|
||||
* This method removes focus from the disabled button if such case happens.
|
||||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
arrowFocusHandler: function ( e ) {
|
||||
var button = e.data.button;
|
||||
|
@ -307,7 +309,7 @@
|
|||
$clickedRev.data( 'revid' )
|
||||
);
|
||||
} else {
|
||||
pOld.setPosition( parseInt( $clickedRev.attr( 'data-pos' ), 10 ) ) ;
|
||||
pOld.setPosition( parseInt( $clickedRev.attr( 'data-pos' ), 10 ) );
|
||||
view.refreshRevisions(
|
||||
$clickedRev.data( 'revid' ),
|
||||
view.getRevElementAtPosition( $revisions, pNew.getPosition() ).data( 'revid' )
|
||||
|
@ -599,11 +601,11 @@
|
|||
|
||||
self.addRevisionsAtEnd( $slider, revs );
|
||||
|
||||
/*jshint -W024 */
|
||||
if ( data.continue === undefined ) {
|
||||
/* jshint -W024 */
|
||||
if ( data.continue === undefined ) { // eslint-disable-line dot-notation
|
||||
self.noMoreNewerRevisions = true;
|
||||
}
|
||||
/*jshint +W024 */
|
||||
/* jshint +W024 */
|
||||
} );
|
||||
},
|
||||
|
||||
|
@ -640,11 +642,11 @@
|
|||
}
|
||||
self.addRevisionsAtStart( $slider, revs, precedingRevisionSize );
|
||||
|
||||
/*jshint -W024 */
|
||||
if ( data.continue === undefined ) {
|
||||
/* jshint -W024 */
|
||||
if ( data.continue === undefined ) { // eslint-disable-line dot-notation
|
||||
self.noMoreOlderRevisions = true;
|
||||
}
|
||||
/*jshint +W024 */
|
||||
/* jshint +W024 */
|
||||
} );
|
||||
},
|
||||
|
||||
|
@ -777,6 +779,7 @@
|
|||
|
||||
/**
|
||||
* @param {jQuery} $slider
|
||||
* @return {boolean}
|
||||
*/
|
||||
shouldExpandSlider: function ( $slider ) {
|
||||
var sliderWidth = parseInt( $slider.css( 'width' ), 10 ),
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
expanded = autoExpand,
|
||||
initialized = false,
|
||||
autoExpandButton,
|
||||
/*jshint -W024 */
|
||||
/* eslint-disable dot-notation */
|
||||
/* jshint -W024 */
|
||||
toggleButton = OO.ui.ButtonWidget.static.infuse( $( '.mw-revslider-toggle-button' ) ),
|
||||
/*jshint +W024 */
|
||||
/* jshint +W024 */
|
||||
/* eslint-enable dot-notation */
|
||||
initialize = function () {
|
||||
var startTime = mw.now(),
|
||||
api = new mw.libs.revisionSlider.Api( mw.util.wikiScript( 'api' ) );
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
"test": "grunt test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint-config-wikimedia": "0.1.0",
|
||||
"grunt": "1.0.1",
|
||||
"grunt-banana-checker": "0.5.0",
|
||||
"grunt-contrib-jshint": "1.0.0",
|
||||
"grunt-eslint": "19.0.0",
|
||||
"grunt-jscs": "3.0.0",
|
||||
"grunt-jsonlint": "1.0.8",
|
||||
"grunt-stylelint": "0.4.0",
|
||||
"stylelint-config-wikimedia": "0.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,4 +11,4 @@
|
|||
}
|
||||
}
|
||||
} );
|
||||
} )( jQuery );
|
||||
}( jQuery ) );
|
||||
|
|
|
@ -41,4 +41,4 @@
|
|||
);
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -40,4 +40,4 @@
|
|||
);
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -15,4 +15,4 @@
|
|||
assert.equal( pointer.getPosition(), pos );
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -24,4 +24,4 @@
|
|||
pv.getElement().addClass( 'mw-revslider-pointer-upper' );
|
||||
assert.equal( pv.getOffset(), 16 );
|
||||
} );
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -107,5 +107,5 @@
|
|||
assert.notOk( rev.hasEmptyComment() );
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@
|
|||
|
||||
QUnit.test( 'Push appends revisions to the end of the list', function ( assert ) {
|
||||
var list = new RevisionList( [
|
||||
new Revision( { revid: 1, size: 5 } ),
|
||||
new Revision( { revid: 2, size: 21 } ),
|
||||
new Revision( { revid: 3, size: 13 } )
|
||||
] ),
|
||||
new Revision( { revid: 1, size: 5 } ),
|
||||
new Revision( { revid: 2, size: 21 } ),
|
||||
new Revision( { revid: 3, size: 13 } )
|
||||
] ),
|
||||
revisions;
|
||||
list.push( [
|
||||
new Revision( { revid: 6, size: 19 } ),
|
||||
|
@ -117,7 +117,7 @@
|
|||
new Revision( { revid: 3, size: 13 } ),
|
||||
new Revision( { revid: 6, size: 19 } ),
|
||||
new Revision( { revid: 8, size: 25 } )
|
||||
] ),
|
||||
] ),
|
||||
slicedList = list.slice( 1, 3 ),
|
||||
revisions = slicedList.getRevisions();
|
||||
|
||||
|
@ -148,10 +148,10 @@
|
|||
|
||||
QUnit.test( 'makeRevisions converts revision data into list of Revision objects', function ( assert ) {
|
||||
var revs = [
|
||||
{ revid: 1, size: 5, userGender: 'female' },
|
||||
{ revid: 2, size: 21, userGender: 'unknown' },
|
||||
{ revid: 3, size: 13 }
|
||||
],
|
||||
{ revid: 1, size: 5, userGender: 'female' },
|
||||
{ revid: 2, size: 21, userGender: 'unknown' },
|
||||
{ revid: 3, size: 13 }
|
||||
],
|
||||
revisions = makeRevisions( revs );
|
||||
|
||||
assert.equal( revisions[ 0 ].getId(), 1 );
|
||||
|
@ -161,4 +161,4 @@
|
|||
assert.equal( revisions[ 2 ].getId(), 3 );
|
||||
assert.equal( revisions[ 2 ].getSize(), 13 );
|
||||
} );
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -189,4 +189,4 @@
|
|||
assert.ok( $pageSizeLineHtml.text().match( /1,337/ ) );
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
QUnit.test( 'has revisions', function ( assert ) {
|
||||
var revs = new RevisionList( [
|
||||
new Revision( { revid: 1 } ),
|
||||
new Revision( { revid: 2 } )
|
||||
] ),
|
||||
new Revision( { revid: 1 } ),
|
||||
new Revision( { revid: 2 } )
|
||||
] ),
|
||||
slider = new Slider( revs );
|
||||
|
||||
assert.equal( slider.getRevisions(), revs );
|
||||
|
@ -54,4 +54,4 @@
|
|||
assert.equal( slider.getFirstVisibleRevisionIndex(), 0 );
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
|
@ -51,11 +51,11 @@
|
|||
mw.config.values.extRevisionSliderOldRev = null;
|
||||
mw.config.values.extRevisionSliderNewRev = null;
|
||||
|
||||
assert.throws(
|
||||
assert.throws( // eslint-disable-line dot-notation
|
||||
function () {
|
||||
view.render( $container );
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
} )( mediaWiki );
|
||||
}( mediaWiki ) );
|
||||
|
|
Loading…
Reference in a new issue