cleanup: Use consistent style for ternary operator

We are currently inconsistent whether to put the operators in front
of the corresponding line or at the end of the preceding one. The
most dominant style for now is to put condition and first branch on
the same line, and then align the second branch:

  let foo = condition ? fooValue
                      : notFooValue;

Unfortunately that's a style that eslint doesn't support, so to account
for it, our legacy configuration currently plainly ignores all indentation
in conditionals.

In order to drop that exception and not let messed up indentation slip
through, change all ternary operators to the non-legacy style.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/725
This commit is contained in:
Florian Müllner 2019-08-19 21:33:15 +02:00 committed by Florian Müllner
parent 4bfb4a0e3d
commit af87bd8c87
25 changed files with 101 additions and 80 deletions

View File

@ -244,7 +244,8 @@ const SystemActions = GObject.registerClass({
_updateOrientationLockIcon() { _updateOrientationLockIcon() {
let locked = this._orientationSettings.get_boolean('orientation-lock'); let locked = this._orientationSettings.get_boolean('orientation-lock');
let iconName = locked ? 'rotation-locked-symbolic' let iconName = locked
? 'rotation-locked-symbolic'
: 'rotation-allowed-symbolic'; : 'rotation-allowed-symbolic';
this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName = iconName; this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName = iconName;

View File

@ -437,8 +437,8 @@ class CyclerHighlight {
if (this._clone.source) if (this._clone.source)
this._clone.source.sync_visibility(); this._clone.source.sync_visibility();
let windowActor = this._window ? this._window.get_compositor_private() let windowActor = this._window
: null; ? this._window.get_compositor_private() : null;
if (windowActor) if (windowActor)
windowActor.hide(); windowActor.hide();
@ -1014,9 +1014,9 @@ class WindowIcon extends St.BoxLayout {
} }
_createAppIcon(app, size) { _createAppIcon(app, size) {
let appIcon = app ? app.create_icon_texture(size) let appIcon = app
: new St.Icon({ icon_name: 'icon-missing', ? app.create_icon_texture(size)
icon_size: size }); : new St.Icon({ icon_name: 'icon-missing', icon_size: size });
appIcon.x_expand = appIcon.y_expand = true; appIcon.x_expand = appIcon.y_expand = true;
appIcon.x_align = appIcon.y_align = Clutter.ActorAlign.END; appIcon.x_align = appIcon.y_align = Clutter.ActorAlign.END;

View File

@ -1107,8 +1107,9 @@ var AppDisplay = class AppDisplay {
else else
this._views[i].control.remove_style_pseudo_class('checked'); this._views[i].control.remove_style_pseudo_class('checked');
let animationDirection = i == activeIndex ? IconGrid.AnimationDirection.IN : let animationDirection = i == activeIndex
IconGrid.AnimationDirection.OUT; ? IconGrid.AnimationDirection.IN
: IconGrid.AnimationDirection.OUT;
this._views[i].view.animateSwitch(animationDirection); this._views[i].view.animateSwitch(animationDirection);
} }
} }
@ -2398,8 +2399,8 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
); );
windows.forEach(window => { windows.forEach(window => {
let title = window.title ? window.title let title = window.title
: this._source.app.get_name(); ? window.title : this._source.app.get_name();
let item = this._appendMenuItem(title); let item = this._appendMenuItem(title);
item.connect('activate', () => { item.connect('activate', () => {
this.emit('activate-window', window); this.emit('activate-window', window);

View File

@ -581,7 +581,8 @@ var Calendar = class Calendar {
if (row == 2) if (row == 2)
styleClass = `calendar-day-top ${styleClass}`; styleClass = `calendar-day-top ${styleClass}`;
let leftMost = rtl ? iter.getDay() == (this._weekStart + 6) % 7 let leftMost = rtl
? iter.getDay() == (this._weekStart + 6) % 7
: iter.getDay() == this._weekStart; : iter.getDay() == this._weekStart;
if (leftMost) if (leftMost)
styleClass = `calendar-day-left ${styleClass}`; styleClass = `calendar-day-left ${styleClass}`;
@ -680,7 +681,8 @@ var EventMessage = class EventMessage extends MessageList.Message {
*/ */
title = C_("event list time", "All Day"); title = C_("event list time", "All Day");
} else { } else {
let date = this._event.date >= periodBegin ? this._event.date let date = this._event.date >= periodBegin
? this._event.date
: this._event.end; : this._event.end;
title = Util.formatTime(date, { timeOnly: true }); title = Util.formatTime(date, { timeOnly: true });
} }

View File

@ -232,7 +232,8 @@ var KeyringPrompter = class {
constructor() { constructor() {
this._prompter = new Gcr.SystemPrompter(); this._prompter = new Gcr.SystemPrompter();
this._prompter.connect('new-prompt', () => { this._prompter.connect('new-prompt', () => {
let dialog = this._enabled ? new KeyringDialog() let dialog = this._enabled
? new KeyringDialog()
: new KeyringDummyDialog(); : new KeyringDummyDialog();
this._currentPrompt = dialog.prompt; this._currentPrompt = dialog.prompt;
return this._currentPrompt; return this._currentPrompt;

View File

@ -673,8 +673,8 @@ var ChatNotification = class extends MessageTray.Notification {
{ datetime: GLib.DateTime.new_from_unix_local (message.timestamp), { datetime: GLib.DateTime.new_from_unix_local (message.timestamp),
bannerMarkup: true }); bannerMarkup: true });
let group = (message.direction == NotificationDirection.RECEIVED ? let group = (message.direction == NotificationDirection.RECEIVED
'received' : 'sent'); ? 'received' : 'sent');
this._append({ body: messageBody, this._append({ body: messageBody,
group: group, group: group,
@ -696,8 +696,8 @@ var ChatNotification = class extends MessageTray.Notification {
// SCROLLBACK_RECENT_LENGTH previous messages. Otherwise // SCROLLBACK_RECENT_LENGTH previous messages. Otherwise
// we'll keep SCROLLBACK_IDLE_LENGTH messages. // we'll keep SCROLLBACK_IDLE_LENGTH messages.
let maxLength = (lastMessageTime < currentTime - SCROLLBACK_RECENT_TIME) ? let maxLength = (lastMessageTime < currentTime - SCROLLBACK_RECENT_TIME)
SCROLLBACK_IDLE_LENGTH : SCROLLBACK_RECENT_LENGTH; ? SCROLLBACK_IDLE_LENGTH : SCROLLBACK_RECENT_LENGTH;
let filteredHistory = this.messages.filter(item => item.realMessage); let filteredHistory = this.messages.filter(item => item.realMessage);
if (filteredHistory.length > maxLength) { if (filteredHistory.length > maxLength) {

View File

@ -703,8 +703,8 @@ var Dash = class Dash {
} }
// App moved // App moved
let nextApp = newApps.length > newIndex + 1 ? newApps[newIndex + 1] let nextApp = newApps.length > newIndex + 1
: null; ? newApps[newIndex + 1] : null;
let insertHere = nextApp && nextApp == oldApp; let insertHere = nextApp && nextApp == oldApp;
let alreadyRemoved = removedActors.reduce((result, actor) => { let alreadyRemoved = removedActors.reduce((result, actor) => {
let removedApp = actor.child._delegate.app; let removedApp = actor.child._delegate.app;

View File

@ -148,7 +148,8 @@ var WorldClocksSection = class WorldClocksSection {
}); });
let layout = this._grid.layout_manager; let layout = this._grid.layout_manager;
let title = (this._locations.length == 0) ? _("Add world clocks…") let title = (this._locations.length == 0)
? _("Add world clocks…")
: _("World Clocks"); : _("World Clocks");
let header = new St.Label({ style_class: 'world-clocks-header', let header = new St.Label({ style_class: 'world-clocks-header',
x_align: Clutter.ActorAlign.START, x_align: Clutter.ActorAlign.START,

View File

@ -273,8 +273,8 @@ var IconGrid = GObject.registerClass({
return [0, 0]; return [0, 0];
let nChildren = this.get_n_children(); let nChildren = this.get_n_children();
let nColumns = this._colLimit ? Math.min(this._colLimit, let nColumns = this._colLimit
nChildren) ? Math.min(this._colLimit, nChildren)
: nChildren; : nChildren;
let totalSpacing = Math.max(0, nColumns - 1) * this._getSpacing(); let totalSpacing = Math.max(0, nColumns - 1) * this._getSpacing();
// Kind of a lie, but not really an issue right now. If // Kind of a lie, but not really an issue right now. If
@ -787,7 +787,8 @@ var IconGrid = GObject.registerClass({
let neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth; let neededWidth = this.usedWidthForNColumns(this._minColumns) - availWidth;
let neededHeight = this.usedHeightForNRows(this._minRows) - availHeight; let neededHeight = this.usedHeightForNRows(this._minRows) - availHeight;
let neededSpacePerItem = (neededWidth > neededHeight) ? Math.ceil(neededWidth / this._minColumns) let neededSpacePerItem = (neededWidth > neededHeight)
? Math.ceil(neededWidth / this._minColumns)
: Math.ceil(neededHeight / this._minRows); : Math.ceil(neededHeight / this._minRows);
this._fixedHItemSize = Math.max(this._hItemSize - neededSpacePerItem, MIN_ICON_SIZE); this._fixedHItemSize = Math.max(this._hItemSize - neededSpacePerItem, MIN_ICON_SIZE);
this._fixedVItemSize = Math.max(this._vItemSize - neededSpacePerItem, MIN_ICON_SIZE); this._fixedVItemSize = Math.max(this._vItemSize - neededSpacePerItem, MIN_ICON_SIZE);
@ -963,8 +964,7 @@ var PaginatedIconGrid = GObject.registerClass({
let childrenPerRow = this._childrenPerPage / this._rowsPerPage; let childrenPerRow = this._childrenPerPage / this._rowsPerPage;
let sourceRow = Math.floor((index - pageOffset) / childrenPerRow); let sourceRow = Math.floor((index - pageOffset) / childrenPerRow);
let nRowsAbove = (side == St.Side.TOP) ? sourceRow + 1 let nRowsAbove = (side == St.Side.TOP) ? sourceRow + 1 : sourceRow;
: sourceRow;
let nRowsBelow = this._rowsPerPage - nRowsAbove; let nRowsBelow = this._rowsPerPage - nRowsAbove;
let nRowsUp, nRowsDown; let nRowsUp, nRowsDown;

View File

@ -76,7 +76,8 @@ var InhibitShortcutsDialog = GObject.registerClass({
let name = this._app ? this._app.get_name() : this._window.title; let name = this._app ? this._app.get_name() : this._window.title;
/* Translators: %s is an application name like "Settings" */ /* Translators: %s is an application name like "Settings" */
let title = name ? _("%s wants to inhibit shortcuts").format(name) let title = name
? _("%s wants to inhibit shortcuts").format(name)
: _("Application wants to inhibit shortcuts"); : _("Application wants to inhibit shortcuts");
let icon = new Gio.ThemedIcon({ name: 'dialog-warning-symbolic' }); let icon = new Gio.ThemedIcon({ name: 'dialog-warning-symbolic' });

View File

@ -771,8 +771,7 @@ var LayoutManager = GObject.registerClass({
this.keyboardBox.ease({ this.keyboardBox.ease({
anchor_y: 0, anchor_y: 0,
opacity: 0, opacity: 0,
duration: immediate ? 0 duration: immediate ? 0 : KEYBOARD_ANIMATION_TIME,
: KEYBOARD_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_IN_QUAD, mode: Clutter.AnimationMode.EASE_IN_QUAD,
onComplete: () => { onComplete: () => {
this._hideKeyboardComplete(); this._hideKeyboardComplete();
@ -856,7 +855,8 @@ var LayoutManager = GObject.registerClass({
index = this._findActor(ancestor); index = this._findActor(ancestor);
} }
let ancestorData = ancestor ? this._trackedActors[index] let ancestorData = ancestor
? this._trackedActors[index]
: defaultParams; : defaultParams;
// We can't use Params.parse here because we want to drop // We can't use Params.parse here because we want to drop
// the extra values like ancestorData.actor // the extra values like ancestorData.actor

View File

@ -735,7 +735,8 @@ var Source = class Source {
} }
get narrowestPrivacyScope() { get narrowestPrivacyScope() {
return this.notifications.every(n => n.privacyScope == PrivacyScope.SYSTEM) ? PrivacyScope.SYSTEM return this.notifications.every(n => n.privacyScope == PrivacyScope.SYSTEM)
? PrivacyScope.SYSTEM
: PrivacyScope.USER; : PrivacyScope.USER;
} }

View File

@ -71,7 +71,8 @@ var MediaMessage = class MediaMessage extends MessageList.Message {
} }
let isPlaying = this._player.status == 'Playing'; let isPlaying = this._player.status == 'Playing';
let iconName = isPlaying ? 'media-playback-pause-symbolic' let iconName = isPlaying
? 'media-playback-pause-symbolic'
: 'media-playback-start-symbolic'; : 'media-playback-start-symbolic';
this._playPauseButton.child.icon_name = iconName; this._playPauseButton.child.icon_name = iconName;

View File

@ -346,7 +346,8 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
notification.setTransient(!!hints['transient']); notification.setTransient(!!hints['transient']);
let privacyScope = (hints['x-gnome-privacy-scope'] || 'user'); let privacyScope = (hints['x-gnome-privacy-scope'] || 'user');
notification.setPrivacyScope(privacyScope == 'system' ? MessageTray.PrivacyScope.SYSTEM notification.setPrivacyScope(privacyScope == 'system'
? MessageTray.PrivacyScope.SYSTEM
: MessageTray.PrivacyScope.USER); : MessageTray.PrivacyScope.USER);
let sourceGIcon = source.useNotificationIcon ? gicon : null; let sourceGIcon = source.useNotificationIcon ? gicon : null;
@ -554,7 +555,8 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
let urgency = PRIORITY_URGENCY_MAP[priority.unpack()]; let urgency = PRIORITY_URGENCY_MAP[priority.unpack()];
this.setUrgency(urgency != undefined ? urgency : MessageTray.Urgency.NORMAL); this.setUrgency(urgency != undefined ? urgency : MessageTray.Urgency.NORMAL);
} else if (urgent) { } else if (urgent) {
this.setUrgency(urgent.unpack() ? MessageTray.Urgency.CRITICAL this.setUrgency(urgent.unpack()
? MessageTray.Urgency.CRITICAL
: MessageTray.Urgency.NORMAL); : MessageTray.Urgency.NORMAL);
} else { } else {
this.setUrgency(MessageTray.Urgency.NORMAL); this.setUrgency(MessageTray.Urgency.NORMAL);

View File

@ -14,8 +14,8 @@ var SIDE_CONTROLS_ANIMATION_TIME = 160;
function getRtlSlideDirection(direction, actor) { function getRtlSlideDirection(direction, actor) {
let rtl = (actor.text_direction == Clutter.TextDirection.RTL); let rtl = (actor.text_direction == Clutter.TextDirection.RTL);
if (rtl) if (rtl)
direction = (direction == SlideDirection.LEFT) ? direction = (direction == SlideDirection.LEFT)
SlideDirection.RIGHT : SlideDirection.LEFT; ? SlideDirection.RIGHT : SlideDirection.LEFT;
return direction; return direction;
} }
@ -67,8 +67,9 @@ var SlideLayout = GObject.registerClass({
// flags only determine what to do if the allocated box is bigger // flags only determine what to do if the allocated box is bigger
// than the actor's box. // than the actor's box.
let realDirection = getRtlSlideDirection(this._direction, child); let realDirection = getRtlSlideDirection(this._direction, child);
let alignX = (realDirection == SlideDirection.LEFT) ? (availWidth - natWidth) let alignX = (realDirection == SlideDirection.LEFT)
: (availWidth - natWidth * this._slideX); ? availWidth - natWidth
: availWidth - natWidth * this._slideX;
let actorBox = new Clutter.ActorBox(); let actorBox = new Clutter.ActorBox();
actorBox.x1 = box.x1 + alignX + this._translationX; actorBox.x1 = box.x1 + alignX + this._translationX;

View File

@ -126,12 +126,14 @@ class AnimatedPageIndicators extends PageIndicators {
offset = children[0].width; offset = children[0].width;
let isAnimationIn = animationDirection == AnimationDirection.IN; let isAnimationIn = animationDirection == AnimationDirection.IN;
let delay = isAnimationIn ? INDICATORS_ANIMATION_DELAY : let delay = isAnimationIn
INDICATORS_ANIMATION_DELAY_OUT; ? INDICATORS_ANIMATION_DELAY
: INDICATORS_ANIMATION_DELAY_OUT;
let baseTime = isAnimationIn ? INDICATORS_BASE_TIME : INDICATORS_BASE_TIME_OUT; let baseTime = isAnimationIn ? INDICATORS_BASE_TIME : INDICATORS_BASE_TIME_OUT;
let totalAnimationTime = baseTime + delay * this._nPages; let totalAnimationTime = baseTime + delay * this._nPages;
let maxTime = isAnimationIn ? INDICATORS_ANIMATION_MAX_TIME : let maxTime = isAnimationIn
INDICATORS_ANIMATION_MAX_TIME_OUT; ? INDICATORS_ANIMATION_MAX_TIME
: INDICATORS_ANIMATION_MAX_TIME_OUT;
if (totalAnimationTime > maxTime) if (totalAnimationTime > maxTime)
delay -= (totalAnimationTime - maxTime) / this._nPages; delay -= (totalAnimationTime - maxTime) / this._nPages;

View File

@ -1306,7 +1306,8 @@ var PopupMenuManager = class {
} }
_changeMenu(newMenu) { _changeMenu(newMenu) {
newMenu.open(this.activeMenu ? BoxPointer.PopupAnimation.FADE newMenu.open(this.activeMenu
? BoxPointer.PopupAnimation.FADE
: BoxPointer.PopupAnimation.FULL); : BoxPointer.PopupAnimation.FULL);
} }

View File

@ -173,7 +173,8 @@ var NotificationsBox = class {
let body = ''; let body = '';
if (n.bannerBodyText) { if (n.bannerBodyText) {
body = n.bannerBodyMarkup ? n.bannerBodyText body = n.bannerBodyMarkup
? n.bannerBodyText
: GLib.markup_escape_text(n.bannerBodyText, -1); : GLib.markup_escape_text(n.bannerBodyText, -1);
} }

View File

@ -710,7 +710,8 @@ var SearchResults = class {
navigateFocus(direction) { navigateFocus(direction) {
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL; let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
if (direction == St.DirectionType.TAB_BACKWARD || if (direction == St.DirectionType.TAB_BACKWARD ||
direction == (rtl ? St.DirectionType.RIGHT direction == (rtl
? St.DirectionType.RIGHT
: St.DirectionType.LEFT) || : St.DirectionType.LEFT) ||
direction == St.DirectionType.UP) { direction == St.DirectionType.UP) {
this.actor.navigate_focus(null, direction, false); this.actor.navigate_focus(null, direction, false);

View File

@ -92,10 +92,10 @@ const _modes = {
isLocked: false, isLocked: false,
isPrimary: true, isPrimary: true,
unlockDialog: imports.ui.unlockDialog.UnlockDialog, unlockDialog: imports.ui.unlockDialog.UnlockDialog,
components: Config.HAVE_NETWORKMANAGER ? components: Config.HAVE_NETWORKMANAGER
['networkAgent', 'polkitAgent', 'telepathyClient', ? ['networkAgent', 'polkitAgent', 'telepathyClient',
'keyring', 'autorunManager', 'automountManager'] : 'keyring', 'autorunManager', 'automountManager']
['polkitAgent', 'telepathyClient', : ['polkitAgent', 'telepathyClient',
'keyring', 'autorunManager', 'automountManager'], 'keyring', 'autorunManager', 'automountManager'],
panel: { panel: {

View File

@ -976,8 +976,8 @@ class InputSourceIndicator extends PanelMenu.Button {
item.prop = prop; item.prop = prop;
radioGroup.push(item); radioGroup.push(item);
item.radioGroup = radioGroup; item.radioGroup = radioGroup;
item.setOrnament(prop.get_state() == IBus.PropState.CHECKED ? item.setOrnament(prop.get_state() == IBus.PropState.CHECKED
PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE); ? PopupMenu.Ornament.DOT : PopupMenu.Ornament.NONE);
item.connect('activate', () => { item.connect('activate', () => {
if (item.prop.get_state() == IBus.PropState.CHECKED) if (item.prop.get_state() == IBus.PropState.CHECKED)
return; return;

View File

@ -168,7 +168,8 @@ var Indicator = class extends PanelMenu.SystemIndicator {
_updateMenuLabels() { _updateMenuLabels() {
if (this._settings.get_boolean(ENABLED)) { if (this._settings.get_boolean(ENABLED)) {
this._item.label.text = this._indicator.visible ? _("Location In Use") this._item.label.text = this._indicator.visible
? _("Location In Use")
: _("Location Enabled"); : _("Location Enabled");
this._onOffAction.label.text = _("Disable"); this._onOffAction.label.text = _("Disable");
} else { } else {

View File

@ -58,9 +58,11 @@ var Indicator = class extends PanelMenu.SystemIndicator {
let visible = this._proxy.NightLightActive; let visible = this._proxy.NightLightActive;
let disabled = this._proxy.DisabledUntilTomorrow; let disabled = this._proxy.DisabledUntilTomorrow;
this._item.label.text = disabled ? _("Night Light Disabled") this._item.label.text = disabled
? _("Night Light Disabled")
: _("Night Light On"); : _("Night Light On");
this._disableItem.label.text = disabled ? _("Resume") this._disableItem.label.text = disabled
? _("Resume")
: _("Disable Until Tomorrow"); : _("Disable Until Tomorrow");
this._item.visible = this._indicator.visible = visible; this._item.visible = this._indicator.visible = visible;
} }

View File

@ -228,9 +228,9 @@ var OutputStreamSlider = class extends StreamSlider {
} }
_updateSliderIcon() { _updateSliderIcon() {
this._icon.icon_name = (this._hasHeadphones ? this._icon.icon_name = (this._hasHeadphones
'audio-headphones-symbolic' : ? 'audio-headphones-symbolic'
'audio-speakers-symbolic'); : 'audio-speakers-symbolic');
} }
_portChanged() { _portChanged() {

View File

@ -389,8 +389,8 @@ var ViewSelector = class {
} }
_onShowAppsButtonToggled() { _onShowAppsButtonToggled() {
this._showPage(this._showAppsButton.checked ? this._showPage(this._showAppsButton.checked
this._appsPage : this._workspacesPage); ? this._appsPage : this._workspacesPage);
} }
_onStageKeyPress(actor, event) { _onStageKeyPress(actor, event) {
@ -424,7 +424,8 @@ var ViewSelector = class {
} }
_searchCancelled() { _searchCancelled() {
this._showPage(this._showAppsButton.checked ? this._appsPage this._showPage(this._showAppsButton.checked
? this._appsPage
: this._workspacesPage); : this._workspacesPage);
// Leave the entry focused when it doesn't have any text; // Leave the entry focused when it doesn't have any text;