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:
Leszek Manicki 2016-09-01 13:17:47 +02:00 committed by addshore
parent b411c98225
commit 8e7fe2434d
19 changed files with 76 additions and 42 deletions

13
.eslintrc Normal file
View file

@ -0,0 +1,13 @@
{
"extends": "wikimedia",
"env": {
"browser": true,
"jquery": true,
"qunit": true
},
"globals": {
"mediaWiki": false,
"OO": false
}
}

View file

@ -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' );
};

View file

@ -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;

View file

@ -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 ),

View file

@ -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

View file

@ -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

View file

@ -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 ),

View file

@ -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' ) );

View file

@ -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"
}
}
}
}

View file

@ -11,4 +11,4 @@
}
}
} );
} )( jQuery );
}( jQuery ) );

View file

@ -41,4 +41,4 @@
);
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -40,4 +40,4 @@
);
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -15,4 +15,4 @@
assert.equal( pointer.getPosition(), pos );
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -24,4 +24,4 @@
pv.getElement().addClass( 'mw-revslider-pointer-upper' );
assert.equal( pv.getOffset(), 16 );
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -107,5 +107,5 @@
assert.notOk( rev.hasEmptyComment() );
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -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 ) );

View file

@ -189,4 +189,4 @@
assert.ok( $pageSizeLineHtml.text().match( /1,337/ ) );
} );
} )( mediaWiki );
}( mediaWiki ) );

View file

@ -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 ) );

View file

@ -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 ) );