build: Update eslint-config-wikimedia to 0.28.2 and autofix

Change-Id: I622f53bf5f56782b7a0529cdc6bb27c1315ff5a0
This commit is contained in:
Ed Sanders 2024-06-14 12:51:53 +01:00 committed by Esanders
parent 170869190c
commit 6958b99f2e
14 changed files with 454 additions and 497 deletions

View file

@ -1,3 +1,4 @@
/resources/lib/
/resources/dist/
/vendor
/docs

810
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -37,7 +37,7 @@
"@wdio/spec-reporter": "7.29.1",
"@wikimedia/mw-node-qunit": "7.2.0",
"dotenv": "8.2.0",
"eslint-config-wikimedia": "0.27.0",
"eslint-config-wikimedia": "0.28.2",
"grunt-banana-checker": "0.13.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",

View file

@ -5,12 +5,15 @@
"wikimedia/jquery",
"wikimedia/mediawiki"
],
"parserOptions": {
"sourceType": "commonjs"
},
"globals": {
"CodeMirror": "readonly"
},
"rules": {
"max-len": "off",
"no-implicit-globals": "off"
"es-x/no-object-assign": "warn"
},
"overrides": [
{
@ -22,6 +25,5 @@
"indent": [ "error", 2 ]
}
}
],
"ignorePatterns": [ "dist/" ]
]
}

View file

