[polari] style: Only omit braces for single-line statements



commit df41fc06393f65db906ebb5d3e5a4c6b1097f4ed
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Apr 4 04:04:12 2019 +0200

    style: Only omit braces for single-line statements
    
    We currently omit braces if all blocks consist of a single statement,
    but the statement itself may still be spread over multiple lines.
    In some places we are stretching it, but in general it's fine. Except
    that if we want to automate the rule, eslint forces us to pick between
    single-statement without, and single-line with nested handling.
    
    https://gitlab.gnome.org/GNOME/polari/merge_requests/108

 src/accountsMonitor.js   |  3 ++-
 src/application.js       | 11 +++++++----
 src/chatView.js          | 18 ++++++++++++------
 src/entryArea.js         |  5 +++--
 src/initialSetup.js      |  5 +++--
 src/ircParser.js         |  7 ++++---
 src/joinDialog.js        |  3 ++-
 src/mainWindow.js        |  3 ++-
 src/pasteManager.js      |  7 ++++---
 src/roomList.js          |  8 +++++---
 src/serverRoomManager.js |  3 ++-
 src/telepathyClient.js   |  8 +++++---
 src/userList.js          | 25 ++++++++++++++++---------
 src/utils.js             |  3 ++-
 14 files changed, 69 insertions(+), 40 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index a2bd730..57b5847 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -16,9 +16,10 @@ var AccountsMonitor = class {
 
         this._app = Gio.Application.get_default();
 
-        if (!this._app.isTestInstance)
+        if (!this._app.isTestInstance) {
             this._app.connect('prepare-shutdown',
                               this._onPrepareShutdown.bind(this));
+        }
 
         let factory = new ClientFactory();
         factory.add_channel_features([Tp.Channel.get_feature_quark_group()]);
diff --git a/src/application.js b/src/application.js
index 2945f18..7297a40 100644
--- a/src/application.js
+++ b/src/application.js
@@ -285,9 +285,10 @@ var Application = GObject.registerClass({
                 action.connect('activate', actionEntry.activate);
             if (actionEntry.change_state)
                 action.connect('change-state', actionEntry.change_state);
-            if (actionEntry.accels)
+            if (actionEntry.accels) {
                 this.set_accels_for_action(`app.${actionEntry.name}`,
                                            actionEntry.accels);
+            }
             this.add_action(action);
         });
 
@@ -438,17 +439,19 @@ var Application = GObject.registerClass({
                        map[a].service == matchedId;
             });
 
-            if (matches.length)
+            if (matches.length) {
                 joinAction.activate(new GLib.Variant('(ssu)',
                                                      [matches[0], `#${room}`, time]));
-            else
+            } else {
                 this._createAccount(matchedId, server, port, a => {
-                    if (a)
+                    if (a) {
                         joinAction.activate(new GLib.Variant('(ssu)', [
                             a.get_object_path(),
                             `#${room}`, time
                         ]));
+                    }
                 });
+            }
         });
     }
 
