From e2e02c9a2fb103eac6719a6488d9727566b07e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 30 Jan 2019 00:01:21 +0100 Subject: [PATCH] cleanup: Avoid implicit coercion Converting a variable to a particular type can be done explicitly (with functions like Number() or toString()) or implicitly by relying on type coercion (like concatenating a variable to the empty string to force a string, or multiplying it with 1 to force a number). As those tend to be less readable and clear, they are best avoided. So replace the cases of string coercion we use with template strings, and clarify the places that can be confused with number coercion. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/607 --- js/ui/barLevel.js | 6 +++--- js/ui/extensionSystem.js | 2 +- js/ui/lookingGlass.js | 2 +- js/ui/main.js | 2 +- js/ui/shellDBus.js | 2 +- js/ui/slider.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/js/ui/barLevel.js b/js/ui/barLevel.js index c4072e2cf..d2f961ce2 100644 --- a/js/ui/barLevel.js +++ b/js/ui/barLevel.js @@ -105,7 +105,7 @@ var BarLevel = class { overdriveSeparatorWidth = themeNode.get_length('-barlevel-overdrive-separator-width'); /* background bar */ - cr.arc(width - barLevelBorderRadius - barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * 3 / 4, TAU * 1 / 4); + cr.arc(width - barLevelBorderRadius - barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * (3 / 4), TAU * (1 / 4)); cr.lineTo(endX, (height + barLevelHeight) / 2); cr.lineTo(endX, (height - barLevelHeight) / 2); cr.lineTo(width - barLevelBorderRadius - barLevelBorderWidth, (height - barLevelHeight) / 2); @@ -117,7 +117,7 @@ var BarLevel = class { /* normal progress bar */ let x = Math.min(endX, overdriveSeparatorX - overdriveSeparatorWidth / 2); - cr.arc(barLevelBorderRadius + barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * 1 / 4, TAU * 3 / 4); + cr.arc(barLevelBorderRadius + barLevelBorderWidth, height / 2, barLevelBorderRadius, TAU * (1 / 4), TAU * (3 / 4)); cr.lineTo(x, (height - barLevelHeight) / 2); cr.lineTo(x, (height + barLevelHeight) / 2); cr.lineTo(barLevelBorderRadius + barLevelBorderWidth, (height + barLevelHeight) / 2); @@ -149,7 +149,7 @@ var BarLevel = class { Clutter.cairo_set_source_color(cr, barLevelActiveColor); else Clutter.cairo_set_source_color(cr, barLevelOverdriveColor); - cr.arc(endX, height / 2, barLevelBorderRadius, TAU * 3 / 4, TAU * 1 / 4); + cr.arc(endX, height / 2, barLevelBorderRadius, TAU * (3 / 4), TAU * (1 / 4)); cr.lineTo(Math.floor(endX), (height + barLevelHeight) / 2); cr.lineTo(Math.floor(endX), (height - barLevelHeight) / 2); cr.lineTo(endX, (height - barLevelHeight) / 2); diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 744f5e7ac..a53838d58 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -147,7 +147,7 @@ function logExtensionError(uuid, error) { if (!extension) return; - let message = '' + error; + let message = `${error}`; extension.state = ExtensionState.ERROR; if (!extension.errors) diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 3149cf421..edcfdecc8 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -242,7 +242,7 @@ function objectToString(o) { // special case this since the default is way, way too verbose return ''; } else { - return '' + o; + return `${o}`; } } diff --git a/js/ui/main.js b/js/ui/main.js index abd83721c..ea0a93984 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -658,7 +658,7 @@ function _queueBeforeRedraw(workId) { */ function initializeDeferredWork(actor, callback, props) { // Turn into a string so we can use as an object property - let workId = '' + (++_deferredWorkSequence); + let workId = `${(++_deferredWorkSequence)}`; _deferredWorkData[workId] = { 'actor': actor, 'callback': callback }; actor.connect('notify::mapped', () => { diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js index 19d07acce..a9224f841 100644 --- a/js/ui/shellDBus.js +++ b/js/ui/shellDBus.js @@ -65,7 +65,7 @@ var GnomeShell = class { returnValue = ''; success = true; } catch (e) { - returnValue = '' + e; + returnValue = `${e}`; success = false; } return [success, returnValue]; diff --git a/js/ui/slider.js b/js/ui/slider.js index 3c1b35e05..4025a11fd 100644 --- a/js/ui/slider.js +++ b/js/ui/slider.js @@ -142,7 +142,7 @@ var Slider = class extends BarLevel.BarLevel { if (direction == Clutter.ScrollDirection.DOWN) { delta = -SLIDER_SCROLL_STEP; } else if (direction == Clutter.ScrollDirection.UP) { - delta = +SLIDER_SCROLL_STEP; + delta = SLIDER_SCROLL_STEP; } else if (direction == Clutter.ScrollDirection.SMOOTH) { let [dx, dy] = event.get_scroll_delta(); // Even though the slider is horizontal, use dy to match