From 4ef5376cab550d3ca8e7226385b300712cc61fb1 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Fri, 7 Jul 2023 18:00:14 -0400 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E2=99=BB=EF=B8=8F=20clean=20?= =?UTF-8?q?up=20various=20eslint=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skins.citizen.preferences.js | 5 +-- .../skins.citizen.search/gateway/smwAskApi.js | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/resources/skins.citizen.preferences/skins.citizen.preferences.js b/resources/skins.citizen.preferences/skins.citizen.preferences.js index a962c975..1fc06958 100644 --- a/resources/skins.citizen.preferences/skins.citizen.preferences.js +++ b/resources/skins.citizen.preferences/skins.citizen.preferences.js @@ -105,10 +105,9 @@ function getPref() { /** * Save to localstorage if preference is changed * - * @param {Event} event * @return {void} */ -function setPref( event ) { +function setPref() { const // eslint-disable-next-line compat/compat formData = Object.fromEntries( new FormData( document.getElementById( CLASS + '-form' ) ) ), @@ -367,7 +366,7 @@ function initPref( window ) { // MIT. Copyright (c) Feross Aboukhadijeh. if ( typeof Object.fromEntries !== 'function' ) { Object.defineProperty( Object, 'fromEntries', { - value( iterable ) { + value( iterable ) { return Array.from( iterable ).reduce( ( obj, [ key, val ] ) => { obj[ key ] = val; return obj; diff --git a/resources/skins.citizen.search/gateway/smwAskApi.js b/resources/skins.citizen.search/gateway/smwAskApi.js index 5ada6179..4d8aff2b 100644 --- a/resources/skins.citizen.search/gateway/smwAskApi.js +++ b/resources/skins.citizen.search/gateway/smwAskApi.js @@ -15,11 +15,14 @@ function getUrl( input ) { if ( input.includes( ':' ) ) { let namespace = input.split( ':' )[ 0 ]; - if ( namespace === 'Category' ) { namespace = ':' + namespace; } + if ( namespace === 'Category' ) { + namespace = ':' + namespace; + } input = input.split( ':' )[ 1 ]; askQuery += '[[' + namespace + ':+]]'; } + /* eslint-disable-next-line es-x/no-string-prototype-replaceall */ askQuery += askQueryTemplate.replaceAll( '${input}', input ); askQuery += '|limit=' + maxResults; @@ -52,11 +55,19 @@ function convertDataToResults( data ) { let textEN = ''; let textResult = ''; for ( const text of item.printouts.displaytitle ) { - if ( text[ 'Language code' ].item[ 0 ] === userLang ) { textResult = text.Text.item[ 0 ]; } - if ( text[ 'Language code' ].item[ 0 ] === 'en' ) { textEN = text.Text.item[ 0 ]; } + if ( text[ 'Language code' ].item[ 0 ] === userLang ) { + textResult = text.Text.item[ 0 ]; + } + if ( text[ 'Language code' ].item[ 0 ] === 'en' ) { + textEN = text.Text.item[ 0 ]; + } + } + if ( textResult === '' ) { + textResult = textEN; + } + if ( textResult === '' ) { + textResult = item.printouts.displaytitle[ 0 ].Text.item[ 0 ]; } - if ( textResult === '' ) { textResult = textEN; } - if ( textResult === '' ) { textResult = item.printouts.displaytitle[ 0 ].Text.item[ 0 ]; } return textResult; } else if ( item.printouts.displaytitle && item.printouts.displaytitle.length ) { return item.printouts.displaytitle[ 0 ]; @@ -72,11 +83,19 @@ function convertDataToResults( data ) { let textEN = ''; let textResult = ''; for ( const text of item.printouts.desc ) { - if ( text[ 'Language code' ].item[ 0 ] === userLang ) { textResult = text.Text.item[ 0 ]; } - if ( text[ 'Language code' ].item[ 0 ] === 'en' ) { textEN = text.Text.item[ 0 ]; } + if ( text[ 'Language code' ].item[ 0 ] === userLang ) { + textResult = text.Text.item[ 0 ]; + } + if ( text[ 'Language code' ].item[ 0 ] === 'en' ) { + textEN = text.Text.item[ 0 ]; + } + } + if ( textResult === '' ) { + textResult = textEN; + } + if ( textResult === '' ) { + textResult = item.printouts.desc[ 0 ].Text.item[ 0 ]; } - if ( textResult === '' ) { textResult = textEN; } - if ( textResult === '' ) { textResult = item.printouts.desc[ 0 ].Text.item[ 0 ]; } return textResult; } else if ( item.printouts.desc && item.printouts.desc.length ) { return item.printouts.desc[ 0 ]; @@ -85,8 +104,8 @@ function convertDataToResults( data ) { const getThumbnail = ( item ) => { if ( item.printouts.thumbnail && item.printouts.thumbnail.length ) { - const img_title = item.printouts.thumbnail[ 0 ].fulltext; - return config.wgScriptPath + '/index.php?title=Special:Redirect/file/' + img_title + '&width=200&height=200'; + const imgTitle = item.printouts.thumbnail[ 0 ].fulltext; + return config.wgScriptPath + '/index.php?title=Special:Redirect/file/' + imgTitle + '&width=200&height=200'; } else { return undefined; } };