cleanup: Use object shorthand where possible

ES6 allows to omit property names where they match the name of the
assigned variable, which makes code less redunant and thus cleaner.
We will soon enforce that in our eslint rules, so make sure we use
the shorthand wherever possible.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
This commit is contained in:
Florian Müllner 2019-08-19 21:06:04 +02:00 committed by Georges Basile Stavracas Neto
parent 9eaa0089d0
commit c860409da5
40 changed files with 89 additions and 94 deletions

View File

@ -126,7 +126,7 @@ class Application extends Gtk.Application {
let buffer = new Gtk.TextBuffer({ text: errortext });
let textview = new Gtk.TextView({
buffer: buffer,
buffer,
wrap_mode: Gtk.WrapMode.WORD,
monospace: true,
editable: false,

View File

@ -64,7 +64,7 @@ var AuthPrompt = GObject.registerClass({
else if (this._mode == AuthPromptMode.UNLOCK_OR_LOG_IN)
reauthenticationOnly = false;
this._userVerifier = new GdmUtil.ShellUserVerifier(this._gdmClient, { reauthenticationOnly: reauthenticationOnly });
this._userVerifier = new GdmUtil.ShellUserVerifier(this._gdmClient, { reauthenticationOnly });
this._userVerifier.connect('ask-question', this._onAskQuestion.bind(this));
this._userVerifier.connect('show-message', this._onShowMessage.bind(this));

View File

@ -1134,8 +1134,7 @@ var LoginDialog = GObject.registerClass({
let userName = item.user.get_user_name();
let hold = new Batch.Hold();
this._authPrompt.begin({ userName: userName,
hold: hold });
this._authPrompt.begin({ userName, hold });
return hold;
}

View File

@ -272,7 +272,7 @@ var ShellUserVerifier = class {
let interval = this._getIntervalForMessage(message);
this.hasPendingMessages = true;
this._messageQueue.push({ text: message, type: messageType, interval: interval });
this._messageQueue.push({ text: message, type: messageType, interval });
this._queueMessageTimeout();
}

View File

@ -185,7 +185,7 @@ var LoginManagerSystemd = class {
try {
let [outVariant_, fdList] = proxy.call_with_unix_fd_list_finish(result);
fd = fdList.steal_fds()[0];
callback(new Gio.UnixInputStream({ fd: fd }));
callback(new Gio.UnixInputStream({ fd }));
} catch (e) {
logError(e, "Error getting systemd inhibitor");
callback(null);

View File

@ -121,8 +121,7 @@ function trySpawn(argv) {
// We are only interested in the part in the parentheses. (And
// we can't pattern match the text, since it gets localized.)
let message = err.message.replace(/.*\((.+)\)/, '$1');
throw new (err.constructor)({ code: err.code,
message: message });
throw new (err.constructor)({ code: err.code, message });
} else {
throw err;
}

View File

@ -92,7 +92,7 @@ class PortalHeaderBar extends Gtk.HeaderBar {
var PortalWindow = GObject.registerClass(
class PortalWindow extends Gtk.ApplicationWindow {
_init(application, url, timestamp, doneCallback) {
super._init({ application: application });
super._init({ application });
this.connect('delete-event', this.destroyWindow.bind(this));
this._headerBar = new PortalHeaderBar();
@ -287,7 +287,7 @@ class WebPortalHelper extends Gtk.Application {
}
Authenticate(connection, url, timestamp) {
this._queue.push({ connection: connection, url: url, timestamp: timestamp });
this._queue.push({ connection, url, timestamp });
this._processQueue();
}

View File

@ -415,7 +415,7 @@ class CyclerHighlight extends St.Widget {
this.add_actor(this._highlight);
let coordinate = Clutter.BindCoordinate.ALL;
let constraint = new Clutter.BindConstraint({ coordinate: coordinate });
let constraint = new Clutter.BindConstraint({ coordinate });
this._clone.bind_property('source', constraint, 'source', 0);
this.add_constraint(constraint);

View File

@ -10,7 +10,7 @@ var SPINNER_ANIMATION_DELAY = 1000;
var Animation = GObject.registerClass(
class Animation extends St.Bin {
_init(file, width, height, speed) {
super._init({ width: width, height: height });
super._init({ width, height });
this.connect('destroy', this._onDestroy.bind(this));
this.connect('resource-scale-changed',
this._loadFile.bind(this, file, width, height));

View File

@ -710,7 +710,7 @@ var AllView = GObject.registerClass({
else
opacity = 255;
this._items[id].ease({
opacity: opacity,
opacity,
duration: INACTIVE_GRID_OPACITY_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
@ -1029,14 +1029,14 @@ class AppDisplay extends St.BoxLayout {
style_class: 'app-view-control button',
can_focus: true,
x_expand: true });
this._views[Views.FREQUENT] = { 'view': view, 'control': button };
this._views[Views.FREQUENT] = { view, 'control': button };
view = new AllView();
button = new St.Button({ label: _("All"),
style_class: 'app-view-control button',
can_focus: true,
x_expand: true });
this._views[Views.ALL] = { 'view': view, 'control': button };
this._views[Views.ALL] = { view, 'control': button };
this._viewStackLayout = new ViewStackLayout();
this._viewStack = new St.Widget({ x_expand: true, y_expand: true,
@ -1472,7 +1472,7 @@ var FolderIcon = GObject.registerClass({
this._parentView = parentView;
this._folder = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders.folder',
path: path });
path });
this._delegate = this;
// whether we need to update arrow side, position etc.
this._popupInvalidated = false;

View File

@ -444,7 +444,7 @@ var Background = GObject.registerClass({
_loadAnimation(file) {
this._cache.getAnimation({
file: file,
file,
settingsSchema: this._settings.schema_id,
onLoaded: animation => {
this._animation = animation;
@ -592,11 +592,11 @@ var BackgroundSource = class BackgroundSource {
if (!(monitorIndex in this._backgrounds)) {
let background = new Background({
monitorIndex: monitorIndex,
monitorIndex,
layoutManager: this._layoutManager,
settings: this._settings,
file: file,
style: style
file,
style
});
background._changedId = background.connect('bg-changed', () => {

View File

@ -230,7 +230,7 @@ var AutomountManager = class {
let existingDialog = prevOperation ? prevOperation.borrowDialog() : null;
let operation =
new ShellMountOperation.ShellMountOperation(volume,
{ existingDialog: existingDialog });
{ existingDialog });
this._mountVolume(volume, operation);
}

View File

@ -56,7 +56,7 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
secret.entry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
text: secret.value, can_focus: reactive,
reactive: reactive,
reactive,
x_expand: true });
ShellEntry.addContextMenu(secret.entry,
{ isPassword: secret.password });
@ -553,7 +553,7 @@ var VPNRequestHandler = class {
contentOverride.secrets.push({
label: keyfile.get_string(groups[i], 'Label'),
key: groups[i],
value: value,
value,
password: keyfile.get_boolean(groups[i], 'IsSecret'),
});
} else {

View File

@ -49,10 +49,10 @@ function makeMessageFromTpMessage(tpMessage, direction) {
return {
messageType: tpMessage.get_message_type(),
text: text,
text,
sender: tpMessage.sender.alias,
timestamp: timestamp,
direction: direction
timestamp,
direction
};
}
@ -66,7 +66,7 @@ function makeMessageFromTplEvent(event) {
text: event.get_message(),
sender: event.get_sender().get_alias(),
timestamp: event.get_timestamp(),
direction: direction
direction
};
}
@ -350,7 +350,7 @@ class ChatSource extends MessageTray.Source {
getIcon() {
let file = this._contact.get_avatar_file();
if (file)
return new Gio.FileIcon({ file: file });
return new Gio.FileIcon({ file });
else
return new Gio.ThemedIcon({ name: 'avatar-default' });
}
@ -683,10 +683,10 @@ var ChatNotification = HAVE_TP ? GObject.registerClass({
? 'received' : 'sent');
this._append({ body: messageBody,
group: group,
styles: styles,
group,
styles,
timestamp: message.timestamp,
noTimestamp: noTimestamp });
noTimestamp });
}
_filterMessages() {

View File

@ -104,7 +104,7 @@ var CtrlAltTabManager = class CtrlAltTabManager {
Main.activateWindow(windows[i], timestamp);
},
iconActor: icon,
iconName: iconName,
iconName,
sortGroup: SortGroup.MIDDLE });
}
}

View File

@ -117,7 +117,7 @@ class Dialog extends St.Widget {
can_focus: true,
x_expand: true,
y_expand: true,
label: label });
label });
button.connect('clicked', action);
buttonInfo['button'] = button;

View File

@ -456,7 +456,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
this._confirm(signal);
});
},
label: label,
label,
});
}

View File

@ -19,7 +19,7 @@ var REPOSITORY_URL_UPDATE = `${REPOSITORY_URL_BASE}/update-info/`;
let _httpSession;
function installExtension(uuid, invocation) {
let params = { uuid: uuid,
let params = { uuid,
shell_version: Config.PACKAGE_VERSION };
let message = Soup.form_request_new_from_hash('GET', REPOSITORY_URL_INFO, params);

View File

@ -487,7 +487,7 @@ var IconGrid = GObject.registerClass({
scale_y: ANIMATION_BOUNCE_ICON_SCALE,
duration: bounceUpTime,
mode: Clutter.AnimationMode.EASE_IN_OUT_QUAD,
delay: delay,
delay,
onComplete: () => {
let duration = ANIMATION_TIME_IN - bounceUpTime;
actor.ease({

View File

@ -404,7 +404,7 @@ var Key = GObject.registerClass({
_makeKey(key) {
let label = GLib.markup_escape_text(key, -1);
let button = new St.Button({
label: label,
label,
style_class: 'keyboard-key',
x_expand: true,
});

View File

@ -445,7 +445,7 @@ var LayoutManager = GObject.registerClass({
_createBackgroundManager(monitorIndex) {
let bgManager = new Background.BackgroundManager({ container: this._backgroundGroup,
layoutManager: this,
monitorIndex: monitorIndex });
monitorIndex });
bgManager.connect('changed', this._addBackgroundMenu.bind(this));
this._addBackgroundMenu(bgManager);
@ -955,7 +955,7 @@ var LayoutManager = GObject.registerClass({
findIndexForActor(actor) {
let [x, y] = actor.get_transformed_position();
let [w, h] = actor.get_transformed_size();
let rect = new Meta.Rectangle({ x: x, y: y, width: w, height: h });
let rect = new Meta.Rectangle({ x, y, width: w, height: h });
return global.display.get_monitor_index_for_rect(rect);
}
@ -1026,7 +1026,7 @@ var LayoutManager = GObject.registerClass({
h = Math.round(h);
if (actorData.affectsInputRegion && wantsInputRegion && actorData.actor.get_paint_visibility())
rects.push(new Meta.Rectangle({ x: x, y: y, width: w, height: h }));
rects.push(new Meta.Rectangle({ x, y, width: w, height: h }));
let monitor = null;
if (actorData.affectsStruts)
@ -1077,7 +1077,7 @@ var LayoutManager = GObject.registerClass({
}
let strutRect = new Meta.Rectangle({ x: x1, y: y1, width: x2 - x1, height: y2 - y1 });
let strut = new Meta.Strut({ rect: strutRect, side: side });
let strut = new Meta.Strut({ rect: strutRect, side });
struts.push(strut);
}
}

View File

@ -86,12 +86,12 @@ var AutoComplete = class AutoComplete {
let currTime = global.get_current_time();
if ((currTime - this._lastTabTime) < AUTO_COMPLETE_DOUBLE_TAB_DELAY) {
this._processCompletionRequest({ tabType: 'double',
completions: completions,
attrHead: attrHead });
completions,
attrHead });
} else {
this._processCompletionRequest({ tabType: 'single',
completions: completions,
attrHead: attrHead });
completions,
attrHead });
}
this._lastTabTime = currTime;
}
@ -141,9 +141,9 @@ var Notebook = GObject.registerClass({
scrollview.get_hscroll_bar().hide();
scrollview.add_actor(child);
let tabData = { child: child,
labelBox: labelBox,
label: label,
let tabData = { child,
labelBox,
label,
scrollView: scrollview,
_scrollToBottom: false };
this._tabs.push(tabData);

View File

@ -858,8 +858,8 @@ var ZoomRegion = class ZoomRegion {
* of the magnified view.
*/
setMagFactor(xMagFactor, yMagFactor) {
this._changeROI({ xMagFactor: xMagFactor,
yMagFactor: yMagFactor,
this._changeROI({ xMagFactor,
yMagFactor,
redoCursorTracking: this._followingCursor });
}

View File

@ -490,11 +490,11 @@ function pushModal(actor, params) {
modalActorFocusStack[index].prevFocus = null;
});
}
modalActorFocusStack.push({ actor: actor,
modalActorFocusStack.push({ actor,
destroyId: actorDestroyId,
prevFocus: prevFocus,
prevFocusDestroyId: prevFocusDestroyId,
actionMode: actionMode });
prevFocus,
prevFocusDestroyId,
actionMode });
actionMode = params.actionMode;
global.stage.set_key_focus(actor);
@ -687,8 +687,8 @@ function _queueBeforeRedraw(workId) {
function initializeDeferredWork(actor, callback) {
// Turn into a string so we can use as an object property
let workId = `${(++_deferredWorkSequence)}`;
_deferredWorkData[workId] = { 'actor': actor,
'callback': callback };
_deferredWorkData[workId] = { actor,
callback };
actor.connect('notify::mapped', () => {
if (!(actor.mapped && _deferredWorkQueue.includes(workId)))
return;

View File

@ -435,7 +435,7 @@ var Notification = GObject.registerClass({
// @label: the label for the action's button
// @callback: the callback for the action
addAction(label, callback) {
this.actions.push({ label: label, callback: callback });
this.actions.push({ label, callback });
}
get acknowledged() {
@ -609,7 +609,7 @@ var NotificationBanner = GObject.registerClass({
addAction(label, callback) {
let button = new St.Button({ style_class: 'notification-button',
label: label,
label,
x_expand: true,
can_focus: true });
@ -750,7 +750,7 @@ var Source = GObject.registerClass({
}
}, class Source extends GObject.Object {
_init(title, iconName) {
super._init({ title: title });
super._init({ title });
this.SOURCE_ICON_SIZE = 48;

View File

@ -72,7 +72,7 @@ class MediaMessage extends MessageList.Message {
if (this._player.trackCoverUrl) {
let file = Gio.File.new_for_uri(this._player.trackCoverUrl);
this._icon.gicon = new Gio.FileIcon({ file: file });
this._icon.gicon = new Gio.FileIcon({ file });
this._icon.remove_style_class_name('fallback');
} else {
this._icon.icon_name = 'audio-x-generic-symbolic';

View File

@ -201,13 +201,13 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
hints['image-data'] = hints['icon_data'];
}
let ndata = { appName: appName,
icon: icon,
summary: summary,
body: body,
actions: actions,
hints: hints,
timeout: timeout };
let ndata = { appName,
icon,
summary,
body,
actions,
hints,
timeout };
if (replacesId != 0 && this._notifications[replacesId]) {
ndata.id = id = replacesId;
ndata.notification = this._notifications[replacesId].notification;
@ -299,7 +299,7 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
else if (!gicon)
gicon = this._fallbackIconForNotificationData(hints);
notification.update(summary, body, { gicon: gicon,
notification.update(summary, body, { gicon,
bannerMarkup: true,
clear: true,
soundFile: hints['sound-file'],

View File

@ -462,7 +462,7 @@ class ControlsManager extends St.Widget {
_updateWorkspacesGeometry() {
let [x, y] = this.get_transformed_position();
let [width, height] = this.get_transformed_size();
let geometry = { x: x, y: y, width: width, height: height };
let geometry = { x, y, width, height };
let spacing = this.get_theme_node().get_length('spacing');
let dashWidth = this._dashSlider.getVisibleWidth() + spacing;

View File

@ -57,8 +57,7 @@ function _unpremultiply(color) {
let red = Math.min((color.red * 255 + 127) / color.alpha, 255);
let green = Math.min((color.green * 255 + 127) / color.alpha, 255);
let blue = Math.min((color.blue * 255 + 127) / color.alpha, 255);
return new Clutter.Color({ red: red, green: green,
blue: blue, alpha: color.alpha });
return new Clutter.Color({ red, green, blue, alpha: color.alpha });
}
class AppMenu extends PopupMenu.PopupMenu {

View File

@ -269,7 +269,7 @@ class PopupMenuItem extends PopupBaseMenuItem {
_init(text, params) {
super._init(params);
this.label = new St.Label({ text: text });
this.label = new St.Label({ text });
this.add_child(this.label);
this.label_actor = this.label;
}
@ -330,7 +330,7 @@ var PopupSwitchMenuItem = GObject.registerClass({
_init(text, active, params) {
super._init(params);
this.label = new St.Label({ text: text });
this.label = new St.Label({ text });
this._switch = new Switch(active);
this.accessible_role = Atk.Role.CHECK_MENU_ITEM;
@ -416,7 +416,7 @@ class PopupImageMenuItem extends PopupBaseMenuItem {
this._icon = new St.Icon({ style_class: 'popup-menu-icon',
x_align: Clutter.ActorAlign.END });
this.add_child(this._icon);
this.label = new St.Label({ text: text });
this.label = new St.Label({ text });
this.add_child(this.label);
this.label_actor = this.label;
@ -1129,7 +1129,7 @@ class PopupSubMenuMenuItem extends PopupBaseMenuItem {
this.add_child(this.icon);
}
this.label = new St.Label({ text: text,
this.label = new St.Label({ text,
y_expand: true,
y_align: Clutter.ActorAlign.CENTER });
this.add_child(this.label);
@ -1251,7 +1251,7 @@ var PopupMenuManager = class {
return;
let menudata = {
menu: menu,
menu,
openStateChangeId: menu.connect('open-state-changed', this._onMenuOpenState.bind(this)),
destroyId: menu.connect('destroy', this._onMenuDestroy.bind(this)),
enterId: 0,

View File

@ -228,8 +228,7 @@ var RemoteSearchProvider = class {
}
if (gicon)
icon = new St.Icon({ gicon: gicon,
icon_size: size });
icon = new St.Icon({ gicon, icon_size: size });
return icon;
}

View File

@ -600,7 +600,7 @@ var ScreenShield = class {
height: monitor.height });
let bgManager = new Background.BackgroundManager({ container: widget,
monitorIndex: monitorIndex,
monitorIndex,
controlPosition: false,
settingsSchema: SCREENSAVER_SCHEMA });
@ -1026,8 +1026,7 @@ var ScreenShield = class {
});
} else {
this._lockScreenGroup.fixed_position_set = false;
this._lockScreenShown({ fadeToBlack: fadeToBlack,
animateFade: false });
this._lockScreenShown({ fadeToBlack, animateFade: false });
}
this._lockScreenGroup.grab_key_focus();

View File

@ -252,7 +252,7 @@ var ScreenshotService = class {
"Invalid params");
return;
}
let flashspot = new Flashspot({ x: x, y: y, width: width, height: height });
let flashspot = new Flashspot({ x, y, width, height });
flashspot.fire();
invocation.return_value(null);
}

View File

@ -233,7 +233,7 @@ var InputSourceSystemSettings = class extends InputSourceSettings {
let id = layouts[i];
if (variants[i])
id += `+${variants[i]}`;
sourcesList.push({ type: INPUT_SOURCE_TYPE_XKB, id: id });
sourcesList.push({ type: INPUT_SOURCE_TYPE_XKB, id });
}
return sourcesList;
}
@ -266,7 +266,7 @@ var InputSourceSessionSettings = class extends InputSourceSettings {
for (let i = 0; i < nSources; i++) {
let [type, id] = sources.get_child_value(i).deep_unpack();
sourcesList.push({ type: type, id: id });
sourcesList.push({ type, id });
}
return sourcesList;
}
@ -562,14 +562,14 @@ var InputSourceManager = class {
}
if (exists)
infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
infosList.push({ type, id, displayName, shortName });
}
if (infosList.length == 0) {
let type = INPUT_SOURCE_TYPE_XKB;
let id = KeyboardManager.DEFAULT_LAYOUT;
let [, displayName, shortName] = this._xkbInfo.get_layout_info(id);
infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
infosList.push({ type, id, displayName, shortName });
}
let inputSourcesByShortName = {};

View File

@ -1710,7 +1710,7 @@ class Indicator extends PanelMenu.SystemIndicator {
this._ensureSource();
let gicon = new Gio.ThemedIcon({ name: iconName });
this._notification = new MessageTray.Notification(this._source, title, text, { gicon: gicon });
this._notification = new MessageTray.Notification(this._source, title, text, { gicon });
this._notification.setUrgency(urgency);
this._notification.setTransient(true);
this._notification.connect('destroy', () => {

View File

@ -95,7 +95,7 @@ var UnlockDialog = GObject.registerClass({
userName = null;
}
this._authPrompt.begin({ userName: userName });
this._authPrompt.begin({ userName });
}
_escape() {

View File

@ -1466,7 +1466,7 @@ var WindowManager = class {
this._resizePending.add(actor);
actor.__animationInfo = { clone: actorClone,
oldRect: oldFrameRect,
destroyId: destroyId };
destroyId };
}
_sizeChangedWindow(shellwm, actor) {

View File

@ -1950,7 +1950,7 @@ class Workspace extends St.Widget {
if (numColumns == lastLayout.numColumns)
break;
let layout = { area: area, strategy: strategy, numRows: numRows, numColumns: numColumns };
let layout = { area, strategy, numRows, numColumns };
strategy.computeLayout(windows, layout);
strategy.computeScaleAndSpace(layout);

View File

@ -697,7 +697,7 @@ class WorkspacesDisplay extends St.Widget {
_getMonitorIndexForEvent(event) {
let [x, y] = event.get_coords();
let rect = new Meta.Rectangle({ x: x, y: y, width: 1, height: 1 });
let rect = new Meta.Rectangle({ x, y, width: 1, height: 1 });
return global.display.get_monitor_index_for_rect(rect);
}
@ -766,7 +766,7 @@ class WorkspacesDisplay extends St.Widget {
let allocation = this.allocation;
let width = allocation.x2 - allocation.x1;
let height = allocation.y2 - allocation.y1;
let primaryGeometry = { x: x, y: y, width: width, height: height };
let primaryGeometry = { x, y, width, height };
let monitors = Main.layoutManager.monitors;
for (let i = 0; i < monitors.length; i++) {

View File

@ -84,8 +84,8 @@ var XdndHandler = class {
Main.uiGroup.set_child_above_sibling(this._cursorWindowClone, null);
let dragEvent = {
x: x,
y: y,
x,
y,
dragActor: this._cursorWindowClone ? this._cursorWindowClone : this._dummy,
source: this,
targetActor: pickedActor