From cedb54ed644d1b644f835ba31bd1e07ca7e8d90b Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Sat, 28 Jan 2023 23:34:15 +0100 Subject: [PATCH] Other: Disallow omitting curly braces and enforce one true brace style Do this by updating the ESLint config accordingly and also fix new complaints. --- .eslintrc.yml | 6 ++++++ src/extensionModules/BoxOrderManager.js | 8 ++++++-- src/prefsModules/PrefsBoxOrderItemRow.js | 17 +++++++++++------ src/prefsModules/PrefsBoxOrderListBox.js | 4 +++- src/prefsModules/PrefsPage.js | 20 ++++++++++++-------- src/prefsModules/ScrollManager.js | 8 ++++++-- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 3eaa9c5..a0fbb75 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -20,6 +20,12 @@ rules: no-unused-vars: - error - argsIgnorePattern: "^_" + curly: + - error + - all + brace-style: + - error + - 1tbs # Rules from GJS Style Guide regarding whitespace. # See here: https://gjs.guide/guides/gjs/style-guide.html#whitespace func-call-spacing: diff --git a/src/extensionModules/BoxOrderManager.js b/src/extensionModules/BoxOrderManager.js index 82c18d3..d0584ab 100644 --- a/src/extensionModules/BoxOrderManager.js +++ b/src/extensionModules/BoxOrderManager.js @@ -176,7 +176,9 @@ var BoxOrderManager = GObject.registerClass({ // Get the indicator container associated with the current role. const associatedIndicatorContainer = Main.panel.statusArea[role]?.container; - if (indicatorContainerSet.has(associatedIndicatorContainer)) validBoxOrder.push(role); + if (indicatorContainerSet.has(associatedIndicatorContainer)) { + validBoxOrder.push(role); + } } return validBoxOrder; @@ -218,7 +220,9 @@ var BoxOrderManager = GObject.registerClass({ // First get the role associated with the current indicator // container. let role = indicatorContainerRoleMap.get(indicatorContainer); - if (!role) continue; + if (!role) { + continue; + } // Handle an AppIndicator/KStatusNotifierItem item differently. if (role.startsWith("appindicator-")) { diff --git a/src/prefsModules/PrefsBoxOrderItemRow.js b/src/prefsModules/PrefsBoxOrderItemRow.js index c177802..69e7d67 100644 --- a/src/prefsModules/PrefsBoxOrderItemRow.js +++ b/src/prefsModules/PrefsBoxOrderItemRow.js @@ -31,11 +31,14 @@ var PrefsBoxOrderItemRow = GObject.registerClass({ #associateItem(item) { this.item = item; - // Set `this._item_name_display_label` to something nicer, if the - // associated item is an AppIndicator/KStatusNotifierItem item. - if (item.startsWith("appindicator-kstatusnotifieritem-")) this._item_name_display_label.set_label(item.replace("appindicator-kstatusnotifieritem-", "")); - // Otherwise just set it to `item`. - else this._item_name_display_label.set_label(item); + if (item.startsWith("appindicator-kstatusnotifieritem-")) { + // Set `this._item_name_display_label` to something nicer, if the + // associated item is an AppIndicator/KStatusNotifierItem item. + this._item_name_display_label.set_label(item.replace("appindicator-kstatusnotifieritem-", "")); + } else { + // Otherwise just set it to `item`. + this._item_name_display_label.set_label(item); + } } /** @@ -133,6 +136,8 @@ var PrefsBoxOrderItemRow = GObject.registerClass({ // If the list boxes of `this` and the drop value were different, // save an updated box order for the list were the drop value was in // as well. - if (ownListBox !== valueListBox) valueListBox.saveBoxOrderToSettings(); + if (ownListBox !== valueListBox) { + valueListBox.saveBoxOrderToSettings(); + } } }); diff --git a/src/prefsModules/PrefsBoxOrderListBox.js b/src/prefsModules/PrefsBoxOrderListBox.js index 1da5fe7..395ac85 100644 --- a/src/prefsModules/PrefsBoxOrderListBox.js +++ b/src/prefsModules/PrefsBoxOrderListBox.js @@ -67,7 +67,9 @@ var PrefsBoxOrderListBox = GObject.registerClass({ let currentBoxOrder = []; for (let potentialPrefsBoxOrderItemRow of this) { // Only process PrefsBoxOrderItemRows. - if (potentialPrefsBoxOrderItemRow.constructor.$gtype.name !== "PrefsBoxOrderItemRow") continue; + if (potentialPrefsBoxOrderItemRow.constructor.$gtype.name !== "PrefsBoxOrderItemRow") { + continue; + } const item = potentialPrefsBoxOrderItemRow.item; currentBoxOrder.push(item); diff --git a/src/prefsModules/PrefsPage.js b/src/prefsModules/PrefsPage.js index abd6791..f9059b0 100644 --- a/src/prefsModules/PrefsPage.js +++ b/src/prefsModules/PrefsPage.js @@ -42,14 +42,18 @@ var PrefsPage = GObject.registerClass({ // Scroll, when the pointer is in the right places. controller.connect("motion", (_, _x, y) => { - // If the pointer is currently in the upper ten percent of this - // widget, then scroll up. - if (y <= this.get_allocated_height() * 0.1) scrollManager.startScrollUp(); - // If the pointer is currently in the lower ten percent of this - // widget, then scroll down. - else if (y >= this.get_allocated_height() * 0.9) scrollManager.startScrollDown(); - // Otherwise stop scrolling. - else scrollManager.stopScrollAll(); + if (y <= this.get_allocated_height() * 0.1) { + // If the pointer is currently in the upper ten percent of this + // widget, then scroll up. + scrollManager.startScrollUp(); + } else if (y >= this.get_allocated_height() * 0.9) { + // If the pointer is currently in the lower ten percent of this + // widget, then scroll down. + scrollManager.startScrollDown(); + } else { + // Otherwise stop scrolling. + scrollManager.stopScrollAll(); + } }); // Make sure scrolling stops, when DND operation ends. diff --git a/src/prefsModules/ScrollManager.js b/src/prefsModules/ScrollManager.js index 1dc2a0e..60fa186 100644 --- a/src/prefsModules/ScrollManager.js +++ b/src/prefsModules/ScrollManager.js @@ -15,7 +15,9 @@ var ScrollManager = class ScrollManager { startScrollUp() { // If the scroll up is already started, don't do anything. - if (this._scrollUp) return; + if (this._scrollUp) { + return; + } // Make sure scroll down is stopped. this.stopScrollDown(); @@ -40,7 +42,9 @@ var ScrollManager = class ScrollManager { startScrollDown() { // If the scroll down is already started, don't do anything. - if (this._scrollDown) return; + if (this._scrollDown) { + return; + } // Make sure scroll up is stopped. this.stopScrollUp();