diff --git a/resources/.eslintrc.json b/resources/.eslintrc.json index 4081351f8..f04ba0765 100644 --- a/resources/.eslintrc.json +++ b/resources/.eslintrc.json @@ -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" }, diff --git a/resources/mmv.ui.reuse.shareembed/mmv.ui.reuse.embed.js b/resources/mmv.ui.reuse.shareembed/mmv.ui.reuse.embed.js index 9bcc9f1a3..d10c9405f 100644 --- a/resources/mmv.ui.reuse.shareembed/mmv.ui.reuse.embed.js +++ b/resources/mmv.ui.reuse.shareembed/mmv.ui.reuse.embed.js @@ -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 ); diff --git a/resources/mmv/mmv.ThumbnailWidthCalculator.js b/resources/mmv/mmv.ThumbnailWidthCalculator.js index 0f0107ab8..bcab5916b 100644 --- a/resources/mmv/mmv.ThumbnailWidthCalculator.js +++ b/resources/mmv/mmv.ThumbnailWidthCalculator.js @@ -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. diff --git a/resources/mmv/mmv.lightboxinterface.js b/resources/mmv/mmv.lightboxinterface.js index 5fab5c2a1..0d684998e 100644 --- a/resources/mmv/mmv.lightboxinterface.js +++ b/resources/mmv/mmv.lightboxinterface.js @@ -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' ], diff --git a/tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js b/tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js index c3288b471..746e5093c 100644 --- a/tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js +++ b/tests/qunit/mmv/logging/mmv.logging.ViewLogger.test.js @@ -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 () { diff --git a/tests/qunit/mmv/mmv.lightboxinterface.test.js b/tests/qunit/mmv/mmv.lightboxinterface.test.js index 6c865783a..ccbca9eaf 100644 --- a/tests/qunit/mmv/mmv.lightboxinterface.test.js +++ b/tests/qunit/mmv/mmv.lightboxinterface.test.js @@ -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() { diff --git a/tests/qunit/mmv/mmv.test.js b/tests/qunit/mmv/mmv.test.js index 758b1870f..369152634 100644 --- a/tests/qunit/mmv/mmv.test.js +++ b/tests/qunit/mmv/mmv.test.js @@ -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', diff --git a/tests/qunit/mmv/model/mmv.model.TaskQueue.test.js b/tests/qunit/mmv/model/mmv.model.TaskQueue.test.js index 4cbc91639..1e92b26c4 100644 --- a/tests/qunit/mmv/model/mmv.model.TaskQueue.test.js +++ b/tests/qunit/mmv/model/mmv.model.TaskQueue.test.js @@ -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(); diff --git a/tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js b/tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js index 2454a61b4..cb852f4a6 100644 --- a/tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js +++ b/tests/qunit/mmv/provider/mmv.provider.GuessedThumbnailInfo.test.js @@ -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' ); diff --git a/tests/qunit/mmv/provider/mmv.provider.Image.test.js b/tests/qunit/mmv/provider/mmv.provider.Image.test.js index 63875746c..fe3120807 100644 --- a/tests/qunit/mmv/provider/mmv.provider.Image.test.js +++ b/tests/qunit/mmv/provider/mmv.provider.Image.test.js @@ -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' ); diff --git a/tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js b/tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js index 8d9992d13..bd74fa1d4 100644 --- a/tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.metadataPanelScroller.test.js @@ -78,7 +78,7 @@ const { MetadataPanelScroller } = require( 'mmv' ); localStorage = getUnsupportedLocalStorage(), scroller = new MetadataPanelScroller( $qf, $( '