@ -9,7 +9,7 @@ function logUsage( data ) {
var event, editCountBucket;
/* eslint-disable camelcase */
event = $.extend( {
event = Object.assign( {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
}, data );

View file

@ -22,7 +22,7 @@
CodeMirror.defineMode( 'mediawiki', function ( config /* , parserConfig */ ) {
var mwConfig = config.mwConfig,
// eslint-disable-next-line security/detect-non-literal-regexp
urlProtocols = new RegExp( '^(?:' + mwConfig.urlProtocols + ')', 'i' ),
permittedHtmlTags = { b: true, bdi: true, del: true, i: true, ins: true,
u: true, font: true, big: true, small: true, sub: true, sup: true,
@ -420,7 +420,7 @@
function eatHtmlTagAttribute( name ) {
return function ( stream, state ) {
// eslint-disable-next-line security/detect-unsafe-regex
if ( stream.match( /^(?:"[^<">]*"|'[^<'>]*'|[^>/<{&~])+/ ) ) {
return makeLocalStyle( 'mw-htmltag-attribute', state );
}
@ -441,7 +441,7 @@
function eatExtTagAttribute( name ) {
return function ( stream, state ) {
// eslint-disable-next-line security/detect-unsafe-regex
if ( stream.match( /^(?:"[^">]*"|'[^'>]*'|[^>/<{&~])+/ ) ) {
return makeLocalStyle( 'mw-exttag-attribute mw-ext-' + name, state );
}
@ -467,7 +467,7 @@
var origString = false,
from = stream.pos,
to,
// eslint-disable-next-line security/detect-non-literal-regexp
pattern = new RegExp( '</' + name + '\\s*>', 'i' ),
m = pattern.exec( from ? stream.string.slice( from ) : stream.string );
@ -657,7 +657,7 @@
}
break;
case '=':
// eslint-disable-next-line security/detect-unsafe-regex
tmp = stream.match( /^(={0,5})(.+?(=\1\s*)(<!--(?!.*-->.*\S).*?)?)$/ );
if ( tmp ) { // Title
stream.backUp( tmp[ 2 ].length );
@ -759,7 +759,7 @@
return makeLocalStyle( 'mw-parserfunction-bracket', state );
}
// Check for parser function without '#'
// eslint-disable-next-line security/detect-unsafe-regex
name = stream.match( /^([^\s\u00a0}[\]<{'|&:]+)(:|[\s\u00a0]*)(\}\}?)?(.)?/ );
if ( name ) {
stream.backUp( name[ 0 ].length );

View file

@ -98,7 +98,7 @@ ve.ui.CodeMirrorAction.prototype.toggle = function ( enable ) {
};
if ( ve.ui.CodeMirrorAction.static.isLineNumbering() ) {
$.extend( cmOptions, {
Object.assign( cmOptions, {
// Set up a special "padding" gutter to create space between the line numbers
// and page content. The first column name is a magic constant which causes
// the built-in line number gutter to appear in the desired, leftmost position.

View file

@ -94,11 +94,9 @@ const bidiIsolationSpec = {
* @param {EditorView} view
* @return {DecorationSet}
*/
const access = ( view ) => {
return view.plugin( plugin ) ?
( view.plugin( plugin ).isolates || Decoration.none ) :
Decoration.none;
};
const access = ( view ) => view.plugin( plugin ) ?
( view.plugin( plugin ).isolates || Decoration.none ) :
Decoration.none;
// Use the lowest precedence to ensure that other decorations
// don't break up the isolating decorations.

View file

@ -35,7 +35,7 @@ class CodeMirrorModeMediaWiki {
*/
constructor( config ) {
this.config = config;
// eslint-disable-next-line security/detect-non-literal-regexp
this.urlProtocols = new RegExp( `^(?:${ this.config.urlProtocols })(?=[^\\s\u00a0{[\\]<>~).,'])`, 'i' );
this.isBold = false;
this.wasBold = false;
@ -512,7 +512,7 @@ class CodeMirrorModeMediaWiki {
eatHtmlTagAttribute( name ) {
return ( stream, state ) => {
// eslint-disable-next-line security/detect-unsafe-regex
if ( stream.match( /^(?:"[^<">]*"|'[^<'>]*'|[^>/<{&~])+/ ) ) {
return this.makeLocalStyle( modeConfig.tags.htmlTagAttribute, state );
}
@ -544,7 +544,7 @@ class CodeMirrorModeMediaWiki {
eatExtTagAttribute( name ) {
return ( stream, state ) => {
// eslint-disable-next-line security/detect-unsafe-regex
if ( stream.match( /^(?:"[^">]*"|'[^'>]*'|[^>/<{&~])+/ ) ) {
return this.makeLocalStyle( `${ modeConfig.tags.extTagAttribute } mw-ext-${ name }`, state );
}
@ -583,7 +583,7 @@ class CodeMirrorModeMediaWiki {
eatExtTagArea( name ) {
return ( stream, state ) => {
const from = stream.pos,
// eslint-disable-next-line security/detect-non-literal-regexp
pattern = new RegExp( `</${ name }\\s*>`, 'i' ),
m = pattern.exec( from ? stream.string.slice( from ) : stream.string );
let origString = false,
@ -791,7 +791,7 @@ class CodeMirrorModeMediaWiki {
}
break;
case '=':
// eslint-disable-next-line security/detect-unsafe-regex
tmp = stream.match( /^(={0,5})(.+?(=\1\s*)(<!--(?!.*-->.*\S).*?)?)$/ );
// Title
if ( tmp ) {
@ -916,7 +916,7 @@ class CodeMirrorModeMediaWiki {
);
}
// Check for parser function without '#'
// eslint-disable-next-line security/detect-unsafe-regex
name = stream.match( /^([^\s\u00a0}[\]<{'|&:]+)(:|[\s\u00a0]*)(\}\}?)?(.)?/ );
if ( name ) {
stream.backUp( name[ 0 ].length );
@ -1104,20 +1104,18 @@ class CodeMirrorModeMediaWiki {
* @return {Object}
* @private
*/
startState: () => {
return {
tokenize: this.eatWikiText( '' ),
stack: [],
inHtmlTag: [],
extName: false,
extMode: false,
extState: false,
nTemplate: 0,
nLink: 0,
nExt: 0,
nDt: 0
};
},
startState: () => ( {
tokenize: this.eatWikiText( '' ),
stack: [],
inHtmlTag: [],
extName: false,
extMode: false,
extState: false,
nTemplate: 0,
nLink: 0,
nExt: 0,
nDt: 0
} ),
/**
* Copies the given state.
@ -1126,20 +1124,18 @@ class CodeMirrorModeMediaWiki {
* @return {Object}
* @private
*/
copyState: ( state ) => {
return {
tokenize: state.tokenize,
stack: state.stack.concat( [] ),
inHtmlTag: state.inHtmlTag.concat( [] ),
extName: state.extName,
extMode: state.extMode,
extState: state.extMode !== false && state.extMode.copyState( state.extState ),
nTemplate: state.nTemplate,
nLink: state.nLink,
nExt: state.nExt,
nDt: state.nDt
};
},
copyState: ( state ) => ( {
tokenize: state.tokenize,
stack: state.stack.concat( [] ),
inHtmlTag: state.inHtmlTag.concat( [] ),
extName: state.extName,
extMode: state.extMode,
extState: state.extMode !== false && state.extMode.copyState( state.extState ),
nTemplate: state.nTemplate,
nLink: state.nLink,
nExt: state.nExt,
nDt: state.nDt
} ),
/**
* Reads one token, advancing the stream past it,

View file

@ -72,9 +72,7 @@ class EditPage extends Page {
async getHighlightedMatchingBrackets() {
await this.highlightedBrackets[ 0 ].waitForDisplayed();
const matchingTexts = await this.highlightedBrackets.map( function ( el ) {
return el.getText();
} );
const matchingTexts = await this.highlightedBrackets.map( ( el ) => el.getText() );
return matchingTexts.join( '' );
}
}

View file

@ -6,28 +6,28 @@ const assert = require( 'assert' ),
UserPreferences = require( '../userpreferences' ),
Util = require( 'wdio-mediawiki/Util' );
describe( 'CodeMirror bracket match highlighting for the wikitext 2010 editor', function () {
describe( 'CodeMirror bracket match highlighting for the wikitext 2010 editor', () => {
let title;
before( async function () {
before( async () => {
title = Util.getTestString( 'CodeMirror-fixture1-' );
await UserPreferences.loginAsOther();
await FixtureContent.createFixturePage( title );
await UserPreferences.enableWikitext2010EditorWithCodeMirror();
} );
beforeEach( async function () {
beforeEach( async () => {
await EditPage.openForEditing( title );
await EditPage.wikiEditorToolbar.waitForDisplayed();
await EditPage.clickText();
} );
it( 'highlights matching bracket', async function () {
it( 'highlights matching bracket', async () => {
await EditPage.cursorToPosition( 0 );
assert.strictEqual( await EditPage.getHighlightedMatchingBrackets(), '[]' );
} );
it( 'matches according to cursor movement', async function () {
it( 'matches according to cursor movement', async () => {
await EditPage.cursorToPosition( 3 );
assert.strictEqual( await EditPage.getHighlightedMatchingBrackets(), '{}' );
} );

View file

@ -8,29 +8,29 @@ const assert = require( 'assert' ),
Util = require( 'wdio-mediawiki/Util' );
// Disable as test is consistently failing on CI.
describe.skip( 'CodeMirror bracket match highlighting for the wikitext 2017 editor', function () {
describe.skip( 'CodeMirror bracket match highlighting for the wikitext 2017 editor', () => {
let title;
before( async function () {
before( async () => {
title = Util.getTestString( 'CodeMirror-fixture1-' );
await LoginPage.loginAdmin();
await FixtureContent.createFixturePage( title );
await UserPreferences.enableWikitext2017EditorWithCodeMirror();
} );
beforeEach( async function () {
beforeEach( async () => {
await EditPage.openForEditing( title );
await EditPage.visualEditorSave.waitForDisplayed();
assert( !( await EditPage.wikiEditorToolbar.isDisplayed() ) );
await EditPage.clickText();
} );
it( 'highlights matching bracket', async function () {
it( 'highlights matching bracket', async () => {
await EditPage.cursorToPosition( 0 );
assert.strictEqual( await EditPage.getHighlightedMatchingBrackets(), '[]' );
} );
it( 'matches according to cursor movement', async function () {
it( 'matches according to cursor movement', async () => {
await EditPage.cursorToPosition( 3 );
assert.strictEqual( await EditPage.getHighlightedMatchingBrackets(), '{}' );
} );

View file

@ -35,9 +35,7 @@ describe( 'CodeMirror textSelection for the wikitext 2010 editor', () => {
$( '.cm-editor' ).textSelection( 'setSelection', { start: 3, end: 6 } );
} );
assert.strictEqual(
await browser.execute( () => {
return $( '.cm-editor' ).textSelection( 'getSelection' );
} ),
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getSelection' ) ),
'bar'
);
} );
@ -60,14 +58,12 @@ describe( 'CodeMirror textSelection for the wikitext 2010 editor', () => {
6
);
assert.deepStrictEqual(
await browser.execute( () => {
return $( '.cm-editor' ).textSelection( 'getCaretPosition', { startAndEnd: true } );
} ),
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getCaretPosition', { startAndEnd: true } ) ),
[ 3, 6 ]
);
} );
it( 'correctly wraps the selected text when using encapsulateSelection', async function () {
it( 'correctly wraps the selected text when using encapsulateSelection', async () => {
await browser.execute( () => {
$( '.cm-editor' ).textSelection( 'setContents', 'foobaz' )
.textSelection( 'encapsulateSelection', {
@ -83,7 +79,7 @@ describe( 'CodeMirror textSelection for the wikitext 2010 editor', () => {
);
} );
it( "correctly inserts the 'peri' option when using encapsulateSelection", async function () {
it( "correctly inserts the 'peri' option when using encapsulateSelection", async () => {
await browser.execute( () => {
$( '.cm-editor' ).textSelection( 'setContents', 'foobaz' )
.textSelection( 'encapsulateSelection', {

View file

@ -17,11 +17,7 @@ class UserPreferences {
await BlankPage.open();
Util.waitForModuleState( 'mediawiki.base' );
return await browser.execute( function ( prefs ) {
return mw.loader.using( 'mediawiki.api' ).then( function () {
return new mw.Api().saveOptions( prefs );
} );
}, preferences );
return await browser.execute( ( prefs ) => mw.loader.using( 'mediawiki.api' ).then( () => new mw.Api().saveOptions( prefs ) ), preferences );
}
async enableWikitext2010EditorWithCodeMirror() {