mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Hygiene: favor string templates over concatenation
Update the ESLint config to favor ES6 strings where variables or string concatenation is used and fix *all* offenders automatically via: eslint \ --cache \ --max-warnings 0 \ --report-unused-disable-directives \ --fix \ src tests Change-Id: I1a9345162348e5ded21d541e7a2ce251ea72ab5a
This commit is contained in:
parent
e284163014
commit
007cc5ab7c
|
@ -37,6 +37,7 @@
|
|||
"no-unused-vars": 0,
|
||||
"no-undef": 0,
|
||||
"no-var": 0,
|
||||
"prefer-template": 0,
|
||||
"quote-props": 0,
|
||||
"curly": 0,
|
||||
"one-var": 0,
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"no-use-before-define": 0,
|
||||
"no-var": 2,
|
||||
"prefer-const": 1,
|
||||
"prefer-template": 1,
|
||||
"one-var": 0, // Interferes with prefer-const.
|
||||
"max-len": [
|
||||
1,
|
||||
|
|
BIN
resources/dist/index.js.json
vendored
BIN
resources/dist/index.js.json
vendored
Binary file not shown.
|
@ -73,7 +73,7 @@ export default function createContainer() {
|
|||
*/
|
||||
get( name ) {
|
||||
if ( !this.has( name ) ) {
|
||||
throw new Error( 'The service "' + name + '" hasn\'t been defined.' );
|
||||
throw new Error( `The service "${ name }" hasn't been defined.` );
|
||||
}
|
||||
|
||||
const factory = factories[ name ];
|
||||
|
|
|
@ -28,7 +28,7 @@ exports.getEditCountBucket = function getEditCountBucket( count ) {
|
|||
bucket = '1000+';
|
||||
}
|
||||
|
||||
return bucket + ' edits';
|
||||
return `${ bucket } edits`;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -58,5 +58,5 @@ exports.getPreviewCountBucket = function getPreviewCountBucket( count ) {
|
|||
bucket = '21+';
|
||||
}
|
||||
|
||||
return bucket !== undefined ? ( bucket + ' previews' ) : 'unknown';
|
||||
return bucket !== undefined ? ( `${ bucket } previews` ) : 'unknown';
|
||||
};
|
||||
|
|
|
@ -38,12 +38,12 @@ export function formatPlainTextExtract( plainTextExtract, title ) {
|
|||
*/
|
||||
function makeTitleInExtractBold( extract, title ) {
|
||||
const elements = [],
|
||||
boldIdentifier = '<bi-' + Math.random() + '>',
|
||||
snip = '<snip-' + Math.random() + '>';
|
||||
boldIdentifier = `<bi-${ Math.random() }>`,
|
||||
snip = `<snip-${ Math.random() }>`;
|
||||
|
||||
title = title.replace( /\s+/g, ' ' ).trim(); // Remove extra white spaces
|
||||
const escapedTitle = mw.RegExp.escape( title ); // Escape RegExp elements
|
||||
const regExp = new RegExp( '(^|\\s)(' + escapedTitle + ')(|$)', 'i' );
|
||||
const regExp = new RegExp( `(^|\\s)(${ escapedTitle })(|$)`, 'i' );
|
||||
|
||||
// Remove text in parentheses along with the parentheses
|
||||
extract = extract.replace( /\s+/, ' ' ); // Remove extra white spaces
|
||||
|
@ -53,7 +53,7 @@ function makeTitleInExtractBold( extract, title ) {
|
|||
// Also, the title is escaped of RegExp elements thus can't have "*"
|
||||
extract = extract.replace(
|
||||
regExp,
|
||||
'$1' + snip + boldIdentifier + '$2' + snip + '$3'
|
||||
`$1${ snip }${ boldIdentifier }$2${ snip }$3`
|
||||
);
|
||||
extract = extract.split( snip );
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ export default function createRESTBaseGateway( ajax, config, extractParser ) {
|
|||
return ajax( {
|
||||
url: endpoint + encodeURIComponent( title ),
|
||||
headers: {
|
||||
Accept: 'application/json; charset=utf-8; ' +
|
||||
'profile="' + RESTBASE_PROFILE + '"'
|
||||
Accept: `application/json; charset=utf-8; profile="${ RESTBASE_PROFILE }"`
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
@ -157,7 +156,7 @@ function generateThumbnailData( thumbnail, original, thumbSize ) {
|
|||
return original;
|
||||
}
|
||||
|
||||
parts[ parts.length - 1 ] = width + 'px-' + filename;
|
||||
parts[ parts.length - 1 ] = `${ width }px-${ filename }`;
|
||||
|
||||
return {
|
||||
source: parts.join( '/' ),
|
||||
|
|
|
@ -236,7 +236,7 @@ mw.requestIdleCallback( function () {
|
|||
|
||||
mw.hook( 'wikipage.content' ).add( function ( $container ) {
|
||||
const invalidLinksSelector = BLACKLISTED_LINKS.join( ', ' ),
|
||||
validLinkSelector = 'a[href][title]:not(' + invalidLinksSelector + ')';
|
||||
validLinkSelector = `a[href][title]:not(${ invalidLinksSelector })`;
|
||||
|
||||
rendererInit();
|
||||
|
||||
|
|
|
@ -513,7 +513,7 @@ export function layoutPreview(
|
|||
|
||||
popup.css( {
|
||||
top: offsetTop,
|
||||
left: layout.offset.left + 'px'
|
||||
left: `${ layout.offset.left }px`
|
||||
} );
|
||||
|
||||
if ( flippedY && hasThumbnail ) {
|
||||
|
|
|
@ -13,21 +13,21 @@ const mw = window.mediaWiki;
|
|||
* @return {jQuery} settings dialog
|
||||
*/
|
||||
export function createSettingsDialog( navPopupsEnabled ) {
|
||||
const path = mw.config.get( 'wgExtensionAssetsPath' ) +
|
||||
'/Popups/resources/ext.popups.main/images/',
|
||||
const assets = mw.config.get( 'wgExtensionAssetsPath' ),
|
||||
path = `${ assets }/Popups/resources/ext.popups.main/images/`,
|
||||
choices = [
|
||||
{
|
||||
id: 'simple',
|
||||
name: mw.msg( 'popups-settings-option-simple' ),
|
||||
description: mw.msg( 'popups-settings-option-simple-description' ),
|
||||
image: path + 'hovercard.svg',
|
||||
image: `${ path }hovercard.svg`,
|
||||
isChecked: true
|
||||
},
|
||||
{
|
||||
id: 'advanced',
|
||||
name: mw.msg( 'popups-settings-option-advanced' ),
|
||||
description: mw.msg( 'popups-settings-option-advanced-description' ),
|
||||
image: path + 'navpop.svg'
|
||||
image: `${ path }navpop.svg`
|
||||
},
|
||||
{
|
||||
id: 'off',
|
||||
|
|
|
@ -101,7 +101,7 @@ export default function createSettingsDialogRenderer() {
|
|||
}
|
||||
|
||||
// Check the appropriate radio button
|
||||
$dialog.find( '#mwe-popups-settings-' + name )
|
||||
$dialog.find( `#mwe-popups-settings-${ name }` )
|
||||
.prop( 'checked', true );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,8 +13,8 @@ export function renderPagePreview(
|
|||
return `
|
||||
<div class='mwe-popups' role='tooltip' aria-hidden>
|
||||
<div class='mwe-popups-container'>
|
||||
${hasThumbnail ? `<a href='${url}' class='mwe-popups-discreet'></a>` : ''}
|
||||
<a dir='${languageDirection}' lang='${languageCode}' class='mwe-popups-extract' href='${url}'></a>
|
||||
${ hasThumbnail ? `<a href='${ url }' class='mwe-popups-discreet'></a>` : '' }
|
||||
<a dir='${ languageDirection }' lang='${ languageCode }' class='mwe-popups-extract' href='${ url }'></a>
|
||||
<footer>
|
||||
<a class='mwe-popups-settings-icon mw-ui-icon mw-ui-icon-element mw-ui-icon-popups-settings'></a>
|
||||
</footer>
|
||||
|
|
|
@ -18,15 +18,15 @@ export function renderPreview(
|
|||
extractMsg = escapeHTML( extractMsg );
|
||||
linkMsg = escapeHTML( linkMsg );
|
||||
return `
|
||||
<div class='mwe-popups mwe-popups-type-${type}' role='tooltip' aria-hidden>
|
||||
<div class='mwe-popups mwe-popups-type-${ type }' role='tooltip' aria-hidden>
|
||||
<div class='mwe-popups-container'>
|
||||
<div class='mw-ui-icon mw-ui-icon-element mw-ui-icon-preview-${type}'></div>
|
||||
${showTitle ? `<strong class='mwe-popups-title'>${title}</strong>` : ''}
|
||||
<a href='${url}' class='mwe-popups-extract'>
|
||||
<span class='mwe-popups-message'>${extractMsg}</span>
|
||||
<div class='mw-ui-icon mw-ui-icon-element mw-ui-icon-preview-${ type }'></div>
|
||||
${ showTitle ? `<strong class='mwe-popups-title'>${ title }</strong>` : '' }
|
||||
<a href='${ url }' class='mwe-popups-extract'>
|
||||
<span class='mwe-popups-message'>${ extractMsg }</span>
|
||||
</a>
|
||||
<footer>
|
||||
<a href='${url}' class='mwe-popups-read-link'>${linkMsg}</a>
|
||||
<a href='${ url }' class='mwe-popups-read-link'>${ linkMsg }</a>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -57,31 +57,31 @@ export function renderSettingsDialog( model ) {
|
|||
<div>
|
||||
<div class='mw-ui-icon mw-ui-icon-element mw-ui-icon-popups-close close'>Close</div>
|
||||
</div>
|
||||
<h1>${heading}</h1>
|
||||
<h1>${ heading }</h1>
|
||||
<div>
|
||||
<button class='save mw-ui-button mw-ui-progressive'>${saveLabel}</button>
|
||||
<button class='okay mw-ui-button mw-ui-progressive' style='display:none;'>${okLabel}</button>
|
||||
<button class='save mw-ui-button mw-ui-progressive'>${ saveLabel }</button>
|
||||
<button class='okay mw-ui-button mw-ui-progressive' style='display:none;'>${ okLabel }</button>
|
||||
</div>
|
||||
</header>
|
||||
<main id='mwe-popups-settings-form'>
|
||||
<form>
|
||||
${choices.map( ( { id, name, description, isChecked } ) => `
|
||||
${ choices.map( ( { id, name, description, isChecked } ) => `
|
||||
<p>
|
||||
<input
|
||||
name='mwe-popups-setting'
|
||||
${isChecked ? 'checked' : ''}
|
||||
value='${id}'
|
||||
${ isChecked ? 'checked' : '' }
|
||||
value='${ id }'
|
||||
type='radio'
|
||||
id='mwe-popups-settings-${id}'>
|
||||
<label for='mwe-popups-settings-${id}'>
|
||||
<span>${name}</span>
|
||||
${description}
|
||||
id='mwe-popups-settings-${ id }'>
|
||||
<label for='mwe-popups-settings-${ id }'>
|
||||
<span>${ name }</span>
|
||||
${ description }
|
||||
</label>
|
||||
</p>` ).join( '' )}
|
||||
</p>` ).join( '' ) }
|
||||
</form>
|
||||
</main>
|
||||
<div class='mwe-popups-settings-help' style='display:none;'>
|
||||
<p>${helpText}</p>
|
||||
<p>${ helpText }</p>
|
||||
</div>
|
||||
</section>
|
||||
`.trim();
|
||||
|
|
|
@ -132,7 +132,7 @@ export function createThumbnailElement(
|
|||
y,
|
||||
width: thumbnailWidth,
|
||||
height: thumbnailHeight,
|
||||
'clip-path': 'url(#' + clipPath + ')'
|
||||
'clip-path': `url(#${ clipPath })`
|
||||
} );
|
||||
|
||||
const $thumbnail = $( document.createElementNS( nsSvg, 'svg' ) )
|
||||
|
|
|
@ -28,7 +28,7 @@ QUnit.test( '#getEditCountBucket', ( assert ) => {
|
|||
assert.equal(
|
||||
bucket,
|
||||
cases[ i ][ 1 ],
|
||||
'Edit count bucket is "' + bucket + '" when edit count is ' + count + '.'
|
||||
`Edit count bucket is "${ bucket }" when edit count is ${ count }.`
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
@ -61,8 +61,7 @@ QUnit.test( '#getPreviewCountBucket', ( assert ) => {
|
|||
assert.equal(
|
||||
bucket,
|
||||
cases[ i ][ 1 ],
|
||||
'Preview count bucket is "' +
|
||||
bucket + '" when preview count is ' + count + '.'
|
||||
`Preview count bucket is "${ bucket }" when preview count is ${ count }.`
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -150,13 +150,13 @@ const DEFAULT_CONSTANTS = {
|
|||
);
|
||||
|
||||
function provideParsedExtract( page ) {
|
||||
return '!' + page.extract + '!';
|
||||
return `!${ page.extract }!`;
|
||||
}
|
||||
|
||||
QUnit.module( 'gateway/rest', {
|
||||
beforeEach() {
|
||||
window.mediaWiki.Title = function ( title ) {
|
||||
this.getUrl = () => 'url/' + title;
|
||||
this.getUrl = () => `url/${ title }`;
|
||||
};
|
||||
},
|
||||
afterEach() {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { createStubUser } from './stubs';
|
|||
QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
||||
beforeEach() {
|
||||
function newFromText( title ) {
|
||||
return { getUrl() { return 'url/' + title; } };
|
||||
return { getUrl() { return `url/${ title }`; } };
|
||||
}
|
||||
|
||||
mediaWiki.Title = { newFromText };
|
||||
|
@ -31,7 +31,7 @@ QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( a
|
|||
|
||||
assert.deepEqual(
|
||||
behavior.settingsUrl,
|
||||
'url/' + testCase[ 1 ]
|
||||
`url/${ testCase[ 1 ] }`
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -63,7 +63,7 @@ export function createStubTitle( namespace, prefixedDb ) {
|
|||
return prefixedDb;
|
||||
},
|
||||
getUrl() {
|
||||
return `/wiki/${prefixedDb}`;
|
||||
return `/wiki/${ prefixedDb }`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -820,12 +820,12 @@ QUnit.test( '#layoutPreview - no thumbnail', ( assert ) => {
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
layout.offset.top + 'px',
|
||||
`${ layout.offset.top }px`,
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
} );
|
||||
|
@ -850,12 +850,12 @@ QUnit.test( '#layoutPreview - tall preview, flipped X, has thumbnail', ( assert
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
layout.offset.top + 'px',
|
||||
`${ layout.offset.top }px`,
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.notOk(
|
||||
|
@ -889,17 +889,17 @@ QUnit.test( '#layoutPreview - portrait preview, flipped X, has thumbnail, small
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
layout.offset.top + 'px',
|
||||
`${ layout.offset.top }px`,
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.find( '.mwe-popups-extract' ).css( 'margin-top' ),
|
||||
( 199 - 8 ) + 'px', // thumb height - pokey size
|
||||
`${ 199 - 8 }px`, // thumb height - pokey size
|
||||
'Extract margin top has been set when preview height is smaller than the predefined landscape image height.'
|
||||
);
|
||||
assert.equal(
|
||||
|
@ -929,12 +929,12 @@ QUnit.test( '#layoutPreview - portrait preview, flipped X, has thumbnail, big he
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
layout.offset.top + 'px',
|
||||
`${ layout.offset.top }px`,
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
|
@ -973,12 +973,12 @@ QUnit.test( '#layoutPreview - tall preview, has thumbnail, flipped Y', ( assert
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
( layout.offset.top - 20 ) + 'px', // - outer height
|
||||
`${ layout.offset.top - 20 }px`, // - outer height
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.notOk(
|
||||
|
@ -1011,12 +1011,12 @@ QUnit.test( '#layoutPreview - tall preview, has thumbnail, flipped X and Y', ( a
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
( layout.offset.top - 20 ) + 'px', // - outer height
|
||||
`${ layout.offset.top - 20 }px`, // - outer height
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
|
@ -1050,12 +1050,12 @@ QUnit.test( '#layoutPreview - portrait preview, has thumbnail, flipped X and Y',
|
|||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'top' ),
|
||||
( layout.offset.top - 20 ) + 'px', // - outer height
|
||||
`${ layout.offset.top - 20 }px`, // - outer height
|
||||
'Top is correct.'
|
||||
);
|
||||
assert.equal(
|
||||
preview.el.css( 'left' ),
|
||||
layout.offset.left + 'px',
|
||||
`${ layout.offset.left }px`,
|
||||
'Left is correct.'
|
||||
);
|
||||
assert.notOk(
|
||||
|
|
|
@ -69,32 +69,32 @@ QUnit.test( 'createThumbnail - tall image element', ( assert ) => {
|
|||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'x' ),
|
||||
case_.expectedX,
|
||||
'Image element x coordinate is correct. ' + case_.message
|
||||
`Image element x coordinate is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'y' ),
|
||||
case_.expectedY,
|
||||
'Image element y coordinate is correct. ' + case_.message
|
||||
`Image element y coordinate is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'width' ),
|
||||
case_.width,
|
||||
'Image element width is correct. ' + case_.message
|
||||
`Image element width is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'height' ),
|
||||
case_.height,
|
||||
'Image element height is correct. ' + case_.message
|
||||
`Image element height is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.attr( 'width' ),
|
||||
case_.expectedSVGWidth,
|
||||
'Image SVG width is correct. ' + case_.message
|
||||
`Image SVG width is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.attr( 'height' ),
|
||||
case_.expectedSVGHeight,
|
||||
'Image SVG height is correct. ' + case_.message
|
||||
`Image SVG height is correct. ${ case_.message }`
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
@ -157,32 +157,32 @@ QUnit.test( 'createThumbnail - landscape image element', ( assert ) => {
|
|||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'x' ),
|
||||
case_.expectedX,
|
||||
'Image x coordinate is correct. ' + case_.message
|
||||
`Image x coordinate is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'y' ),
|
||||
case_.expectedY,
|
||||
'Image y coordinate is correct. ' + case_.message
|
||||
`Image y coordinate is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'width' ),
|
||||
case_.width,
|
||||
'Image element width is correct. ' + case_.message
|
||||
`Image element width is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.find( 'image' ).attr( 'height' ),
|
||||
case_.height,
|
||||
'Image element height is correct. ' + case_.message
|
||||
`Image element height is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.attr( 'width' ),
|
||||
case_.expectedSVGWidth,
|
||||
'Image SVG width is correct. ' + case_.message
|
||||
`Image SVG width is correct. ${ case_.message }`
|
||||
);
|
||||
assert.equal(
|
||||
thumbnail.el.attr( 'height' ),
|
||||
case_.expectedSVGHeight,
|
||||
'Image SVG height is correct. ' + case_.message
|
||||
`Image SVG height is correct. ${ case_.message }`
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -10,7 +10,7 @@ class PopupsPage extends Page {
|
|||
setup() {
|
||||
browser.call( () => {
|
||||
return new Promise( ( resolve ) => {
|
||||
fs.readFile( `${__dirname}/../fixtures/test_page.wikitext`, 'utf-8', ( err, content ) => {
|
||||
fs.readFile( `${ __dirname }/../fixtures/test_page.wikitext`, 'utf-8', ( err, content ) => {
|
||||
if ( err ) {
|
||||
throw err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue