ESLint: Update to ES6 and autofix

Change-Id: I38afd9a3340ca9a85e7204978cae00b48513f5ca
This commit is contained in:
Ed Sanders 2024-11-15 10:55:47 +00:00
parent f9c14b89a3
commit 5fc902bd9c
10 changed files with 60 additions and 72 deletions

View file

@ -1,7 +1,7 @@
{
"root": true,
"extends": [
"wikimedia/client-es5",
"wikimedia/client",
"wikimedia/jquery",
"wikimedia/mediawiki"
],
@ -11,6 +11,6 @@
"rules": {
"max-len": "off",
"no-jquery/no-global-selector": "off",
"es-x/no-object-assign": "warn"
"no-var": "off"
}
}

View file

@ -65,7 +65,7 @@ function logAbort( switchingToVE, unmodified ) {
} );
}
$( function () {
$( () => {
var $textarea = $( '#wpTextbox1' ),
$editingSessionIdInput = $( '#editingStatsId' ),
origText = $textarea.val();
@ -87,12 +87,12 @@ $( function () {
action: 'ready',
timing: readyTime - window.performance.timing.navigationStart
} );
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () {
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', () => {
logEditEvent( {
action: 'loaded',
timing: Date.now() - window.performance.timing.navigationStart
} );
} ).one( 'input', function () {
} ).one( 'input', () => {
logEditEvent( {
action: 'firstChange',
timing: Date.now() - readyTime
@ -101,13 +101,13 @@ $( function () {
}
var $form = $textarea.closest( 'form' );
if ( mw.user.options.get( 'uselivepreview' ) ) {
$form.find( '#wpPreview' ).on( 'click', function () {
$form.find( '#wpPreview' ).on( 'click', () => {
logEditFeature( 'preview', 'preview-live' );
} );
}
var submitting;
$form.on( 'submit', function () {
$form.on( 'submit', () => {
submitting = true;
} );
var onUnloadFallback = window.onunload;
@ -140,7 +140,7 @@ $( function () {
return fallbackResult;
};
$textarea.on( 'wikiEditor-switching-visualeditor', function () {
$textarea.on( 'wikiEditor-switching-visualeditor', () => {
var unmodified = mw.config.get( 'wgAction' ) !== 'submit' && origText === $textarea.val();
// A non-navigation switch to VE has occurred. As such, avoid eventually
// double-logging an abort when VE is done.
@ -150,28 +150,28 @@ $( function () {
} );
// Add logging for Realtime Preview.
mw.hook( 'ext.WikiEditor.realtimepreview.enable' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.enable' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-on' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.inuse' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-inuse' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.disable' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.disable' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-off' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.loaded' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.loaded' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-loaded' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.stop' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.stop' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-error-stopped' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.reloadError' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.reloadError' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-reload-error' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.reloadHover' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.reloadHover' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-reload-hover' );
} );
mw.hook( 'ext.WikiEditor.realtimepreview.reloadManual' ).add( function () {
mw.hook( 'ext.WikiEditor.realtimepreview.reloadManual' ).add( () => {
logEditFeature( 'preview', 'preview-realtime-reload-manual' );
} );
}

View file

@ -51,7 +51,7 @@ TitleInputWidget.prototype.onLookupInputBlur = function () {
*/
TitleInputWidget.prototype.selectFirstMatch = function () {
var that = this;
this.getLookupMenuItems().done( function ( items ) {
this.getLookupMenuItems().done( ( items ) => {
// The matching item is not always the first,
// because disambiguation pages are moved to the end.
for ( var i = 0; i < items.length; i++ ) {

View file

@ -372,9 +372,7 @@ module.exports = {
// Expandable help message for 'alt text' field
$( this ).find( '.wikieditor-toolbar-file-alt-help' ).text( altHelpLabel );
$( '.wikieditor-toolbar-file-alt-help' ).on( 'click', function () {
$( this ).text( function ( i, text ) {
return text === altHelpLabel ? altHelpText : altHelpLabel;
} );
$( this ).text( ( i, text ) => text === altHelpLabel ? altHelpText : altHelpLabel );
} );
// Preload modules of file upload dialog.
@ -415,9 +413,7 @@ module.exports = {
}
var options = [ fileSize, fileFormat, fileFloat ];
// Filter empty values
options = options.filter( function ( val ) {
return val.length && val !== 'default';
} );
options = options.filter( ( val ) => val.length && val !== 'default' );
if ( fileAlt.length ) {
options.push( magicWordsI18N.img_alt[ 0 ].replace( '$1', fileAlt ) );
}
@ -459,7 +455,7 @@ module.exports = {
'mediawiki.ForeignStructuredUpload.BookletLayout',
'mediawiki.Upload.Dialog',
'oojs-ui-windows'
] ).then( function () {
] ).then( () => {
var windowManager = new OO.ui.WindowManager(),
uploadDialog = new mw.Upload.Dialog( {
bookletClass: mw.ForeignStructuredUpload.BookletLayout
@ -503,9 +499,7 @@ module.exports = {
}
// Escape pipes inside links and templates,
// then split the parameters at the remaining pipes
var params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, function ( link ) {
return link.replace( /\|/g, escapedPipe );
} ).split( '|' );
var params = match[ 2 ].replace( /\[\[[^[\]]*\]\]|\{\{[^{}]\}\}/g, ( link ) => link.replace( /\|/g, escapedPipe ) ).split( '|' );
var file = mw.Title.newFromText( params[ 0 ] );
if ( !file || file.getNamespaceId() !== 6 ) {
return false;
@ -604,7 +598,7 @@ module.exports = {
$( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 );
$( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 );
$( '#wikieditor-toolbar-table-wikitable' ).on( 'click', function () {
$( '#wikieditor-toolbar-table-wikitable' ).on( 'click', () => {
// eslint-disable-next-line no-jquery/no-class-state
$( '.wikieditor-toolbar-table-preview' ).toggleClass( 'wikitable' );
} );
@ -618,11 +612,11 @@ module.exports = {
.insertAfter( $( '#wikieditor-toolbar-table-preview' ) )
.hide();
mw.loader.using( 'jquery.tablesorter', function () {
mw.loader.using( 'jquery.tablesorter', () => {
$( '#wikieditor-toolbar-table-preview2' ).tablesorter();
} );
$( '#wikieditor-toolbar-table-sortable' ).on( 'click', function () {
$( '#wikieditor-toolbar-table-sortable' ).on( 'click', () => {
// Swap the currently shown one clone with the other one
$( '#wikieditor-toolbar-table-preview' )
.hide()
@ -633,7 +627,7 @@ module.exports = {
$( '#wikieditor-toolbar-table-preview3' ).attr( 'id', 'wikieditor-toolbar-table-preview2' );
} );
$( '#wikieditor-toolbar-table-dimensions-header' ).on( 'click', function () {
$( '#wikieditor-toolbar-table-dimensions-header' ).on( 'click', () => {
// Instead of show/hiding, switch the HTML around
// We do this because the sortable tables script styles the first row,
// visible or not
@ -643,7 +637,7 @@ module.exports = {
$( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML );
var $sortable = $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' )
.filter( '.sortable' );
mw.loader.using( 'jquery.tablesorter', function () {
mw.loader.using( 'jquery.tablesorter', () => {
$sortable.tablesorter();
} );
} );
@ -937,7 +931,7 @@ module.exports = {
var $dialog = $( this ).closest( '.ui-dialog' );
that = this;
$( this ).data( 'context' ).$textarea
.on( 'keypress.srdialog', function ( e ) {
.on( 'keypress.srdialog', ( e ) => {
if ( e.which === 13 ) {
// Enter
triggerButtonClick( $dialog );

View file

@ -121,7 +121,7 @@ var dialogsModule = {
.each( module.init )
.dialog( configuration );
$dialogDiv.on( 'dialogclose', function () {
$dialogDiv.on( 'dialogclose', () => {
context.fn.restoreSelection();
} );

View file

@ -423,10 +423,8 @@ $.fn.wikiEditor = function () {
.addClass( context.view === opts.name ? 'current' : null )
.append( $( '<a>' )
.attr( 'tabindex', 0 )
.on( 'mousedown', function () {
// No dragging!
return false;
} )
// No dragging!
.on( 'mousedown', () => false )
.on( 'click keydown', function ( event ) {
if (
event.type === 'click' ||
@ -539,7 +537,7 @@ $.fn.wikiEditor = function () {
// Setup the initial view
context.view = 'wikitext';
// Trigger the "resize" event anytime the window is resized
$( window ).on( 'resize', function ( event ) {
$( window ).on( 'resize', ( event ) => {
context.fn.trigger( 'resize', event );
} );
}

View file

@ -111,7 +111,7 @@ var toolbarModule = {
// Character
$characters.append(
$( toolbarModule.fn.buildCharacter( data.characters[ i ], actions ) )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -315,7 +315,7 @@ var toolbarModule = {
$button.css( 'background-image', 'url(' + icon + ')' );
}
}
$button.data( 'setActive', function ( active ) {
$button.data( 'setActive', ( active ) => {
$button.toggleClass( 'tool-active', active );
// OOUI button
@ -324,7 +324,7 @@ var toolbarModule = {
// Use progressive icon in WMUI theme
if ( OO.ui.WikimediaUITheme && OO.ui.theme instanceof OO.ui.WikimediaUITheme ) {
// Wait for updateElementClasses to run
setTimeout( function () {
setTimeout( () => {
$button.data( 'ooui' ).$icon.toggleClass( 'oo-ui-image-progressive', active );
} );
}
@ -334,19 +334,19 @@ var toolbarModule = {
$button
.data( 'action', tool.action )
.data( 'context', context )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
} );
if ( $button.data( 'ooui' ) ) {
$button.data( 'ooui' ).on( 'click', function () {
$button.data( 'ooui' ).on( 'click', () => {
toolbarModule.fn.doAction(
context, tool.action
);
} );
} else {
$button.on( 'click keydown', function ( e ) {
$button.on( 'click keydown', ( e ) => {
if (
e.type === 'click' ||
e.type === 'keydown' && e.key === 'Enter'
@ -376,7 +376,7 @@ var toolbarModule = {
$( '<a>' )
.data( 'action', tool.list[ option ].action )
.data( 'context', context )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -406,7 +406,7 @@ var toolbarModule = {
.text( label )
.data( 'options', $options )
.attr( { role: 'button', tabindex: 0, 'aria-expanded': false, 'aria-controls': menuId, 'aria-haspopup': 'menu' } )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -454,7 +454,7 @@ var toolbarModule = {
role: 'option'
} )
.data( 'context', context )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -482,7 +482,7 @@ var toolbarModule = {
rel: id
} );
if ( deferLoad ) {
$page.one( 'loadPage', function () {
$page.one( 'loadPage', () => {
toolbarModule.fn.reallyBuildPage( context, id, page, $page );
} );
} else {
@ -530,7 +530,7 @@ var toolbarModule = {
.html( html )
.children()
.attr( 'role', 'option' )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -627,7 +627,7 @@ var toolbarModule = {
.on( 'mouseup', function () {
$( this ).trigger( 'blur' );
} )
.on( 'mousedown', function ( e ) {
.on( 'mousedown', ( e ) => {
// No dragging!
e.preventDefault();
return false;
@ -642,7 +642,7 @@ var toolbarModule = {
// We have to set aria-pressed over here, as NVDA wont recognize it
// if we do it in the below .each as it seems
$( this ).attr( 'aria-pressed', 'true' );
$( '.tab > a' ).each( function ( i, elem ) {
$( '.tab > a' ).each( ( i, elem ) => {
if ( elem !== e.target ) {
$( elem ).attr( 'aria-pressed', 'false' );
}
@ -723,7 +723,7 @@ var toolbarModule = {
tabindex: '0',
role: 'listbox'
} )
.on( 'keydown', function ( event ) {
.on( 'keydown', ( event ) => {
var $selected = $pages.children().filter( function () {
return $( this ).css( 'display' ) !== 'none';
} );
@ -735,7 +735,7 @@ var toolbarModule = {
tabindex: '0',
role: 'listbox'
} )
.on( 'keydown', function ( event ) {
.on( 'keydown', ( event ) => {
$.wikiEditor.modules.toolbar.fn.handleKeyDown( $index, event, $index );
} );
if ( 'pages' in section ) {
@ -784,7 +784,7 @@ var toolbarModule = {
$tabs.append( toolbarModule.fn.buildTab( context, section, config[ section ] ) );
}
}
setTimeout( function () {
setTimeout( () => {
context.$textarea.trigger( 'wikiEditor-toolbar-doneInitialSections' );
// Use hook for attaching new toolbar tools to avoid race conditions
mw.hook( 'wikiEditor.toolbarReady' ).fire( context.$textarea );
@ -797,7 +797,7 @@ var toolbarModule = {
var platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
var otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
context.$textarea.on( 'keydown', function ( e ) {
context.$textarea.on( 'keydown', ( e ) => {
// Check if the primary modifier key is pressed and that others aren't
var target = e[ platformModifier ] && !e[ otherModifier ] && !e.altKey && !e.shiftKey &&
toolbarModule.fn.ctrlShortcuts[ e.which ];

View file

@ -228,12 +228,12 @@ RealtimePreview.prototype.toggle = function ( saveUserPref ) {
*/
RealtimePreview.prototype.getEventHandler = function () {
return mw.util.debounce(
function () {
() => {
// Only do preview if we're not in manual mode (as set in this.checkResponseTimes()).
if ( !this.inManualMode ) {
this.doRealtimePreview();
}
}.bind( this ),
},
this.configData.realtimeDebounce
);
};
@ -301,9 +301,7 @@ RealtimePreview.prototype.checkResponseTimes = function ( time ) {
return;
}
var totalResponseTime = this.responseTimes.reduce( function ( a, b ) {
return a + b;
}, 0 );
var totalResponseTime = this.responseTimes.reduce( ( a, b ) => a + b, 0 );
if ( ( totalResponseTime / this.responseTimes.length ) > this.configData.realtimeDisableDuration ) {
this.inManualMode = true;
@ -344,9 +342,7 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
var loadingSelectors = this.pagePreview.getLoadingSelectors()
// config.$previewNode below is a clone of #wikiPreview with a different selector!
// config.$diffNode defaults to #wikiDiff but is disabled below and never updated.
.filter( function ( selector ) {
return selector.indexOf( '#wiki' ) !== 0;
} );
.filter( ( selector ) => selector.indexOf( '#wiki' ) !== 0 );
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-preview' );
loadingSelectors.push( '.ext-WikiEditor-ManualWidget' );
loadingSelectors.push( '.ext-WikiEditor-realtimepreview-ErrorLayout' );
@ -359,12 +355,12 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
loadingSelectors: loadingSelectors,
// Don't hide the diff view, if visible.
$diffNode: null
} ).done( function () {
} ).done( () => {
this.errorLayout.toggle( false );
}.bind( this ) ).fail( function ( code, result ) {
} ).fail( ( code, result ) => {
this.showError( ( new mw.Api() ).getErrorMessage( result ) );
mw.log.error( 'WikiEditor realtime preview error', result );
}.bind( this ) ).always( function () {
} ).always( () => {
this.$loadingBar.hide();
this.reloadButton.setDisabled( false );
if ( !this.errorLayout.isVisible() ) {
@ -382,7 +378,7 @@ RealtimePreview.prototype.doRealtimePreview = function ( forceUpdate ) {
this.doRealtimePreview();
}
mw.hook( 'ext.WikiEditor.realtimepreview.loaded' ).fire( this );
}.bind( this ) );
} );
};
module.exports = RealtimePreview;

View file

@ -21,7 +21,7 @@ function ResizingDragBar( config ) {
var resizingDragBar = this;
// Determine the horizontal direction to move (flexbox automatically reverses but the offset direction doesn't).
var rtlFactor = config.isEW && OO.ui.Element.static.getDir( document ) === 'rtl' ? -1 : 1;
this.$element.on( 'mousedown', function ( eventMousedown ) {
this.$element.on( 'mousedown', ( eventMousedown ) => {
if ( eventMousedown.button !== ResizingDragBar.static.MAIN_MOUSE_BUTTON ) {
// If not the main mouse (e.g. left) button, ignore.
return;
@ -33,7 +33,7 @@ function ResizingDragBar( config ) {
var widthOrHeight = config.isEW ? 'width' : 'height';
var lastOffset = eventMousedown[ xOrY ];
// Handle the actual dragging.
$( document ).on( 'mousemove.' + classNameDir, function ( eventMousemove ) {
$( document ).on( 'mousemove.' + classNameDir, ( eventMousemove ) => {
// Initial width or height of the pane.
var startSize = resizingDragBar.getResizedPane()[ widthOrHeight ]();
// Current position of the mouse (relative to page, not viewport).
@ -52,7 +52,7 @@ function ResizingDragBar( config ) {
// Add a UI affordance within the handle area (CSS gives it its appearance).
this.$element.append( $( '<span>' ) );
// Remove the resize event handler when the mouse is released.
$( document ).on( 'mouseup', function () {
$( document ).on( 'mouseup', () => {
$( document ).off( 'mousemove.' + classNameDir );
$( document ).off( 'selectstart.' + classNameDir, false );
} );

View file

@ -1,4 +1,4 @@
QUnit.module( 'ext.wikiEditor.toolbar', function ( hooks ) {
QUnit.module( 'ext.wikiEditor.toolbar', ( hooks ) => {
hooks.beforeEach( function () {
var $target = $( '<textarea>' )
.attr( 'id', 'wpTextBox1' )