From 26076514c18bacc6635830a54f070eb794385b6b Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 7 Jun 2024 19:01:54 +0000 Subject: [PATCH] =?UTF-8?q?ci:=20=F0=9F=91=B7=20lint=20code=20to=20MediaWi?= =?UTF-8?q?ki=20standards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check commit and GitHub actions for more details --- .../clientPreferences.js | 3 +-- .../clientPrefs.polyfill.js | 8 +++--- .../skins.citizen.preferences.js | 4 +-- resources/skins.citizen.scripts/inline.js | 6 ++--- resources/skins.citizen.scripts/search.js | 2 +- resources/skins.citizen.scripts/skin.js | 26 ++++++++----------- .../skins.citizen.scripts/tableOfContents.js | 16 ++++-------- .../searchClients/mwActionApi.js | 8 ++---- .../searchClients/mwRestApi.js | 4 +-- .../searchClients/smwAskApi.js | 16 +++--------- 10 files changed, 32 insertions(+), 61 deletions(-) diff --git a/resources/skins.citizen.preferences/clientPreferences.js b/resources/skins.citizen.preferences/clientPreferences.js index cb84bc566..f55c3bd0f 100644 --- a/resources/skins.citizen.preferences/clientPreferences.js +++ b/resources/skins.citizen.preferences/clientPreferences.js @@ -231,8 +231,7 @@ function createRow( className ) { * @param {string} featureName * @return {MwMessage} */ -const getFeatureLabelMsg = ( featureName ) => - getMessage( `${ featureName }-name` ); +const getFeatureLabelMsg = ( featureName ) => getMessage( `${ featureName }-name` ); /** * adds a toggle button diff --git a/resources/skins.citizen.preferences/clientPrefs.polyfill.js b/resources/skins.citizen.preferences/clientPrefs.polyfill.js index fb4a0c0a6..594396314 100644 --- a/resources/skins.citizen.preferences/clientPrefs.polyfill.js +++ b/resources/skins.citizen.preferences/clientPrefs.polyfill.js @@ -43,7 +43,7 @@ function isValidFeatureValue( value ) { function saveClientPrefs( feature, value ) { const existingStorage = mw.storage.get( CLIENTPREF_STORAGE_NAME ) || ''; const data = {}; - existingStorage.split( CLIENTPREF_DELIMITER ).forEach( function ( keyValuePair ) { + existingStorage.split( CLIENTPREF_DELIMITER ).forEach( ( keyValuePair ) => { const m = keyValuePair.match( /^([\w-]+)-clientpref-(\w+)$/ ); if ( m ) { data[ m[ 1 ] ] = m[ 2 ]; @@ -51,9 +51,7 @@ function saveClientPrefs( feature, value ) { } ); data[ feature ] = value; - const newStorage = Object.keys( data ).map( function ( key ) { - return key + CLIENTPREF_SUFFIX + data[ key ]; - } ).join( CLIENTPREF_DELIMITER ); + const newStorage = Object.keys( data ).map( ( key ) => key + CLIENTPREF_SUFFIX + data[ key ] ).join( CLIENTPREF_DELIMITER ); mw.storage.set( CLIENTPREF_STORAGE_NAME, newStorage ); } @@ -100,7 +98,7 @@ function clientPrefs() { get: function ( feature ) { const featurePrefix = feature + CLIENTPREF_SUFFIX; const docClass = document.documentElement.className; - // eslint-disable-next-line security/detect-non-literal-regexp + const featureRegEx = new RegExp( '(^| )' + mw.util.escapeRegExp( featurePrefix ) + '([a-zA-Z0-9]+)( |$)' ); diff --git a/resources/skins.citizen.preferences/skins.citizen.preferences.js b/resources/skins.citizen.preferences/skins.citizen.preferences.js index e600058fb..762d115a1 100644 --- a/resources/skins.citizen.preferences/skins.citizen.preferences.js +++ b/resources/skins.citizen.preferences/skins.citizen.preferences.js @@ -132,9 +132,7 @@ function handleClientPreferences() { 'skin-citizen-light', 'skin-citizen-dark' ]; - const legacyThemeKey = Object.keys( CLIENTPREFS_THEME_MAP ).find( ( key ) => { - return CLIENTPREFS_THEME_MAP[ key ] === clientPrefs.get( 'skin-theme' ); - } ); + const legacyThemeKey = Object.keys( CLIENTPREFS_THEME_MAP ).find( ( key ) => CLIENTPREFS_THEME_MAP[ key ] === clientPrefs.get( 'skin-theme' ) ); document.documentElement.classList.remove( ...LEGACY_THEME_CLASSES ); document.documentElement.classList.add( `skin-citizen-${ legacyThemeKey }` ); }; diff --git a/resources/skins.citizen.scripts/inline.js b/resources/skins.citizen.scripts/inline.js index d8086d255..b92326eb8 100644 --- a/resources/skins.citizen.scripts/inline.js +++ b/resources/skins.citizen.scripts/inline.js @@ -14,9 +14,9 @@ window.clientPrefs = () => { const storage = localStorage.getItem( 'mwclientpreferences' ); if ( storage ) { // TODO: Just use array for localStorage - storage.split( ',' ).forEach( function ( pref ) { + storage.split( ',' ).forEach( ( pref ) => { className = className.replace( - // eslint-disable-next-line security/detect-non-literal-regexp + new RegExp( '(^| )' + pref.replace( /-clientpref-\w+$|[^\w-]+/g, '' ) + '-clientpref-\\w+( |$)' ), '$1' + pref + '$2' ); @@ -33,7 +33,7 @@ window.clientPrefs = () => { // eslint-disable-next-line max-len, es-x/no-object-values const classesToRemove = Object.values( CLIENTPREFS_THEME_MAP ).map( ( theme ) => LEGACY_PREFIX + theme ); className = className.replace( - // eslint-disable-next-line security/detect-non-literal-regexp + new RegExp( classesToRemove.join( '|' ), 'g' ), '' ); diff --git a/resources/skins.citizen.scripts/search.js b/resources/skins.citizen.scripts/search.js index 1f66678a4..d0ab69fb8 100644 --- a/resources/skins.citizen.scripts/search.js +++ b/resources/skins.citizen.scripts/search.js @@ -71,7 +71,7 @@ function setLoadingIndicatorListeners( element, attach, eventCallback ) { /** @type { "addEventListener" | "removeEventListener" } */ const addOrRemoveListener = ( attach ? 'addEventListener' : 'removeEventListener' ); - [ 'input', 'focusin', 'focusout' ].forEach( function ( eventType ) { + [ 'input', 'focusin', 'focusout' ].forEach( ( eventType ) => { element[ addOrRemoveListener ]( eventType, eventCallback ); } ); diff --git a/resources/skins.citizen.scripts/skin.js b/resources/skins.citizen.scripts/skin.js index 3efa7c59f..0dcbd6419 100644 --- a/resources/skins.citizen.scripts/skin.js +++ b/resources/skins.citizen.scripts/skin.js @@ -22,24 +22,20 @@ function enableCssAnimations( document ) { function initStickyHeader( document ) { const { initDirectionObserver, initIntersectionObserver } = require( './scrollObserver.js' ); - const toggleScrollClass = ( removeClass, addClass ) => { - return () => { - window.requestAnimationFrame( () => { - document.body.classList.remove( removeClass ); - document.body.classList.add( addClass ); - } ); - }; + const toggleScrollClass = ( removeClass, addClass ) => () => { + window.requestAnimationFrame( () => { + document.body.classList.remove( removeClass ); + document.body.classList.add( addClass ); + } ); }; const addScrollDownClass = toggleScrollClass( SCROLL_UP_CLASS, SCROLL_DOWN_CLASS ); const addScrollUpClass = toggleScrollClass( SCROLL_DOWN_CLASS, SCROLL_UP_CLASS ); - const toggleStickyClass = ( state ) => { - return () => { - window.requestAnimationFrame( () => { - document.body.classList.toggle( STICKY_CLASS, state ); - } ); - }; + const toggleStickyClass = ( state ) => () => { + window.requestAnimationFrame( () => { + document.body.classList.toggle( STICKY_CLASS, state ); + } ); }; initDirectionObserver( addScrollDownClass, addScrollUpClass, 10 ); @@ -118,7 +114,7 @@ function main( window ) { checkbox.bind(); dropdown.init(); - mw.hook( 'wikipage.content' ).add( function ( content ) { + mw.hook( 'wikipage.content' ).add( ( content ) => { // content is a jQuery object // note that this refers to .mw-body-content, not #bodyContent initBodyContent( content[ 0 ] ); @@ -148,7 +144,7 @@ function main( window ) { if ( document.readyState === 'interactive' || document.readyState === 'complete' ) { main( window ); } else { - document.addEventListener( 'DOMContentLoaded', function () { + document.addEventListener( 'DOMContentLoaded', () => { main( window ); } ); } diff --git a/resources/skins.citizen.scripts/tableOfContents.js b/resources/skins.citizen.scripts/tableOfContents.js index 7182762a5..ca30d7fcb 100644 --- a/resources/skins.citizen.scripts/tableOfContents.js +++ b/resources/skins.citizen.scripts/tableOfContents.js @@ -60,15 +60,11 @@ function init( bodyContent ) { return; } - const extractIds = () => { - return Array.from( toc.querySelectorAll( '.citizen-toc__listItem' ) ) - .map( ( tocListEl ) => tocListEl.id.slice( 4 ) ); - }; + const extractIds = () => Array.from( toc.querySelectorAll( '.citizen-toc__listItem' ) ) + .map( ( tocListEl ) => tocListEl.id.slice( 4 ) ); - const queryElements = ( ids ) => { - return ids.map( ( id ) => bodyContent.querySelector( '#' + CSS.escape( id ) ) ) - .filter( ( element ) => element !== null && element !== undefined ); - }; + const queryElements = ( ids ) => ids.map( ( id ) => bodyContent.querySelector( '#' + CSS.escape( id ) ) ) + .filter( ( element ) => element !== null && element !== undefined ); const headlines = queryElements( extractIds() ); @@ -76,9 +72,7 @@ function init( bodyContent ) { const scrollPaddingTop = computedStyle.getPropertyValue( 'scroll-padding-top' ); const topMargin = Number( scrollPaddingTop.slice( 0, -2 ) ) + 20; - const getTopMargin = () => { - return topMargin; - }; + const getTopMargin = () => topMargin; const initSectionObserver = require( './sectionObserver.js' ).init; diff --git a/resources/skins.citizen.search/searchClients/mwActionApi.js b/resources/skins.citizen.search/searchClients/mwActionApi.js index 6a6882e53..87ab5ae6b 100644 --- a/resources/skins.citizen.search/searchClients/mwActionApi.js +++ b/resources/skins.citizen.search/searchClients/mwActionApi.js @@ -82,9 +82,7 @@ function adaptApiResponse( config, query, response, showDescription ) { // Sometimes there can be multiple redirect object for the same page, only take the one with lower index if ( response.pages.length !== pageCount ) { - response.pages = response.pages.filter( ( obj ) => { - return Object.prototype.hasOwnProperty.call( obj, 'title' ); - } ); + response.pages = response.pages.filter( ( obj ) => Object.prototype.hasOwnProperty.call( obj, 'title' ) ); } } @@ -195,9 +193,7 @@ function mwActionApiSearchClient( config ) { } } ); const searchResponsePromise = result.fetch - .then( ( /** @type {ActionResponse} */ res ) => { - return adaptApiResponse( config, q, res, showDescription ); - } ); + .then( ( /** @type {ActionResponse} */ res ) => adaptApiResponse( config, q, res, showDescription ) ); return { abort: result.abort, fetch: searchResponsePromise diff --git a/resources/skins.citizen.search/searchClients/mwRestApi.js b/resources/skins.citizen.search/searchClients/mwRestApi.js index 783b055ee..622383fa2 100644 --- a/resources/skins.citizen.search/searchClients/mwRestApi.js +++ b/resources/skins.citizen.search/searchClients/mwRestApi.js @@ -108,9 +108,7 @@ function mwRestApiSearchClient( config ) { } } ); const searchResponsePromise = result.fetch - .then( ( /** @type {RestResponse} */ res ) => { - return adaptApiResponse( config, q, res, showDescription ); - } ); + .then( ( /** @type {RestResponse} */ res ) => adaptApiResponse( config, q, res, showDescription ) ); return { abort: result.abort, fetch: searchResponsePromise diff --git a/resources/skins.citizen.search/searchClients/smwAskApi.js b/resources/skins.citizen.search/searchClients/smwAskApi.js index e41fcb1fb..538259a40 100644 --- a/resources/skins.citizen.search/searchClients/smwAskApi.js +++ b/resources/skins.citizen.search/searchClients/smwAskApi.js @@ -46,9 +46,7 @@ function getFirstString( s ) { */ function adaptApiResponse( config, query, response, showDescription ) { const urlGeneratorInstance = urlGenerator( config ); - const getDescription = ( page ) => { - return getFirstString( page?.printouts?.Description ).slice( 0, 60 ); - }; + const getDescription = ( page ) => getFirstString( page?.printouts?.Description ).slice( 0, 60 ); return { query, @@ -113,12 +111,8 @@ function smwAskApiSearchClient( config ) { const searchApiUrl = config.wgScriptPath + '/api.php'; const getConditions = () => { - const separateConditions = ( s ) => { - return s.replace( /\]\]\s*\[\[/g, '|' ); - }; - const removeSquareBrackets = ( s ) => { - return s.replace( /\[|\]/g, '' ); - }; + const separateConditions = ( s ) => s.replace( /\]\]\s*\[\[/g, '|' ); + const removeSquareBrackets = ( s ) => s.replace( /\[|\]/g, '' ); const conditions = removeSquareBrackets( separateConditions( q ) ); return conditions; }; @@ -159,9 +153,7 @@ function smwAskApiSearchClient( config ) { } } ); const searchResponsePromise = result.fetch - .then( ( /** @type {SMWAskArgResponse} */ res ) => { - return adaptApiResponse( config, q, res, showDescription ); - } ); + .then( ( /** @type {SMWAskArgResponse} */ res ) => adaptApiResponse( config, q, res, showDescription ) ); return { abort: result.abort, fetch: searchResponsePromise