ESLint: Enforce prefer-const

Change-Id: I7f45137a47dddcd2fc70201f28680edce907b522
This commit is contained in:
Ed Sanders 2024-06-14 12:57:43 +01:00
parent 1b101f09ee
commit f0fb93d3e1
6 changed files with 21 additions and 27 deletions

View file

@ -12,8 +12,7 @@
"CodeMirror": "readonly"
},
"rules": {
"max-len": "off",
"prefer-const": "warn"
"max-len": "off"
},
"overrides": [
{

View file

@ -51,8 +51,8 @@
nestedBracketsToSkip = 0,
lineNo = where.line,
line = cm.getLine( lineNo ),
pos = where.ch,
maxScanLen = ( config && config.maxScanLineLength ) || 10000,
pos = where.ch;
const maxScanLen = ( config && config.maxScanLineLength ) || 10000,
maxScanLines = ( config && config.maxScanLines ) || 1000;
// Check the limit for the current line

View file

@ -148,8 +148,7 @@ function init() {
const config = mw.config.get( 'extCodeMirrorConfig' );
mw.loader.using( codeMirrorCoreModules.concat( config.pluginModules ), () => {
let $codeMirror, cmOptions,
selectionStart = $textbox1.prop( 'selectionStart' ),
const selectionStart = $textbox1.prop( 'selectionStart' ),
selectionEnd = $textbox1.prop( 'selectionEnd' ),
scrollTop = $textbox1.scrollTop(),
hasFocus = $textbox1.is( ':focus' );
@ -164,7 +163,7 @@ function init() {
CodeMirror.keyMap.pcDefault[ 'Alt-Left' ] = false;
CodeMirror.keyMap.pcDefault[ 'Alt-Right' ] = false;
cmOptions = {
const cmOptions = {
mwConfig: config,
// styleActiveLine: true, // disabled since Bug: T162204, maybe should be optional
lineWrapping: true,
@ -190,7 +189,7 @@ function init() {
};
codeMirror = CodeMirror.fromTextArea( $textbox1[ 0 ], cmOptions );
$codeMirror = $( codeMirror.getWrapperElement() );
const $codeMirror = $( codeMirror.getWrapperElement() );
codeMirror.on( 'focus', () => {
$textbox1.triggerHandler( 'focus' );
@ -305,8 +304,7 @@ function init() {
* Adds the CodeMirror button to WikiEditor
*/
function addCodeMirrorToWikiEditor() {
let $codeMirrorButton,
context = $textbox1.data( 'wikiEditor-context' ),
const context = $textbox1.data( 'wikiEditor-context' ),
toolbar = context && context.modules && context.modules.toolbar;
// Guard against something having removed WikiEditor (T271457)
@ -338,7 +336,7 @@ function init() {
}
);
$codeMirrorButton = toolbar.$toolbar.find( '.tool[rel=CodeMirror]' );
const $codeMirrorButton = toolbar.$toolbar.find( '.tool[rel=CodeMirror]' );
$codeMirrorButton
.attr( 'id', 'mw-editbutton-codemirror' );

View file

@ -6,14 +6,12 @@ require( './ext.CodeMirror.data.js' );
* @param {Object} data
*/
function logUsage( data ) {
let event, editCountBucket;
/* eslint-disable camelcase */
event = Object.assign( {
const event = Object.assign( {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
}, data );
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
const editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
if ( editCountBucket !== null ) {
event.user_edit_count_bucket = editCountBucket;
}

View file

@ -21,7 +21,7 @@
CodeMirror.defineMode( 'mediawiki', ( config /* , parserConfig */ ) => {
let mwConfig = config.mwConfig,
const mwConfig = config.mwConfig,
urlProtocols = new RegExp( '^(?:' + mwConfig.urlProtocols + ')', 'i' ),
permittedHtmlTags = { b: true, bdi: true, del: true, i: true, ins: true,
@ -34,8 +34,8 @@
kbd: true, samp: true, data: true, time: true, mark: true, br: true,
wbr: true, hr: true, li: true, dt: true, dd: true, td: true, th: true,
tr: true, noinclude: true, includeonly: true, onlyinclude: true },
voidHtmlTags = { br: true, hr: true, wbr: true },
isBold, isItalic, firstsingleletterword, firstmultiletterword, firstspace, mBold, mItalic, mTokens = [],
voidHtmlTags = { br: true, hr: true, wbr: true };
let isBold, isItalic, firstsingleletterword, firstmultiletterword, firstspace, mBold, mItalic, mTokens = [],
mStyle;
function makeStyle( style, state, endGround ) {
@ -464,9 +464,9 @@
function eatExtTagArea( name ) {
return function ( stream, state ) {
let origString = false,
from = stream.pos,
to,
let to,
origString = false;
const from = stream.pos,
pattern = new RegExp( '</' + name + '\\s*>', 'i' ),
m = pattern.exec( from ? stream.string.slice( from ) : stream.string );
@ -634,8 +634,8 @@
function eatWikiText( style, mnemonicStyle ) {
return function ( stream, state ) {
let ch, tmp, mt, name, isCloseTag, tagname,
sol = stream.sol();
let ch, tmp, mt, name, isCloseTag, tagname;
const sol = stream.sol();
function chain( parser ) {
state.stack.push( state.tokenize );
@ -994,13 +994,12 @@
function eatNowiki( style, lineStyle ) {
return function ( stream, state, ownLine ) {
let s;
if ( ownLine && stream.sol() ) {
state.ownLine = true;
} else if ( ownLine === false && state.ownLine ) {
state.ownLine = false;
}
s = ( state.ownLine ? lineStyle : style );
const s = ( state.ownLine ? lineStyle : style );
if ( stream.match( /^[^&]+/ ) ) {
return s;
}

View file

@ -226,12 +226,12 @@ ve.ui.CodeMirrorAction.prototype.onLangChange = function () {
* @param {ve.dm.Transaction} tx
*/
ve.ui.CodeMirrorAction.prototype.onDocumentPrecommit = function ( tx ) {
let offset = 0,
replacements = [],
const replacements = [],
action = this,
store = this.surface.getModel().getDocument().getStore(),
mirror = this.surface.mirror;
let offset = 0;
tx.operations.forEach( ( op ) => {
if ( op.type === 'retain' ) {
offset += op.length;