eslint: Enforce max-statements-per-line

Change-Id: I416d0c951d18f2fb3b477695ab0913f75fb60a68
This commit is contained in:
Ed Sanders 2023-06-27 21:33:13 +01:00
parent a33f7e5c57
commit 67188f8c31
14 changed files with 67 additions and 52 deletions

View file

@ -8,7 +8,6 @@
"rules": {
"no-var": "off",
"max-len": "off",
"max-statements-per-line": "off",
"no-jquery/no-class-state": "off",
"no-jquery/no-support": "off"
},

View file

@ -404,8 +404,12 @@ const Tab = require( './mmv.ui.reuse.tab.js' );
const sizes = this.getSizeOptions( image.width, image.height );
this.embedFileInfo = { imageInfo: image, repoInfo: repo };
if ( caption ) { this.embedFileInfo.caption = caption; }
if ( alt ) { this.embedFileInfo.alt = alt; }
if ( caption ) {
this.embedFileInfo.caption = caption;
}
if ( alt ) {
this.embedFileInfo.alt = alt;
}
this.utils.updateMenuOptions( sizes.html, htmlSizeOptions );
this.utils.updateMenuOptions( sizes.wikitext, wikitextSizeOptions );

View file

@ -64,7 +64,7 @@ const ThumbnailWidth = require( './model/mmv.model.ThumbnailWidth.js' );
* @property {number[]}
*/
this.widthBuckets = options.widthBuckets;
this.widthBuckets.sort( ( a, b ) => { return a - b; } );
this.widthBuckets.sort( ( a, b ) => a - b );
/**
* Screen pixel count per CSS pixel.

View file

@ -174,15 +174,21 @@ const UiElement = require( './ui/mmv.ui.js' );
this.fullscreenChange( e );
} );
this.handleEvent( 'keydown', ( e ) => { this.keydown( e ); } );
this.handleEvent( 'keydown', ( e ) => {
this.keydown( e );
} );
// mousemove generates a ton of events, which is why we throttle it
this.handleEvent( 'mousemove.lip', mw.util.throttle( ( e ) => {
this.mousemove( e );
}, 250 ) );
this.handleEvent( 'mmv-faded-out', ( e ) => { this.fadedOut( e ); } );
this.handleEvent( 'mmv-fade-stopped', ( e ) => { this.fadeStopped( e ); } );
this.handleEvent( 'mmv-faded-out', ( e ) => {
this.fadedOut( e );
} );
this.handleEvent( 'mmv-fade-stopped', ( e ) => {
this.fadeStopped( e );
} );
this.buttons.connect( this, {
next: [ 'emit', 'next' ],

View file

@ -10,7 +10,7 @@ const { ViewLogger } = require( 'mmv' );
// override that new behavior in order to run these tests...
// @see https://github.com/sinonjs/lolex/issues/76
this.oldNow = $.now;
$.now = function () { return Date.now(); };
$.now = () => Date.now();
},
afterEach: function () {

View file

@ -6,7 +6,9 @@ const { enterFullscreenMock, exitFullscreenMock, getMultimediaViewer } = require
function stubScrollTo() {
oldScrollTo = $.scrollTo;
$.scrollTo = function () { return { scrollTop: function () {}, on: function () {}, off: function () {} }; };
$.scrollTo = function () {
return { scrollTop: () => {}, on: () => {}, off: () => {} };
};
}
function restoreScrollTo() {

View file

@ -123,7 +123,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
viewer.setImage = function () {};
viewer.scroll = function () {};
viewer.preloadFullscreenThumbnail = function () {};
viewer.fetchSizeIndependentLightboxInfo = function () { return $.Deferred().resolve( {} ); };
viewer.fetchSizeIndependentLightboxInfo = () => $.Deferred().resolve( {} );
viewer.ui = {
setFileReuseData: function () {},
setupForLoad: function () {},
@ -146,9 +146,9 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
},
open: function () {} };
viewer.imageProvider.get = function () { return imageDeferred.promise(); };
viewer.imageInfoProvider.get = function () { return $.Deferred().resolve( {} ); };
viewer.thumbnailInfoProvider.get = function () { return $.Deferred().resolve( {} ); };
viewer.imageProvider.get = () => imageDeferred.promise();
viewer.imageInfoProvider.get = () => $.Deferred().resolve( {} );
viewer.thumbnailInfoProvider.get = () => $.Deferred().resolve( {} );
// loadImage will call setupProgressBar, which will attach done, fail &
// progress handlers
@ -201,7 +201,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
viewer.preloadFullscreenThumbnail = function () {};
viewer.preloadImagesMetadata = function () {};
viewer.preloadThumbnails = function () {};
viewer.fetchSizeIndependentLightboxInfo = function () { return $.Deferred().resolve( {} ); };
viewer.fetchSizeIndependentLightboxInfo = () => $.Deferred().resolve( {} );
viewer.ui = {
setFileReuseData: function () {},
setupForLoad: function () {},
@ -225,8 +225,8 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
open: function () {},
empty: function () {} };
viewer.imageInfoProvider.get = function () { return $.Deferred().resolve( {} ); };
viewer.thumbnailInfoProvider.get = function () { return $.Deferred().resolve( {} ); };
viewer.imageInfoProvider.get = () => $.Deferred().resolve( {} );
viewer.thumbnailInfoProvider.get = () => $.Deferred().resolve( {} );
// load some image
viewer.imageProvider.get = this.sandbox.stub().returns( firstImageDeferred );
@ -445,8 +445,8 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
viewer.eachPreloadableLightboxIndex = function () {};
viewer.animateMetadataDivOnce = this.sandbox.stub().returns( $.Deferred().reject() );
viewer.imageProvider.get = this.sandbox.stub();
viewer.imageInfoProvider.get = function () { return $.Deferred().reject(); };
viewer.thumbnailInfoProvider.get = function () { return $.Deferred().resolve( {} ); };
viewer.imageInfoProvider.get = () => $.Deferred().reject( {} );
viewer.thumbnailInfoProvider.get = () => $.Deferred().resolve( {} );
viewer.imageProvider.get.returns( firstImageDeferred.promise() );
viewer.fetchSizeIndependentLightboxInfo.returns( firstLigthboxInfoDeferred.promise() );
@ -470,7 +470,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
clock.tick( 10 );
assert.strictEqual( viewer.displayRealThumbnail.called, false, 'The first image being done loading should have no effect' );
viewer.displayRealThumbnail = this.sandbox.spy( function () { viewer.close(); } );
viewer.displayRealThumbnail = this.sandbox.spy( () => viewer.close() );
secondImageDeferred.resolve( {}, {} );
secondLigthboxInfoDeferred.resolve( {} );
clock.tick( 10 );
@ -495,14 +495,16 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
// animation would keep running, conflict with other tests
this.sandbox.stub( $.fn, 'animate' ).returnsThis();
$.scrollTo = function () { return { scrollTop: function () {}, on: function () {}, off: function () {} }; };
$.scrollTo = function () {
return { scrollTop: () => {}, on: () => {}, off: () => {} };
};
viewer.setupEventHandlers();
viewer.imageProvider.get = function () { return $.Deferred().reject(); };
viewer.imageInfoProvider.get = function () { return $.Deferred().reject(); };
viewer.thumbnailInfoProvider.get = function () { return $.Deferred().reject(); };
viewer.fileRepoInfoProvider.get = function () { return $.Deferred().reject(); };
viewer.imageProvider.get = () => $.Deferred().reject();
viewer.imageInfoProvider.get = () => $.Deferred().reject();
viewer.thumbnailInfoProvider.get = () => $.Deferred().reject();
viewer.fileRepoInfoProvider.get = () => $.Deferred().reject();
viewer.preloadFullscreenThumbnail = function () {};
viewer.initWithThumbs( [] );
@ -588,7 +590,7 @@ const { MultimediaViewerBootstrap } = require( 'mmv.bootstrap' );
imageStub,
promise,
useThumbnailGuessing,
viewer = new MultimediaViewer( { imageQueryParameter: function () {}, language: function () {}, recordVirtualViewBeaconURI: function () {}, extensions: function () { return { jpg: 'default' }; }, useThumbnailGuessing: function () { return useThumbnailGuessing; } } ),
viewer = new MultimediaViewer( { imageQueryParameter: function () {}, language: function () {}, recordVirtualViewBeaconURI: function () {}, extensions: function () { return { jpg: 'default' }; }, useThumbnailGuessing: () => useThumbnailGuessing } ),
sandbox = this.sandbox,
file = new mw.Title( 'File:Copyleft.svg' ),
sampleURL = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png',

View file

@ -41,7 +41,7 @@ const { TaskQueue } = require( 'mmv' );
task = $.Deferred(),
promise;
taskQueue.push( function () { return task; } );
taskQueue.push( () => task );
assert.strictEqual( taskQueue.state, TaskQueue.State.NOT_STARTED,
'state is initially NOT_STARTED' );
@ -63,7 +63,7 @@ const { TaskQueue } = require( 'mmv' );
var taskQueue = new TaskQueue(),
task = $.Deferred();
taskQueue.push( function () { return task; } );
taskQueue.push( () => task );
taskQueue.execute();
taskQueue.cancel();

View file

@ -36,7 +36,7 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
done = assert.async(),
result;
provider.getUrl = function () { return resultUrl; };
provider.getUrl = () => resultUrl;
result = provider.get( file, sampleUrl, width, originalWidth, originalHeight );
assert.true( typeof result.then === 'function', 'Result is a promise' );
assert.strictEqual( result.state(), 'resolved', 'Result is resolved' );
@ -47,7 +47,7 @@ const { GuessedThumbnailInfo } = require( 'mmv' );
done();
} );
provider.getUrl = function () { return undefined; };
provider.getUrl = () => undefined;
result = provider.get( file, sampleUrl, width, originalWidth, originalHeight );
assert.true( typeof result.then === 'function', 'Result is a promise' );
assert.strictEqual( result.state(), 'rejected', 'Result is rejected' );

View file

@ -32,7 +32,7 @@ const { ImageProvider } = require( 'mmv' );
'8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
imageProvider = new ImageProvider();
imageProvider.imagePreloadingSupported = function () { return false; };
imageProvider.imagePreloadingSupported = () => false;
return imageProvider.get( url ).then( function ( image ) {
assert.true( image instanceof HTMLImageElement,
@ -49,7 +49,7 @@ const { ImageProvider } = require( 'mmv' );
result,
imageProvider = new ImageProvider();
imageProvider.imagePreloadingSupported = function () { return false; };
imageProvider.imagePreloadingSupported = () => false;
return QUnit.whenPromisesComplete(
imageProvider.get( url ).then( function ( image ) {
@ -77,8 +77,10 @@ const { ImageProvider } = require( 'mmv' );
done = assert.async(),
mwLogCalled = false;
imageProvider.imagePreloadingSupported = function () { return false; };
mw.log = function () { mwLogCalled = true; };
imageProvider.imagePreloadingSupported = () => false;
mw.log = function () {
mwLogCalled = true;
};
imageProvider.get( 'doesntexist.png' ).fail( function () {
assert.true( true, 'fail handler was called' );
@ -93,7 +95,7 @@ const { ImageProvider } = require( 'mmv' );
imageProvider = new ImageProvider(),
endsWith = function ( a, b ) { return a.indexOf( b ) === a.length - b.length; };
imageProvider.imagePreloadingSupported = function () { return true; };
imageProvider.imagePreloadingSupported = () => true;
imageProvider.performance = {
record: function () { return $.Deferred().resolve(); }
};
@ -109,7 +111,7 @@ const { ImageProvider } = require( 'mmv' );
imageProvider = new ImageProvider(),
done = assert.async();
imageProvider.imagePreloadingSupported = function () { return true; };
imageProvider.imagePreloadingSupported = () => true;
imageProvider.performance = {
record: function () { return $.Deferred().resolve(); }
};
@ -124,7 +126,7 @@ const { ImageProvider } = require( 'mmv' );
var imageProvider = new ImageProvider( 'foo' ),
done = assert.async();
imageProvider.imagePreloadingSupported = function () { return false; };
imageProvider.imagePreloadingSupported = () => false;
imageProvider.rawGet = function ( url ) {
assert.strictEqual( url, 'http://www.wikipedia.org/?foo', 'Extra parameter added' );

View file

@ -78,7 +78,7 @@ const { MetadataPanelScroller } = require( 'mmv' );
localStorage = getUnsupportedLocalStorage(),
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
this.sandbox.stub( $.fn, 'scrollTop', function () { return 10; } );
this.sandbox.stub( $.fn, 'scrollTop', () => 10 );
scroller.scroll();
@ -94,7 +94,7 @@ const { MetadataPanelScroller } = require( 'mmv' );
} ),
scroller = new MetadataPanelScroller( $qf, $( '<div>' ).appendTo( $qf ), localStorage );
this.sandbox.stub( $.fn, 'scrollTop', function () { return 10; } );
this.sandbox.stub( $.fn, 'scrollTop', () => 10 );
scroller.attach();

View file

@ -64,14 +64,14 @@ const { ReuseDialog, Repo } = require( 'mmv' );
reuseDialog.initTabs();
// Share pane is selected
reuseDialog.handleTabSelection( { getData: function () { return 'share'; } } );
reuseDialog.handleTabSelection( { getData: () => 'share' } );
assert.strictEqual( reuseDialog.tabs.share.$pane.hasClass( 'active' ), true, 'Share tab shown.' );
assert.strictEqual( reuseDialog.tabs.embed.$pane.hasClass( 'active' ), false, 'Embed tab hidden.' );
assert.strictEqual( reuseDialog.config.setInLocalStorage.calledWith( 'mmv-lastUsedTab', 'share' ), true,
'Tab state saved in local storage.' );
// Embed pane is selected
reuseDialog.handleTabSelection( { getData: function () { return 'embed'; } } );
reuseDialog.handleTabSelection( { getData: () => 'embed' } );
assert.strictEqual( reuseDialog.tabs.share.$pane.hasClass( 'active' ), false, 'Share tab hidden.' );
assert.strictEqual( reuseDialog.tabs.embed.$pane.hasClass( 'active' ), true, 'Embed tab shown.' );
} );
@ -152,18 +152,18 @@ const { ReuseDialog, Repo } = require( 'mmv' );
function assertDialogDoesNotCatchClicks() {
var event;
reuseDialog.closeDialog = function () { assert.true( false, 'Dialog is not affected by click' ); };
reuseDialog.closeDialog = () => assert.true( false, 'Dialog is not affected by click' );
event = clickOutsideDialog();
assert.strictEqual( event.isDefaultPrevented(), false, 'Dialog does not affect click' );
assert.strictEqual( event.isPropagationStopped(), false, 'Dialog does not affect click propagation' );
}
function assertDialogCatchesOutsideClicksOnly() {
var event;
reuseDialog.closeDialog = function () { assert.true( false, 'Dialog is not affected by inside click' ); };
reuseDialog.closeDialog = () => assert.true( false, 'Dialog is not affected by inside click' );
event = clickInsideDialog();
assert.strictEqual( event.isDefaultPrevented(), false, 'Dialog does not affect inside click' );
assert.strictEqual( event.isPropagationStopped(), false, 'Dialog does not affect inside click propagation' );
reuseDialog.closeDialog = function () { assert.true( true, 'Dialog is closed by outside click' ); };
reuseDialog.closeDialog = () => assert.true( true, 'Dialog is closed by outside click' );
event = clickOutsideDialog();
assert.strictEqual( event.isDefaultPrevented(), true, 'Dialog catches outside click' );
assert.strictEqual( event.isPropagationStopped(), true, 'Dialog stops outside click propagation' );

View file

@ -66,7 +66,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
height = 20;
embed.embedSwitch.findSelectedItem = function () {
return { getData: function () { return 'html'; } };
return { getData: () => 'html' };
};
embed.updateEmbedHtml = function ( thumb, w, h ) {
assert.strictEqual( thumb.url, undefined, 'Empty thumbnail passed.' );
@ -89,7 +89,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
height = 20;
embed.embedSwitch.findSelectedItem = function () {
return { getData: function () { return 'wikitext'; } };
return { getData: () => 'wikitext' };
};
embed.updateEmbedHtml = function () {
assert.true( false, 'Dealing with wikitext menu, this should not have been called.' );
@ -365,7 +365,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
};
// HTML selected
embed.handleTypeSwitch( { getData: function () { return 'html'; } } );
embed.handleTypeSwitch( { getData: () => 'html' } );
assert.strictEqual( embed.isSizeMenuDefaultReset, true, 'Reset flag updated correctly.' );
assert.strictEqual( embed.embedSizeSwitchWikitext.getMenu().isVisible(), false, 'Wikitext size menu should be hidden.' );
@ -375,7 +375,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
};
// Wikitext selected, we are done resetting defaults
embed.handleTypeSwitch( { getData: function () { return 'wikitext'; } } );
embed.handleTypeSwitch( { getData: () => 'wikitext' } );
assert.strictEqual( embed.isSizeMenuDefaultReset, true, 'Reset flag updated correctly.' );
assert.strictEqual( embed.embedSizeSwitchHtml.getMenu().isVisible(), false, 'HTML size menu should be hidden.' );
@ -385,7 +385,7 @@ const { Embed } = require( 'mmv.ui.reuse.shareembed' );
var embed,
oldUserIsAnon = mw.user.isAnon;
mw.user.isAnon = function () { return true; };
mw.user.isAnon = () => true;
embed = new Embed( $qf );

View file

@ -30,14 +30,14 @@ const { StripeButtons } = require( 'mmv' );
oldMwUserIsAnon = mw.user.isAnon;
// first pretend we are anonymous
mw.user.isAnon = function () { return true; };
mw.user.isAnon = () => true;
buttons = createStripeButtons();
assert.true( buttons instanceof StripeButtons, 'UI element is created.' );
assert.strictEqual( buttons.buttons.$descriptionPage.length, 1, 'File page button created for anon.' );
// now pretend we are logged in
mw.user.isAnon = function () { return false; };
mw.user.isAnon = () => false;
buttons = createStripeButtons();
assert.strictEqual( buttons.buttons.$descriptionPage.length, 1, 'File page button created for logged in.' );
@ -70,13 +70,13 @@ const { StripeButtons } = require( 'mmv' );
assert.strictEqual( $button.hasClass( 'mw-mmv-repo-button-commons' ), false, 'Button does not have commons class non-Commons files' );
assert.strictEqual( $button.find( 'a' ).addBack().filter( 'a' ).attr( 'href' ), descriptionUrl, 'Description page link is correct' );
repoInfo.isCommons = function () { return true; };
repoInfo.isCommons = () => true;
buttons.setDescriptionPageButton( imageInfo, repoInfo );
assert.strictEqual( $button.hasClass( 'mw-mmv-repo-button-commons' ), true, 'Button commons class for Commons files' );
imageInfo.pageID = 1;
imageInfo.title = { getUrl: function () { return descriptionUrl2; } };
imageInfo.title = { getUrl: () => descriptionUrl2 };
repoInfo.isLocal = false;
buttons.setDescriptionPageButton( imageInfo, repoInfo );