ESLint: Enforce prefer-const

Change-Id: I5985d1b532988bb3b71ff1aa24eae57ac2e1b9c5
This commit is contained in:
Ed Sanders 2024-05-24 13:43:07 +01:00
parent 44303de9cf
commit ea5639b20b
8 changed files with 31 additions and 36 deletions

View file

@ -368,10 +368,6 @@ class CommentModifier {
* @param DocumentFragment|null $fragment Containing document fragment if list has no parent
*/
public static function unwrapList( Node $list, ?DocumentFragment $fragment = null ): void {
$doc = $list->ownerDocument;
$container = $fragment ?: $list->parentNode;
$referenceNode = $list;
if ( !(
$list instanceof Element && (
strtolower( $list->tagName ) === 'dl' ||
@ -388,6 +384,9 @@ class CommentModifier {
return;
}
$doc = $list->ownerDocument;
$container = $fragment ?: $list->parentNode;
$referenceNode = $list;
while ( $list->firstChild ) {
if ( $list->firstChild instanceof Element ) {
// Move <dd> contents to <p>

View file

@ -11,7 +11,6 @@
},
"rules": {
"no-implicit-globals": "off",
"prefer-const": "off",
"max-len": "off",
"prefer-arrow-callback": "error",
"implicit-arrow-linebreak": "error",

View file

@ -671,10 +671,10 @@ CommentController.prototype.getUnsupportedNodeSelectors = function () {
* @return {jQuery.Promise} Promise which resolves when switch is complete
*/
CommentController.prototype.switchToVisual = function () {
let oldWidget = this.replyWidget,
const oldWidget = this.replyWidget,
oldShowAdvanced = oldWidget.showAdvanced,
oldEditSummary = oldWidget.getEditSummary(),
wikitext = oldWidget.getValue();
oldEditSummary = oldWidget.getEditSummary();
let wikitext = oldWidget.getValue();
// Replace wikitext signatures with a special marker recognized by DtDmMWSignatureNode
// to render them as signature nodes in visual mode.

View file

@ -516,11 +516,10 @@ function acceptOnlyNodesAllowingComments( node ) {
* - {Object} range Range-like object covering the timestamp
*/
Parser.prototype.findTimestamp = function ( node, timestampRegexps ) {
let matchData, i,
nodeText = '',
offset = 0,
// Searched nodes (reverse order)
nodes = [];
let nodeText = '';
let offset = 0;
// Searched nodes (reverse order)
const nodes = [];
while ( node ) {
nodeText = node.nodeValue + nodeText;
@ -554,12 +553,12 @@ Parser.prototype.findTimestamp = function ( node, timestampRegexps ) {
}
}
for ( i = 0; i < timestampRegexps.length; i++ ) {
for ( let i = 0; i < timestampRegexps.length; i++ ) {
// Technically, there could be multiple matches in a single text node. However, the ultimate
// point of this is to find the signatures which precede the timestamps, and any later
// timestamps in the text node can't be directly preceded by a signature (as we require them to
// have links), so we only concern ourselves with the first match.
matchData = nodeText.match( timestampRegexps[ i ] );
const matchData = nodeText.match( timestampRegexps[ i ] );
if ( matchData ) {
const timestampLength = matchData[ 0 ].length;
// Bytes at the end of the last node which aren't part of the match

View file

@ -251,9 +251,9 @@ function getCheckboxesPromise( pageName, oldId ) {
* @return {string[]}
*/
function getReplyWidgetModules() {
let veConf = mw.config.get( 'wgVisualEditorConfig' ),
modules = [ 'ext.discussionTools.ReplyWidget' ]
.concat( veConf.pluginModules.filter( mw.loader.getState ) );
const veConf = mw.config.get( 'wgVisualEditorConfig' );
let modules = [ 'ext.discussionTools.ReplyWidget' ]
.concat( veConf.pluginModules.filter( mw.loader.getState ) );
if ( OO.ui.isMobile() ) {
modules = [
@ -281,9 +281,9 @@ function getReplyWidgetModules() {
function init( $container, state ) {
let
activeCommentId = null,
activeController = null,
// Loads later to avoid circular dependency
CommentController = require( './CommentController.js' ),
activeController = null;
// Loads later to avoid circular dependency
const CommentController = require( './CommentController.js' ),
NewTopicController = require( './NewTopicController.js' );
// We may be re-initializing after posting a new comment, so clear the cache, because

View file

@ -1,5 +1,5 @@
const controller = require( 'ext.discussionTools.init' ).controller;
let sequence;
let sequence = null;
function sortAuthors( a, b ) {
return a.username < b.username ? -1 : ( a.username === b.username ? 0 : 1 );
@ -67,8 +67,8 @@ MWUsernameCompletionAction.static.methods.push( 'insertAndOpen' );
/* Methods */
MWUsernameCompletionAction.prototype.insertAndOpen = function () {
let inserted = false,
surfaceModel = this.surface.getModel(),
let inserted = false;
const surfaceModel = this.surface.getModel(),
fragment = surfaceModel.getFragment();
// This is opening a window in a slightly weird way, so the normal logging

View file

@ -310,10 +310,6 @@ function removeAddedListItem( node ) {
* @param {DocumentFragment|null} fragment Containing document fragment if list has no parent
*/
function unwrapList( list, fragment ) {
let doc = list.ownerDocument,
container = fragment || list.parentNode,
referenceNode = list;
if ( !(
list.nodeType === Node.ELEMENT_NODE && (
list.tagName.toLowerCase() === 'dl' ||
@ -330,7 +326,9 @@ function unwrapList( list, fragment ) {
return;
}
let insertBefore;
const doc = list.ownerDocument;
const container = fragment || list.parentNode;
let referenceNode = list;
while ( list.firstChild ) {
if ( list.firstChild.nodeType === Node.ELEMENT_NODE ) {
// Move <dd> contents to <p>
@ -340,11 +338,11 @@ function unwrapList( list, fragment ) {
// and start a new paragraph after
if ( utils.isBlockElement( list.firstChild.firstChild ) ) {
if ( p.firstChild ) {
insertBefore = referenceNode.nextSibling;
const insertBefore2 = referenceNode.nextSibling;
referenceNode = p;
container.insertBefore( p, insertBefore );
container.insertBefore( p, insertBefore2 );
}
insertBefore = referenceNode.nextSibling;
const insertBefore = referenceNode.nextSibling;
referenceNode = list.firstChild.firstChild;
container.insertBefore( list.firstChild.firstChild, insertBefore );
p = doc.createElement( 'p' );
@ -353,14 +351,14 @@ function unwrapList( list, fragment ) {
}
}
if ( p.firstChild ) {
insertBefore = referenceNode.nextSibling;
const insertBefore = referenceNode.nextSibling;
referenceNode = p;
container.insertBefore( p, insertBefore );
}
list.removeChild( list.firstChild );
} else {
// Text node / comment node, probably empty
insertBefore = referenceNode.nextSibling;
const insertBefore = referenceNode.nextSibling;
referenceNode = list.firstChild;
container.insertBefore( list.firstChild, insertBefore );
}

View file

@ -321,7 +321,7 @@ function maybeShowFirstTimeAutoTopicSubPopup() {
mw.user.options.set( 'discussiontools-seenautotopicsubpopup', '1' );
api.saveOption( 'discussiontools-seenautotopicsubpopup', '1' );
let $popupContent, popup;
let popup = null;
function close() {
popup.$element.removeClass( 'ext-discussiontools-autotopicsubpopup-fadein' );
@ -330,7 +330,7 @@ function maybeShowFirstTimeAutoTopicSubPopup() {
}, 1000 );
}
$popupContent = $( '<div>' )
const $popupContent = $( '<div>' )
.append(
$( '<strong>' )
.addClass( 'ext-discussiontools-autotopicsubpopup-title' )