From 8a2b9abc09cc973cc215c0138cab6a4de8340085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sat, 26 Jan 2019 22:04:09 +0100 Subject: [PATCH] style: Stop using string concatenation String concatenation is considered bad style after ES6 added template strings. The latter is the replacement we generally want, except where the aforementioned xgettext bug would trip over the backtick/slash combination. https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/49 --- extensions/apps-menu/extension.js | 10 +++++----- extensions/auto-move-windows/prefs.js | 8 ++++---- extensions/places-menu/extension.js | 2 +- extensions/user-theme/extension.js | 4 ++-- extensions/window-list/prefs.js | 2 +- extensions/workspace-indicator/extension.js | 2 +- extensions/workspace-indicator/prefs.js | 2 +- lib/convenience.js | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js index 866bd9c7..a834330e 100644 --- a/extensions/apps-menu/extension.js +++ b/extensions/apps-menu/extension.js @@ -327,7 +327,7 @@ class DesktopTarget { try { o.set_attributes_finish(res); } catch (e) { - log('Failed to update access time: ' + e.message); + log(`Failed to update access time: ${e.message}`); } }); } @@ -354,7 +354,7 @@ class DesktopTarget { this._touchFile(file); }); } catch (e) { - log('Failed to mark file as trusted: ' + e.message); + log(`Failed to mark file as trusted: ${e.message}`); } }); } @@ -392,7 +392,7 @@ class DesktopTarget { src.copy(dst, Gio.FileCopyFlags.OVERWRITE, null, null); this._markTrusted(dst); } catch (e) { - log('Failed to copy to desktop: ' + e.message); + log(`Failed to copy to desktop: ${e.message}`); } return true; @@ -688,8 +688,8 @@ class ApplicationsButton extends PanelMenu.Button { let themeContext = St.ThemeContext.get_for_stage(global.stage); let scaleFactor = themeContext.scale_factor; let categoriesHeight = this.categoriesBox.height / scaleFactor; - let height = Math.round(categoriesHeight) + MENU_HEIGHT_OFFSET + 'px'; - this.mainBox.style+=('height: ' + height); + let height = Math.round(categoriesHeight) + MENU_HEIGHT_OFFSET; + this.mainBox.style += `height: ${height}px`; } selectCategory(dir) { diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js index 56f50e74..893cc6d5 100644 --- a/extensions/auto-move-windows/prefs.js +++ b/extensions/auto-move-windows/prefs.js @@ -216,12 +216,12 @@ const Widget = GObject.registerClass({ _checkId(id) { let items = this._settings.get_strv(SETTINGS_KEY); - return !items.some(i => i.startsWith(id + ':')); + return !items.some(i => i.startsWith(`${id}:`)); } _appendItem(id, workspace) { let currentItems = this._settings.get_strv(SETTINGS_KEY); - currentItems.push(id + ':' + workspace); + currentItems.push(`${id}:${workspace}`); this._settings.set_strv(SETTINGS_KEY, currentItems); } @@ -240,9 +240,9 @@ const Widget = GObject.registerClass({ let index = currentItems.map(el => el.split(':')[0]).indexOf(id); if (index < 0) - currentItems.push(id + ':' + workspace); + currentItems.push(`${id}:${workspace}`); else - currentItems[index] = id + ':' + workspace; + currentItems[index] = `${id}:${workspace}`; this._settings.set_strv(SETTINGS_KEY, currentItems); } }); diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js index e9e9914a..968a45ee 100644 --- a/extensions/places-menu/extension.js +++ b/extensions/places-menu/extension.js @@ -91,7 +91,7 @@ class PlacesMenu extends PanelMenu.Button { for (let i = 0; i < SECTIONS.length; i++) { let id = SECTIONS[i]; this._sections[id] = new PopupMenu.PopupMenuSection(); - this.placesManager.connect(id + '-updated', () => { + this.placesManager.connect(`${id}-updated`, () => { this._redisplay(id); }); diff --git a/extensions/user-theme/extension.js b/extensions/user-theme/extension.js index 24a34a71..9a0bd215 100644 --- a/extensions/user-theme/extension.js +++ b/extensions/user-theme/extension.js @@ -17,7 +17,7 @@ class ThemeManager { } enable() { - this._changedId = this._settings.connect('changed::'+SETTINGS_KEY, this._changeTheme.bind(this)); + this._changedId = this._settings.connect(`changed::${SETTINGS_KEY}`, this._changeTheme.bind(this)); this._changeTheme(); } @@ -59,7 +59,7 @@ class ThemeManager { } if (_stylesheet) - global.log('loading user theme: ' + _stylesheet); + global.log(`loading user theme: ${_stylesheet}`); else global.log('loading default theme (Adwaita)'); Main.setThemeStylesheet(_stylesheet); diff --git a/extensions/window-list/prefs.js b/extensions/window-list/prefs.js index 8cc90f12..f7bb3ee0 100644 --- a/extensions/window-list/prefs.js +++ b/extensions/window-list/prefs.js @@ -25,7 +25,7 @@ class WindowListPrefsWidget extends Gtk.Grid { this.row_spacing = 6; this.orientation = Gtk.Orientation.VERTICAL; - let groupingLabel = '' + _("Window Grouping") + ''; + let groupingLabel = '%s'.format(_("Window Grouping")); this.add(new Gtk.Label({ label: groupingLabel, use_markup: true, halign: Gtk.Align.START })); diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js index bd36b779..cdd841ba 100644 --- a/extensions/workspace-indicator/extension.js +++ b/extensions/workspace-indicator/extension.js @@ -53,7 +53,7 @@ class WorkspaceIndicator extends PanelMenu.Button { this._settings = new Gio.Settings({ schema_id: WORKSPACE_SCHEMA }); this._settingsChangedId = - this._settings.connect('changed::' + WORKSPACE_KEY, + this._settings.connect(`changed::${WORKSPACE_KEY}`, this._createWorkspacesSection.bind(this)); } diff --git a/extensions/workspace-indicator/prefs.js b/extensions/workspace-indicator/prefs.js index 73c44f80..3a70eaa7 100644 --- a/extensions/workspace-indicator/prefs.js +++ b/extensions/workspace-indicator/prefs.js @@ -130,7 +130,7 @@ class WorkspaceSettingsWidget extends Gtk.Grid { this.margin = 12; this.orientation = Gtk.Orientation.VERTICAL; - this.add(new Gtk.Label({ label: '' + _("Workspace Names") + '', + this.add(new Gtk.Label({ label: '%s'.format(_("Workspace Names")), use_markup: true, margin_bottom: 6, hexpand: true, halign: Gtk.Align.START })); diff --git a/lib/convenience.js b/lib/convenience.js index bbc86081..4775eddb 100644 --- a/lib/convenience.js +++ b/lib/convenience.js @@ -85,9 +85,9 @@ function getSettings(schema) { let schemaObj = schemaSource.lookup(schema, true); if (!schemaObj) - throw new Error('Schema ' + schema + ' could not be found for extension ' - + extension.metadata.uuid + '. Please check your installation.'); + throw new Error( + `Schema ${schema} could not be found for extension ${extension.metadata.uuid}. Please check your installation.` + ); return new Gio.Settings({ settings_schema: schemaObj }); } -