From 54b4014504ad7f088a3b29259f951565ebcc619c Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:04 +0000 Subject: [PATCH 1/15] cleanup: Use shorthand in object literals Property names can be omitted if the variable used to set its value already has the same name. --- diff --git a/prefs.js b/prefs.js index 6c018c0..8535be7 100644 --- a/prefs.js +++ b/prefs.js @@ -52,16 +52,15 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { this._addRow(2, "Position", comboBox); let adjustment = this._createAdjustment('logo-size', 0.25); - let scale = new Gtk.Scale({ adjustment: adjustment, - draw_value: false }); + let scale = new Gtk.Scale({ adjustment, draw_value: false }); this._addRow(3, "Size", scale); adjustment = this._createAdjustment('logo-border', 1.0); - scale = new Gtk.Scale({ adjustment: adjustment, draw_value: false }); + scale = new Gtk.Scale({ adjustment, draw_value: false }); this._addRow(4, "Border", scale); adjustment = this._createAdjustment('logo-opacity', 1.0); - scale = new Gtk.Scale({ adjustment: adjustment, draw_value: false }); + scale = new Gtk.Scale({ adjustment, draw_value: false }); this._addRow(5, "Opacity", scale); let checkWidget = new Gtk.CheckButton({ label: "Show for all backgrounds" }); @@ -90,8 +89,8 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let [type, variant] = schemaKey.get_range().deep_unpack(); if (type != 'range') throw new Error('Invalid key type "%s" for adjustment'.format(type)); - let [min, max] = variant.deep_unpack(); - let adj = new Gtk.Adjustment({ lower: min, upper: max, + let [lower, upper] = variant.deep_unpack(); + let adj = new Gtk.Adjustment({ lower, upper, step_increment: step, page_increment: 10 * step }); this._settings.bind(key, adj, 'value', Gio.SettingsBindFlags.DEFAULT); From fb8c481b6fc5e7f49ac807eb719611b2121b2ead Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:09 +0000 Subject: [PATCH 2/15] cleanup: Remove unused parameter Spotted by eslint. --- diff --git a/prefs.js b/prefs.js index 8535be7..e7d6592 100644 --- a/prefs.js +++ b/prefs.js @@ -107,7 +107,7 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { cr.paint(); if (!this._logo) - this._createLogoThumbnail(width, height); + this._createLogoThumbnail(width); let [x, y] = this._getLogoPosition(width, height); Gdk.cairo_set_source_pixbuf(cr, this._logo, x, y); @@ -132,7 +132,7 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { GdkPixbuf.InterpType.BILINEAR); } - _createLogoThumbnail(width, height) { + _createLogoThumbnail(width) { let filename = this._settings.get_string('logo-file'); let file = Gio.File.new_for_commandline_arg(filename); let pixbuf = GdkPixbuf.Pixbuf.new_from_file(file.get_path()); From 17b9ddf200f28ba3b9f3ed157c8b28b556d24aa6 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:09 +0000 Subject: [PATCH 3/15] style: Switch switch indent Switch to the style that gjs uses, which sort of sets the canonical GNOME javascript style ... --- diff --git a/extension.js b/extension.js index 0f90e8e..801a801 100644 --- a/extension.js +++ b/extension.js @@ -160,22 +160,22 @@ class BackgroundLogo { _updatePosition() { let xAlign, yAlign; switch (this._settings.get_string('logo-position')) { - case 'center': - xAlign = Clutter.ActorAlign.CENTER; - yAlign = Clutter.ActorAlign.CENTER; - break; - case 'bottom-left': - xAlign = Clutter.ActorAlign.START; - yAlign = Clutter.ActorAlign.END; - break; - case 'bottom-center': - xAlign = Clutter.ActorAlign.CENTER; - yAlign = Clutter.ActorAlign.END; - break; - case 'bottom-right': - xAlign = Clutter.ActorAlign.END; - yAlign = Clutter.ActorAlign.END; - break; + case 'center': + xAlign = Clutter.ActorAlign.CENTER; + yAlign = Clutter.ActorAlign.CENTER; + break; + case 'bottom-left': + xAlign = Clutter.ActorAlign.START; + yAlign = Clutter.ActorAlign.END; + break; + case 'bottom-center': + xAlign = Clutter.ActorAlign.CENTER; + yAlign = Clutter.ActorAlign.END; + break; + case 'bottom-right': + xAlign = Clutter.ActorAlign.END; + yAlign = Clutter.ActorAlign.END; + break; } this._bin.x_align = xAlign; this._bin.y_align = yAlign; diff --git a/prefs.js b/prefs.js index e7d6592..d9376b6 100644 --- a/prefs.js +++ b/prefs.js @@ -147,22 +147,22 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let scaledBorder = this._settings.get_uint('logo-border') * this._scale; let x, y; switch (this._settings.get_string('logo-position')) { - case 'center': - x = (width - this._logo.get_width()) / 2; - y = (height - this._logo.get_height()) / 2; - break; - case 'bottom-left': - x = scaledBorder; - y = height - this._logo.get_height() - scaledBorder; - break; - case 'bottom-center': - x = (width - this._logo.get_width()) / 2; - y = height - this._logo.get_height() - scaledBorder; - break; - case 'bottom-right': - x = width - this._logo.get_width() - scaledBorder; - y = height - this._logo.get_height() - scaledBorder; - break; + case 'center': + x = (width - this._logo.get_width()) / 2; + y = (height - this._logo.get_height()) / 2; + break; + case 'bottom-left': + x = scaledBorder; + y = height - this._logo.get_height() - scaledBorder; + break; + case 'bottom-center': + x = (width - this._logo.get_width()) / 2; + y = height - this._logo.get_height() - scaledBorder; + break; + case 'bottom-right': + x = width - this._logo.get_width() - scaledBorder; + y = height - this._logo.get_height() - scaledBorder; + break; } return [x, y]; } From 9709720cbe29121ae6b8a68b21137ab2cb8ae337 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:36 +0000 Subject: [PATCH 4/15] style: Change indentation style of object literals Instead of keeping the first property on the same line as the opening brace and aligning the properties, use a four-space indent. This brings us closer to gjs' coding style, and as a bonus helps keeping lines in the soft 80 character limit. --- diff --git a/extension.js b/extension.js index 801a801..4035498 100644 --- a/extension.js +++ b/extension.js @@ -73,8 +73,10 @@ class BackgroundLogo { this._updateLogoTexture(); }); - this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(), - opacity: 0 }); + this.actor = new St.Widget({ + layout_manager: new Clutter.BinLayout(), + opacity: 0 + }); bgManager._container.add_actor(this.actor); this.actor.connect('destroy', this._onDestroy.bind(this)); @@ -201,11 +203,11 @@ class BackgroundLogo { else // background == NONE visible = false; - Tweener.addTween(this.actor, - { opacity: visible ? 255 : 0, - time: Background.FADE_ANIMATION_TIME, - transition: 'easeOutQuad' - }); + Tweener.addTween(this.actor, { + opacity: visible ? 255 : 0, + time: Background.FADE_ANIMATION_TIME, + transition: 'easeOutQuad' + }); } _backgroundDestroyed() { diff --git a/prefs.js b/prefs.js index d9376b6..c048357 100644 --- a/prefs.js +++ b/prefs.js @@ -26,16 +26,20 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { this._preview.queue_draw(); }); - this._preview = new Gtk.DrawingArea({ halign: Gtk.Align.CENTER, - margin_bottom: 18 }); + this._preview = new Gtk.DrawingArea({ + halign: Gtk.Align.CENTER, + margin_bottom: 18 + }); this._preview.connect('draw', this._drawPreview.bind(this)); this.attach(this._preview, 0, 0, 2, 1); let filter = new Gtk.FileFilter(); filter.add_pixbuf_formats(); - let fileChooser = new Gtk.FileChooserButton({ title: "Select an Image", - filter: filter }); + let fileChooser = new Gtk.FileChooserButton({ + title: "Select an Image", + filter: filter + }); fileChooser.set_filename(this._settings.get_string('logo-file')); fileChooser.connect('file-set', () => { this._settings.set_string('logo-file', fileChooser.get_filename()); @@ -63,7 +67,9 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { scale = new Gtk.Scale({ adjustment, draw_value: false }); this._addRow(5, "Opacity", scale); - let checkWidget = new Gtk.CheckButton({ label: "Show for all backgrounds" }); + let checkWidget = new Gtk.CheckButton({ + label: "Show for all backgrounds" + }); this._settings.bind('logo-always-visible', checkWidget, 'active', Gio.SettingsBindFlags.DEFAULT); this.attach(checkWidget, 1, 6, 1, 1); @@ -76,11 +82,16 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { widget.hexpand = true; if (!this._sizeGroup) - this._sizeGroup = new Gtk.SizeGroup({ mode: Gtk.SizeGroupMode.VERTICAL }); + this._sizeGroup = new Gtk.SizeGroup({ + mode: Gtk.SizeGroupMode.VERTICAL + }); this._sizeGroup.add_widget(widget); - this.attach(new Gtk.Label({ label: label, xalign: 1.0, - margin_start: margin }), 0, row, 1, 1); + this.attach(new Gtk.Label({ + label, + xalign: 1.0, + margin_start: margin + }), 0, row, 1, 1); this.attach(widget, 1, row, 1, 1); } @@ -90,9 +101,12 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { if (type != 'range') throw new Error('Invalid key type "%s" for adjustment'.format(type)); let [lower, upper] = variant.deep_unpack(); - let adj = new Gtk.Adjustment({ lower, upper, - step_increment: step, - page_increment: 10 * step }); + let adj = new Gtk.Adjustment({ + lower, + upper, + step_increment: step, + page_increment: 10 * step + }); this._settings.bind(key, adj, 'value', Gio.SettingsBindFlags.DEFAULT); return adj; } From 601efd457b0fd5da81c1f77d8dc6984ebf055b1f Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:38 +0000 Subject: [PATCH 5/15] style: Use single quotes The coding style has always been to use single quotes for non-translatable strings, and is nowadays moving towards using single quotes consistently for all strings. --- diff --git a/prefs.js b/prefs.js index c048357..87e3f3e 100644 --- a/prefs.js +++ b/prefs.js @@ -37,38 +37,38 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { filter.add_pixbuf_formats(); let fileChooser = new Gtk.FileChooserButton({ - title: "Select an Image", + title: 'Select an Image', filter: filter }); fileChooser.set_filename(this._settings.get_string('logo-file')); fileChooser.connect('file-set', () => { this._settings.set_string('logo-file', fileChooser.get_filename()); }); - this._addRow(1, "Logo image", fileChooser); + this._addRow(1, 'Logo image', fileChooser); let comboBox = new Gtk.ComboBoxText(); - comboBox.append('center', "Center"); - comboBox.append('bottom-left', "Bottom left"); - comboBox.append('bottom-center', "Bottom center"); - comboBox.append('bottom-right', "Bottom right"); + comboBox.append('center', 'Center'); + comboBox.append('bottom-left', 'Bottom left'); + comboBox.append('bottom-center', 'Bottom center'); + comboBox.append('bottom-right', 'Bottom right'); this._settings.bind('logo-position', comboBox, 'active-id', Gio.SettingsBindFlags.DEFAULT); - this._addRow(2, "Position", comboBox); + this._addRow(2, 'Position', comboBox); let adjustment = this._createAdjustment('logo-size', 0.25); let scale = new Gtk.Scale({ adjustment, draw_value: false }); - this._addRow(3, "Size", scale); + this._addRow(3, 'Size', scale); adjustment = this._createAdjustment('logo-border', 1.0); scale = new Gtk.Scale({ adjustment, draw_value: false }); - this._addRow(4, "Border", scale); + this._addRow(4, 'Border', scale); adjustment = this._createAdjustment('logo-opacity', 1.0); scale = new Gtk.Scale({ adjustment, draw_value: false }); - this._addRow(5, "Opacity", scale); + this._addRow(5, 'Opacity', scale); let checkWidget = new Gtk.CheckButton({ - label: "Show for all backgrounds" + label: 'Show for all backgrounds' }); this._settings.bind('logo-always-visible', checkWidget, 'active', Gio.SettingsBindFlags.DEFAULT); From 793602be16a95f008375b16931d55d40206db69d Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:03:38 +0000 Subject: [PATCH 6/15] style: Stop using braces for single-line arrow functions Braces are optional for single-line arrow functions, but there's a subtle difference: Without braces, the expression is implicitly used as return value; with braces, the function returns nothing unless there's an explicit return. We currently reflect that in our style by only omitting braces when the function is expected to have a return value, but that's not very obvious, not an important differentiation to make, and not easy to express in an automatic rule. So just omit braces consistently as mandated by gjs' coding style. --- diff --git a/extension.js b/extension.js index 4035498..55e6587 100644 --- a/extension.js +++ b/extension.js @@ -264,7 +264,7 @@ class Extension { } _destroyLogo() { - this._logos.forEach(l => { l.actor.destroy(); }); + this._logos.forEach(l => l.actor.destroy()); } enable() { From 8c9947c258343fdfd5ed35cb8a6d75d30fe75823 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 7/15] style: Change indentation of method arguments Move from the old coding style of aligning method arguments to the new style used by gjs, where arguments use the same four-space indent used elsewhere. It will need a bit getting used to, but lends itself less to overly lengthy lines. --- diff --git a/extension.js b/extension.js index 55e6587..2a78ea8 100644 --- a/extension.js +++ b/extension.js @@ -56,15 +56,15 @@ class BackgroundLogo { this._settings = ExtensionUtils.getSettings(); this._settings.connect('changed::logo-file', - this._updateLogo.bind(this)); + this._updateLogo.bind(this)); this._settings.connect('changed::logo-size', - this._updateScale.bind(this)); + this._updateScale.bind(this)); this._settings.connect('changed::logo-position', - this._updatePosition.bind(this)); + this._updatePosition.bind(this)); this._settings.connect('changed::logo-border', - this._updateBorder.bind(this)); + this._updateBorder.bind(this)); this._settings.connect('changed::logo-always-visible', - this._updateVisibility.bind(this)); + this._updateVisibility.bind(this)); this._textureCache = St.TextureCache.get_default(); this._textureCache.connect('texture-file-changed', (cache, file) => { @@ -92,19 +92,19 @@ class BackgroundLogo { this._bin.connect('notify::resource-scale', this._updateLogoTexture.bind(this)); - this._settings.bind('logo-opacity', this._bin, 'opacity', - Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('logo-opacity', + this._bin, 'opacity', + Gio.SettingsBindFlags.DEFAULT); this._updateLogo(); this._updatePosition(); this._updateBorder(); - this._bgDestroyedId = - bgManager.backgroundActor.connect('destroy', - this._backgroundDestroyed.bind(this)); + this._bgDestroyedId = bgManager.backgroundActor.connect('destroy', + this._backgroundDestroyed.bind(this)); - this._bgChangedId = - bgManager.connect('changed', this._updateVisibility.bind(this)); + this._bgChangedId = bgManager.connect('changed', + this._updateVisibility.bind(this)); this._updateVisibility(); } @@ -216,7 +216,7 @@ class BackgroundLogo { if (this._bgManager._backgroundSource) // background swapped this._bgDestroyedId = this._bgManager.backgroundActor.connect('destroy', - this._backgroundDestroyed.bind(this)); + this._backgroundDestroyed.bind(this)); else // bgManager destroyed this.actor.destroy(); } diff --git a/prefs.js b/prefs.js index 87e3f3e..8f1b90d 100644 --- a/prefs.js +++ b/prefs.js @@ -51,8 +51,9 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { comboBox.append('bottom-left', 'Bottom left'); comboBox.append('bottom-center', 'Bottom center'); comboBox.append('bottom-right', 'Bottom right'); - this._settings.bind('logo-position', comboBox, 'active-id', - Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('logo-position', + comboBox, 'active-id', + Gio.SettingsBindFlags.DEFAULT); this._addRow(2, 'Position', comboBox); let adjustment = this._createAdjustment('logo-size', 0.25); @@ -70,8 +71,9 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let checkWidget = new Gtk.CheckButton({ label: 'Show for all backgrounds' }); - this._settings.bind('logo-always-visible', checkWidget, 'active', - Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('logo-always-visible', + checkWidget, 'active', + Gio.SettingsBindFlags.DEFAULT); this.attach(checkWidget, 1, 6, 1, 1); } @@ -142,8 +144,8 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { file = Gio.File.new_for_commandline_arg(filename1); } let pixbuf = GdkPixbuf.Pixbuf.new_from_file(file.get_path()); - this._background = pixbuf.scale_simple(width, height, - GdkPixbuf.InterpType.BILINEAR); + this._background = pixbuf.scale_simple( + width, height, GdkPixbuf.InterpType.BILINEAR); } _createLogoThumbnail(width) { @@ -152,9 +154,10 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let pixbuf = GdkPixbuf.Pixbuf.new_from_file(file.get_path()); let size = this._settings.get_double('logo-size') / 100; let ratio = pixbuf.get_width() / pixbuf.get_height(); - this._logo = pixbuf.scale_simple(size * width, - size * width / ratio, - GdkPixbuf.InterpType.BILINEAR); + this._logo = pixbuf.scale_simple( + size * width, + size * width / ratio, + GdkPixbuf.InterpType.BILINEAR); } _getLogoPosition(width, height) { @@ -188,8 +191,9 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let rect = screen.get_monitor_geometry(screen.get_primary_monitor()); this._scale = PREVIEW_WIDTH / rect.width; - this._preview.set_size_request(PREVIEW_WIDTH, - PREVIEW_WIDTH * rect.height / rect.width); + this._preview.set_size_request( + PREVIEW_WIDTH, + PREVIEW_WIDTH * rect.height / rect.width); } }); From 2284c92970c37445d4f58ee2e8e65b9458962f86 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 8/15] lint: Import eslint rules from gjs gjs started to run eslint during its CI a while ago, so there is an existing rules set we can use as a starting point for our own setup. As we will adapt those rules to our code base, we don't want those changes to make it harder to synchronize the copy with future gjs changes, so include the rules from a separate file rather than using the configuration directly. --- diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..255b0f2 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "./lint/eslintrc-gjs.json" + ] +} diff --git a/lint/eslintrc-gjs.json b/lint/eslintrc-gjs.json new file mode 100644 index 0000000..51964a0 --- /dev/null +++ b/lint/eslintrc-gjs.json @@ -0,0 +1,133 @@ +{ + "env": { + "es6": true + }, + "extends": "eslint:recommended", + "rules": { + "array-bracket-newline": [ + "error", + "consistent" + ], + "array-bracket-spacing": [ + "error", + "never" + ], + "arrow-spacing": "error", + "brace-style": "error", + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "indent": [ + "error", + 4, + { + "ignoredNodes": [ + "CallExpression[callee.object.name=GObject][callee.property.name=registerClass] > ClassExpression:first-child" + ], + "MemberExpression": "off" + } + ], + "key-spacing": [ + "error", + { + "beforeColon": false, + "afterColon": true + } + ], + "keyword-spacing": [ + "error", + { + "before": true, + "after": true + } + ], + "linebreak-style": [ + "error", + "unix" + ], + "no-empty": [ + "error", + { + "allowEmptyCatch": true + } + ], + "no-implicit-coercion": [ + "error", + { + "allow": ["!!"] + } + ], + "no-restricted-properties": [ + "error", + { + "object": "Lang", + "property": "bind", + "message": "Use arrow notation or Function.prototype.bind()" + }, + { + "object": "Lang", + "property": "Class", + "message": "Use ES6 classes" + } + ], + "nonblock-statement-body-position": [ + "error", + "below" + ], + "object-curly-newline": [ + "error", + { + "consistent": true + } + ], + "object-curly-spacing": [ + "error", + "always" + ], + "prefer-template": "error", + "quotes": [ + "error", + "single", + { + "avoidEscape": true + } + ], + "semi": [ + "error", + "always" + ], + "semi-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "space-before-blocks": "error", + "space-infix-ops": [ + "error", + { + "int32Hint": false + } + ] + }, + "globals": { + "ARGV": false, + "Debugger": false, + "GIRepositoryGType": false, + "imports": false, + "Intl": false, + "log": false, + "logError": false, + "print": false, + "printerr": false, + "window": false + }, + "parserOptions": { + "ecmaVersion": 2017 + } +} From 572bedbc3bd8f5c18125b5a37a17a0308a240fca Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 9/15] lint: Tweak the whitelist of globals gjs doesn't include any gettext wrappers, and obviously can't know about the shell's global object, so include those in the list of globals. --- diff --git a/.eslintrc.json b/.eslintrc.json index 255b0f2..30afb59 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,6 @@ { "extends": [ - "./lint/eslintrc-gjs.json" + "./lint/eslintrc-gjs.json", + "./lint/eslintrc-shell.json" ] } diff --git a/lint/eslintrc-shell.json b/lint/eslintrc-shell.json new file mode 100644 index 0000000..f0290fe --- /dev/null +++ b/lint/eslintrc-shell.json @@ -0,0 +1,9 @@ +{ + "globals": { + "global": false, + "_": false, + "C_": false, + "N_": false, + "ngettext": false + } +} From 1f8869ecfa398ad12ee2e026f8fb8156c64f3388 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 10/15] lint: Require spaces inside braces in object literals Prohibiting spaces where the established GNOME style has required them for a decade would be a harsh change for no good reason. --- diff --git a/lint/eslintrc-shell.json b/lint/eslintrc-shell.json index f0290fe..d2157c2 100644 --- a/lint/eslintrc-shell.json +++ b/lint/eslintrc-shell.json @@ -1,4 +1,10 @@ { + "rules": { + "object-curly-spacing": [ + "error", + "always" + ] + }, "globals": { "global": false, "_": false, From 9bcdaf8bce2e2ef3ff287f31c7482edc4d7eb936 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 11/15] lint: Enforce arrow notation We replaced all Lang.bind() calls with arrow functions or the standardized Function.prototype.bind(), at least for the former eslint has some options to ensure that the old custom doesn't sneak back in. --- diff --git a/lint/eslintrc-shell.json b/lint/eslintrc-shell.json index d2157c2..5f75e8c 100644 --- a/lint/eslintrc-shell.json +++ b/lint/eslintrc-shell.json @@ -3,7 +3,8 @@ "object-curly-spacing": [ "error", "always" - ] + ], + "prefer-arrow-callback": "error" }, "globals": { "global": false, From a0babc3a53f2f9420cc77585c26dbe8d609583a1 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 12/15] lint: Enforce camelCase All variables should be in camelCase, so configure the corresponding rule to enforce this. Exempt properties for now, to accommodate the existing practice of using C-style underscore names for construct properties of introspected objects --- diff --git a/lint/eslintrc-shell.json b/lint/eslintrc-shell.json index 5f75e8c..349542e 100644 --- a/lint/eslintrc-shell.json +++ b/lint/eslintrc-shell.json @@ -1,5 +1,12 @@ { "rules": { + "camelcase": [ + "error", + { + "properties": "never", + "allow": ["^vfunc_"] + } + ], "object-curly-spacing": [ "error", "always" From 7f76a971cc27d5789314389c38391b598e511cd6 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:18:29 +0000 Subject: [PATCH 13/15] lint: Allow marking variables/arguments as unused Unused variables or arguments can indicate bugs, but they can also help document the code, in particular in case of signal handlers and destructuring. Account for this by keeping the error, but set up patterns that allow us to opt out of if for individual variables/arguments. For arguments we pick a '_' prefix, while for variables we go with a suffix instead, to not accidentally exempt private module-scope variables. --- diff --git a/lint/eslintrc-shell.json b/lint/eslintrc-shell.json index 349542e..fc6f581 100644 --- a/lint/eslintrc-shell.json +++ b/lint/eslintrc-shell.json @@ -7,6 +7,13 @@ "allow": ["^vfunc_"] } ], + "no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "_$" + } + ], "object-curly-spacing": [ "error", "always" From 6b4dc0effcb766bcda756104e858e03387c152fc Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:20:40 +0000 Subject: [PATCH 14/15] cleanup: Mark unused arguments as unused This will stop eslint from warning about them, while keeping their self-documenting benefit. --- diff --git a/prefs.js b/prefs.js index 8f1b90d..2b922d4 100644 --- a/prefs.js +++ b/prefs.js @@ -139,7 +139,7 @@ class BackgroundLogoPrefsWidget extends Gtk.Grid { let slideShow = new GnomeDesktop.BGSlideShow({ filename: file.get_path() }); slideShow.load(); - let [progress, duration, isFixed, filename1, filename2] = + let [progress_, duration_, isFixed_, filename1, filename2_] = slideShow.get_current_slide(width, height); file = Gio.File.new_for_commandline_arg(filename1); } From 87519e323ae85b189a29acc3681b7fb5cec027de Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 09 2019 12:21:00 +0000 Subject: [PATCH 15/15] cleanup: Mark exported symbols eslint obviously doesn't know about gnome-shell's extension API, so the various entry points trigger unused-variable errors. To fix, explicitly mark those symbols as exported. --- diff --git a/extension.js b/extension.js index 2a78ea8..53a3115 100644 --- a/extension.js +++ b/extension.js @@ -1,3 +1,4 @@ +/* exported init */ /* * Copyright 2014 Red Hat, Inc * diff --git a/prefs.js b/prefs.js index 2b922d4..ef97251 100644 --- a/prefs.js +++ b/prefs.js @@ -1,3 +1,4 @@ +/* exported init, buildPrefsWidget */ const { Gdk, GdkPixbuf, Gio, GnomeDesktop, GObject, Gtk } = imports.gi; const ExtensionUtils = imports.misc.extensionUtils;