diff --git a/src/chatView.js b/src/chatView.js
index 858a39d..36855b3 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -546,9 +546,10 @@ var ChatView = GObject.registerClass({
             GLib.source_remove(this._backlogTimeoutId);
         this._backlogTimeoutId = 0;
 
-        if (this._nickStatusChangedId)
+        if (this._nickStatusChangedId) {
             this._userTracker.unwatchRoomStatus(this._room,
                                                 this._nickStatusChangedId);
+        }
         this._nickStatusChangedId = 0;
         this._userTracker = null;
 
@@ -1095,12 +1096,14 @@ var ChatView = GObject.registerClass({
         }
 
         let stats = [];
-        if (this._statusCount.joined > 0)
+        if (this._statusCount.joined > 0) {
             stats.push(ngettext('%d user joined',
                                 '%d users joined', 
this._statusCount.joined).format(this._statusCount.joined));
-        if (this._statusCount.left > 0)
+        }
+        if (this._statusCount.left > 0) {
             stats.push(ngettext('%d user left',
                                 '%d users left', this._statusCount.left).format(this._statusCount.left));
+        }
         // TODO: How do we update the arrow direction when text direction change?
         let iter = buffer.get_iter_at_mark(headerMark);
         let tags = [this._lookupTag('status'), headerTag];
@@ -1333,18 +1336,20 @@ var ChatView = GObject.registerClass({
         }
         this._insertWithTags(iter, text.substr(pos), tags);
 
-        if (highlight && message.pendingId)
+        if (highlight && message.pendingId) {
             this._pending.set(message.pendingId,
                               this._view.buffer.create_mark(null, iter, true));
+        }
     }
 
     _onNickStatusChanged(baseNick, status) {
         if (this._room.type == Tp.HandleType.CONTACT &&
             status == Tp.ConnectionPresenceType.OFFLINE &&
-            this._room.channel)
+            this._room.channel) {
             this._room.channel.ack_all_pending_messages_async(channel => {
                 channel.close_async(null);
             });
+        }
 
         let nickTagName = this._getNickTagName(baseNick);
         let nickTag = this._lookupTag(nickTagName);
@@ -1388,12 +1393,13 @@ var ChatView = GObject.registerClass({
 
         let actualNickName = view.get_buffer().get_slice(start, end, false);
 
-        if (!tag._popover)
+        if (!tag._popover) {
             tag._popover = new UserPopover({
                 relative_to: this._view,
                 userTracker: this._userTracker,
                 room: this._room
             });
+        }
 
         tag._popover.nickname = actualNickName;
 
diff --git a/src/entryArea.js b/src/entryArea.js
index 5d225fe..1dbbc00 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -446,12 +446,13 @@ var EntryArea = GObject.registerClass({
     _onChannelChanged(room) {
         this._updateCompletions();
 
-        if (room.channel)
+        if (room.channel) {
             this._selfAliasChangedId =
                 room.channel.connection.connect('notify::self-contact',
                                                 this._updateNick.bind(this));
-        else
+        } else {
             this._selfAliasChangedId = 0;
+        }
         this._updateNick();
     }
 
diff --git a/src/initialSetup.js b/src/initialSetup.js
index b3389ca..cb1e036 100644
--- a/src/initialSetup.js
+++ b/src/initialSetup.js
@@ -64,11 +64,12 @@ var InitialSetupWindow = GObject.registerClass({
     }
 
     _onNetworkAvailableChanged() {
-        if (this._networkMonitor.network_available)
+        if (this._networkMonitor.network_available) {
             this._setPage(this._currentAccount ?
                 SetupPage.ROOM : SetupPage.CONNECTION);
-        else
+        } else {
             this._setPage(SetupPage.OFFLINE);
+        }
     }
 
     _setPage(page) {
diff --git a/src/ircParser.js b/src/ircParser.js
index 4212472..83cdc85 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -81,13 +81,14 @@ var IrcParser = class {
 
             retval = (command == null || knownCommands[command] != null);
 
-            if (!retval) //error
+            if (!retval) {
                 output = this._createFeedbackLabel(_(UNKNOWN_COMMAND_MESSAGE));
-            else if (command)
+            } else if (command) {
                 output = this._createFeedbackUsage(command);
-            else
+            } else {
                 output = this._createFeedbackGrid(_('Known commands:'),
                                                   Object.keys(knownCommands));
+            }
             break;
         }
         case 'INVITE': {
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 3fd796f..17613ac 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -203,9 +203,10 @@ var JoinDialog = GObject.registerClass({
     _updateCanJoin() {
         let sensitive = false;
 
-        if (this._page == DialogPage.MAIN)
+        if (this._page == DialogPage.MAIN) {
             sensitive = this._connectionCombo.get_active() > -1  &&
                         this._serverRoomList.can_join;
+        }
 
         this._joinButton.sensitive = sensitive;
         this.set_default_response(sensitive ?
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a64d97a..c52f25d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -228,11 +228,12 @@ var MainWindow = GObject.registerClass({
                                  GLib.Variant.new('ai', this._currentSize));
 
         let serializedChannel = null;
-        if (this._lastActiveRoom)
+        if (this._lastActiveRoom) {
             serializedChannel = new GLib.Variant('a{sv}', {
                 account: new GLib.Variant('s', this._lastActiveRoom.account.object_path),
                 channel: new GLib.Variant('s', this._lastActiveRoom.channel_name)
             });
+        }
 
         if (serializedChannel)
             this._settings.set_value('last-selected-channel', serializedChannel);
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 1aaa816..46915f2 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -52,12 +52,12 @@ var PasteManager = class {
         let contentType = fileInfo.get_content_type();
         let targetType = _getTargetForContentType(contentType);
 
-        if (targetType == DndTargetType.TEXT)
+        if (targetType == DndTargetType.TEXT) {
             file.load_contents_async(null, (f, res) => {
                 let [, contents] = f.load_contents_finish(res);
                 Utils.gpaste(contents.toString(), title, callback);
             });
-        else if (targetType == DndTargetType.IMAGE)
+        } else if (targetType == DndTargetType.IMAGE) {
             file.read_async(GLib.PRIORITY_DEFAULT, null, (f, res) => {
                 let stream = f.read_finish(res);
                 GdkPixbuf.Pixbuf.new_from_stream_async(stream, null, (s, res) => {
@@ -65,8 +65,9 @@ var PasteManager = class {
                     Utils.imgurPaste(pixbuf, title, callback);
                 });
             });
-        else
+        } else {
             callback(null);
+        }
     }
 };
 
diff --git a/src/roomList.js b/src/roomList.js
index 3a5d145..ca10a5a 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -120,7 +120,7 @@ var RoomRow = GObject.registerClass({
     _onConnectionStatusChanged() {
         let status = this._getConnectionStatus();
         // Show loading indicator if joining a room takes more than 3 seconds
-        if (status == Tp.ConnectionStatus.CONNECTED && !this._room.channel)
+        if (status == Tp.ConnectionStatus.CONNECTED && !this._room.channel) {
             this._connectingTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 3, () => {
                 this._connectingTimeoutId = 0;
 
@@ -129,8 +129,9 @@ var RoomRow = GObject.registerClass({
                 this._eventStack.visible_child_name = 'connecting';
                 return GLib.SOURCE_REMOVE;
             });
-        else
+        } else {
             this._eventStack.visible_child_name = 'messages';
+        }
     }
 
     _updatePending() {
@@ -153,11 +154,12 @@ var RoomRow = GObject.registerClass({
             return;
         this._eventStack.visible_child_name = 'messages';
 
-        for (let signal of ['message-received', 'pending-message-removed'])
+        for (let signal of ['message-received', 'pending-message-removed']) {
             this._channelSignals.push(
                 this._room.channel.connect(signal,
                                            this._updatePending.bind(this))
             );
+        }
         this._updatePending();
     }
 
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 0a4a9a7..b03b1f9 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -323,9 +323,10 @@ var ServerRoomList = GObject.registerClass({
                 if (name[0] == '#')
                     name = name.substr(1, name.length);
 
-                if (_strBaseEqual(name, customName))
+                if (_strBaseEqual(name, customName)) {
                     store.set_value(this._customRoomItem,
                                     RoomListColumn.NAME, customName = '');
+                }
 
                 let room = roomManager.lookupRoomByName(roomInfo.get_name(), this._account);
                 let sensitive = room == null;
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 3646646..ccd7a87 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -61,13 +61,14 @@ class SASLAuthHandler {
     }
 
     _onPasswordReady(password) {
-        if (password)
+        if (password) {
             this._proxy.StartMechanismWithDataRemote('X-TELEPATHY-PASSWORD',
                                                      password);
-        else
+        } else {
             this._proxy.AbortSASLRemote(SASLAbortReason.USER_ABORT,
                                         'Password not available',
                                         this._resetPrompt.bind(this));
+        }
     }
 
     _onSASLStatusChanged(proxy, sender, [status]) {
@@ -243,9 +244,10 @@ class TelepathyClient extends Tp.BaseClient {
 
         this._networkMonitor.connect('network-changed',
                                      this._onNetworkChanged.bind(this));
-        if (this._networkMonitor.state_valid)
+        if (this._networkMonitor.state_valid) {
             this._onNetworkChanged(this._networkMonitor,
                                    this._networkMonitor.network_available);
+        }
     }
 
     _onNetworkChanged(mon, connected) {
diff --git a/src/userList.js b/src/userList.js
index ac0bcde..55908b5 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -168,10 +168,11 @@ var UserDetails = GObject.registerClass({
 
         this._user = user;
 
-        if (this._user)
+        if (this._user) {
             this._selfContactChangedId =
                 this._user.connection.connect('notify::self-contact',
                                               this._updateButtonVisibility.bind(this));
+        }
 
         if (this.expanded)
             this._expand();
@@ -216,12 +217,13 @@ var UserDetails = GObject.registerClass({
 
         this._cancellable = new Gio.Cancellable();
 
-        if (this._user)
+        if (this._user) {
             this._user.request_contact_info_async(this._cancellable,
                                                   this._onContactInfoReady.bind(this));
-        //TODO: else use this._nickname to query tracker
-        else
+        } else {
+            //TODO: else use this._nickname to query tracker
             this._revealDetails();
+        }
     }
 
     _unexpand() {
@@ -233,29 +235,34 @@ var UserDetails = GObject.registerClass({
     }
 
     _formatLast(seconds) {
-        if (seconds < 60)
+        if (seconds < 60) {
             return ngettext('%d second ago',
                             '%d seconds ago', seconds).format(seconds);
+        }
 
         let minutes = seconds / 60;
-        if (minutes < 60)
+        if (minutes < 60) {
             return ngettext('%d minute ago',
                             '%d minutes ago', minutes).format(minutes);
+        }
 
         let hours = minutes / 60;
-        if (hours < 24)
+        if (hours < 24) {
             return ngettext('%d hour ago',
                             '%d hours ago', hours).format(hours);
+        }
 
         let days = hours / 24;
-        if (days < 7)
+        if (days < 7) {
             return ngettext('%d day ago',
                             '%d days ago', days).format(days);
+        }
 
         let weeks = days / 7;
-        if (days < 30)
+        if (days < 30) {
             return ngettext('%d week ago',
                             '%d weeks ago', weeks).format(weeks);
+        }
 
         let months = days / 30;
         return ngettext('%d month ago',
diff --git a/src/utils.js b/src/utils.js
index 75da466..b880a1e 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -166,12 +166,13 @@ function findUrls(str) {
 
 function findChannels(str, server) {
     let res = [], match;
-    while ((match = _channelRegexp.exec(str)))
+    while ((match = _channelRegexp.exec(str))) {
         res.push({
             url: `irc://${server}/${match[2]}`,
             name: `#${match[2]}`,
             pos: match.index + match[1].length
         });
+    }
     return res;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]