diff options
author | Claudio André <claudioandre.br@gmail.com> | 2018-08-09 14:23:40 -0300 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2018-08-09 19:13:02 -0400 |
commit | 8c58407d79059f96d9a54c7c2cfcc8f9a8bbf829 (patch) | |
tree | d2716975f0807a9fc3d6bd5b570c841563bb7366 | |
parent | a0229da3bce64cbe67a0340f2cf8f35c5037df42 (diff) | |
download | gjs-8c58407d79059f96d9a54c7c2cfcc8f9a8bbf829.tar.gz |
examples: fix eslint errors
Run `eslint --fix examples --format unix`. Examples don't have a real
history, so that is acceptable.
-rw-r--r-- | examples/calc.js | 23 | ||||
-rw-r--r-- | examples/clutter.js | 12 | ||||
-rw-r--r-- | examples/gettext.js | 8 | ||||
-rw-r--r-- | examples/gio-cat.js | 4 | ||||
-rw-r--r-- | examples/gtk-application.js | 52 | ||||
-rw-r--r-- | examples/gtk.js | 16 | ||||
-rw-r--r-- | examples/http-server.js | 18 | ||||
-rw-r--r-- | examples/webkit.js | 2 |
8 files changed, 70 insertions, 65 deletions
diff --git a/examples/calc.js b/examples/calc.js index 7ec6a353..57c30fc5 100644 --- a/examples/calc.js +++ b/examples/calc.js @@ -10,7 +10,7 @@ var calc_val = ''; function update_display() { label.set_markup(`<span size='30000'>${calc_val}</span>`); - if(calc_val === '') { + if (calc_val === '') { label.set_markup("<span size='30000'>0</span>"); } } @@ -50,12 +50,12 @@ function pressed_number(button) { function swap_sign() { calc_val = ((calc_val[0] == '-') ? - calc_val.substring(1) : '-' + calc_val); + calc_val.substring(1) : `-${calc_val}`); update_display(); } function random_num() { - calc_val = Math.floor(Math.random() * 1000) + ''; + calc_val = `${Math.floor(Math.random() * 1000)}`; update_display(); } @@ -66,7 +66,7 @@ function pack_buttons(buttons, vbox) { vbox.pack_start(hbox, true, true, 2); - for(let i = 0; i <= 4; i++) { + for (let i = 0; i <= 4; i++) { hbox.pack_start(buttons[i], true, true, 1); } } @@ -85,35 +85,40 @@ function create_buttons() { create_button('←', backspace), create_button('↻', random_num), create_button('Clr', clear), - create_button('±', swap_sign)], vbox); + create_button('±', swap_sign) + ], vbox); pack_buttons([ create_button(')', pressed_number), create_button('7', pressed_number), create_button('8', pressed_number), create_button('9', pressed_number), - create_button('/', pressed_operator)], vbox); + create_button('/', pressed_operator) + ], vbox); pack_buttons([ create_button('sin(', pressed_number), create_button('4', pressed_number), create_button('5', pressed_number), create_button('6', pressed_number), - create_button('*', pressed_operator)], vbox); + create_button('*', pressed_operator) + ], vbox); pack_buttons([ create_button('cos(', pressed_number), create_button('1', pressed_number), create_button('2', pressed_number), create_button('3', pressed_number), - create_button('-', pressed_operator)], vbox); + create_button('-', pressed_operator) + ], vbox); pack_buttons([ create_button('tan(', pressed_number), create_button('0', pressed_number), create_button('.', pressed_number), create_button('=', pressed_equals), - create_button('+', pressed_operator)], vbox); + create_button('+', pressed_operator) + ], vbox); return vbox; } diff --git a/examples/clutter.js b/examples/clutter.js index a6b50edd..2fc3eabb 100644 --- a/examples/clutter.js +++ b/examples/clutter.js @@ -4,14 +4,14 @@ Clutter.init(null); let stage = new Clutter.Stage(); -let texture = new Clutter.Texture({ filename: 'test.jpg', - reactive: true }); +let texture = new Clutter.Texture({filename: 'test.jpg', + reactive: true}); texture.connect('button-press-event', - function(o, event) { - log('Clicked!'); - return true; - }); + function(o, event) { + log('Clicked!'); + return true; + }); let color = new Clutter.Color(); color.from_string('Black'); diff --git a/examples/gettext.js b/examples/gettext.js index 3c67be71..25236ebd 100644 --- a/examples/gettext.js +++ b/examples/gettext.js @@ -2,13 +2,13 @@ imports.gi.versions.Gtk = '3.0'; const Gettext = imports.gettext; const Gtk = imports.gi.Gtk; -Gettext.bindtextdomain("gnome-panel-3.0", "/usr/share/locale"); -Gettext.textdomain("gnome-panel-3.0"); +Gettext.bindtextdomain('gnome-panel-3.0', '/usr/share/locale'); +Gettext.textdomain('gnome-panel-3.0'); Gtk.init(null); -let w = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL }); -w.add(new Gtk.Label({ label: Gettext.gettext("Panel") })); +let w = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL}); +w.add(new Gtk.Label({label: Gettext.gettext('Panel')})); w.show_all(); Gtk.main(); diff --git a/examples/gio-cat.js b/examples/gio-cat.js index f26e7108..5b058d1a 100644 --- a/examples/gio-cat.js +++ b/examples/gio-cat.js @@ -11,7 +11,7 @@ function cat(filename) { try { contents = f.load_contents_finish(res)[1]; } catch (e) { - log("*** ERROR: " + e.message); + log(`*** ERROR: ${e.message}`); loop.quit(); return; } @@ -23,7 +23,7 @@ function cat(filename) { } if (ARGV.length != 1) { - printerr("Usage: gio-cat.js filename"); + printerr('Usage: gio-cat.js filename'); } else { cat(ARGV[0]); } diff --git a/examples/gtk-application.js b/examples/gtk-application.js index 65084c11..4e81183d 100644 --- a/examples/gtk-application.js +++ b/examples/gtk-application.js @@ -3,7 +3,7 @@ const System = imports.system; // Include this in case both GTK3 and GTK4 installed, otherwise an exception // will be thrown -imports.gi.versions.Gtk = "3.0"; +imports.gi.versions.Gtk = '3.0'; const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; @@ -15,27 +15,27 @@ const Gtk = imports.gi.Gtk; // https://wiki.gnome.org/HowDoI/GtkApplication var ExampleApplication = GObject.registerClass({ Properties: { - "exampleprop": GObject.ParamSpec.string( - "exampleprop", // property name - "ExampleProperty", // nickname - "An example read write property", // description + 'exampleprop': GObject.ParamSpec.string( + 'exampleprop', // property name + 'ExampleProperty', // nickname + 'An example read write property', // description GObject.ParamFlags.READWRITE, // read/write/construct... - "" // implement defaults manually + '' // implement defaults manually ) }, - Signals: { "examplesig": { param_types: [ GObject.TYPE_INT ] } }, + Signals: {'examplesig': {param_types: [GObject.TYPE_INT]}}, }, class ExampleApplication extends Gtk.Application { _init() { super._init({ - application_id: "org.gnome.gjs.ExampleApplication", + application_id: 'org.gnome.gjs.ExampleApplication', flags: Gio.ApplicationFlags.FLAGS_NONE }); } // Example property getter/setter get exampleprop() { - if (typeof this._exampleprop === "undefined") { - return "a default value"; + if (typeof this._exampleprop === 'undefined') { + return 'a default value'; } return this._exampleprop; @@ -45,12 +45,12 @@ var ExampleApplication = GObject.registerClass({ this._exampleprop = value; // notify() has to be called, if you want it - this.notify("exampleprop"); + this.notify('exampleprop'); } // Example signal emission emit_examplesig(number) { - this.emit("examplesig", number); + this.emit('examplesig', number); } vfunc_startup() { @@ -58,15 +58,15 @@ var ExampleApplication = GObject.registerClass({ // An example GAction, see: https://wiki.gnome.org/HowDoI/GAction let exampleAction = new Gio.SimpleAction({ - name: "exampleAction", - parameter_type: new GLib.VariantType("s") + name: 'exampleAction', + parameter_type: new GLib.VariantType('s') }); - exampleAction.connect("activate", (action, param) => { + exampleAction.connect('activate', (action, param) => { param = param.deep_unpack().toString(); - if (param === "exampleParameter") { - log("Yes!"); + if (param === 'exampleParameter') { + log('Yes!'); } }); @@ -81,15 +81,15 @@ var ExampleApplication = GObject.registerClass({ // Example ApplicationWindow let window = new Gtk.ApplicationWindow({ application: this, - title: "Example Application Window", + title: 'Example Application Window', default_width: 300, default_height: 200 }); - let label = new Gtk.Label({ label: this.exampleprop }); + let label = new Gtk.Label({label: this.exampleprop}); window.add(label); - window.connect("delete-event", () => { + window.connect('delete-event', () => { this.quit(); }); @@ -97,10 +97,10 @@ var ExampleApplication = GObject.registerClass({ // Example GNotification, see: https://developer.gnome.org/GNotification/ let notif = new Gio.Notification(); - notif.set_title("Example Notification"); - notif.set_body("Example Body"); + notif.set_title('Example Notification'); + notif.set_body('Example Body'); notif.set_icon( - new Gio.ThemedIcon({ name: "dialog-information-symbolic" }) + new Gio.ThemedIcon({name: 'dialog-information-symbolic'}) ); // A default action for when the body of the notification is clicked @@ -108,16 +108,16 @@ var ExampleApplication = GObject.registerClass({ // A button for the notification notif.add_button( - "Button Text", + 'Button Text', "app.exampleAction('exampleParameter')" ); // This won't actually be shown, since an application needs a .desktop // file with a base name matching the application id - this.send_notification("example-notification", notif); + this.send_notification('example-notification', notif); // Withdraw - this.withdraw_notification("example-notification"); + this.withdraw_notification('example-notification'); } }); diff --git a/examples/gtk.js b/examples/gtk.js index ec3a29df..dc22a311 100644 --- a/examples/gtk.js +++ b/examples/gtk.js @@ -1,6 +1,6 @@ // Include this in case both GTK3 and GTK4 installed, otherwise an exception // will be thrown -imports.gi.versions.Gtk = "3.0"; +imports.gi.versions.Gtk = '3.0'; const Gtk = imports.gi.Gtk; // Initialize Gtk before you start calling anything from the import @@ -9,7 +9,7 @@ Gtk.init(null); // Construct a top-level window let window = new Gtk.Window ({ type: Gtk.WindowType.TOPLEVEL, - title: "A default title", + title: 'A default title', default_width: 300, default_height: 250, // A decent example of how constants are mapped: @@ -20,11 +20,11 @@ let window = new Gtk.Window ({ // Object properties can also be set or changed after construction, unless they // are marked construct-only. -window.title = "Hello World!"; +window.title = 'Hello World!'; // This is a callback function function onDeleteEvent(widget, event) { - log("delete-event emitted"); + log('delete-event emitted'); // If you return false in the "delete_event" signal handler, Gtk will emit // the "destroy" signal. // @@ -36,20 +36,20 @@ function onDeleteEvent(widget, event) { // When the window is given the "delete_event" signal (this is given by the // window manager, usually by the "close" option, or on the titlebar), we ask // it to call the onDeleteEvent() function as defined above. -window.connect("delete-event", onDeleteEvent); +window.connect('delete-event', onDeleteEvent); // GJS will warn when calling a C function with unexpected arguments... // // window.connect("destroy", Gtk.main_quit); // // ...so use arrow functions for inline callbacks with arguments to adjust -window.connect("destroy", () => { +window.connect('destroy', () => { Gtk.main_quit(); }); // Create a button to close the window let button = new Gtk.Button({ - label: "Close the Window", + label: 'Close the Window', // Set visible to 'true' if you don't want to call button.show() later visible: true, // Another example of constant mapping: @@ -60,7 +60,7 @@ let button = new Gtk.Button({ }); // Connect to the 'clicked' signal, using another way to call an arrow function -button.connect("clicked", () => window.destroy()); +button.connect('clicked', () => window.destroy()); // Add the button to the window window.add(button); diff --git a/examples/http-server.js b/examples/http-server.js index 36c73f02..a49f0727 100644 --- a/examples/http-server.js +++ b/examples/http-server.js @@ -4,22 +4,22 @@ const Soup = imports.gi.Soup; function main() { let handler = function(server, msg, path, query, client) { - msg.status_code = 200; - msg.response_headers.set_content_type('text/html', {}); - msg.response_body.append('<html><body>Greetings, visitor from ' + client.get_host() + '<br>What is your name?<form action="/hello"><input name="myname"></form></body></html>\n'); + msg.status_code = 200; + msg.response_headers.set_content_type('text/html', {}); + msg.response_body.append(`<html><body>Greetings, visitor from ${client.get_host()}<br>What is your name?<form action="/hello"><input name="myname"></form></body></html>\n`); }; let helloHandler = function(server, msg, path, query, client) { - if (!query) { + if (!query) { msg.set_redirect(302, '/'); return; - } + } - msg.status_code = 200; - msg.response_headers.set_content_type('text/html', { charset: 'UTF-8' }); - msg.response_body.append('<html><body>Hello, ' + query.myname + '! \u263A<br><a href="/">Go back</a></body></html>'); + msg.status_code = 200; + msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'}); + msg.response_body.append(`<html><body>Hello, ${query.myname}! \u263A<br><a href="/">Go back</a></body></html>`); }; - let server = new Soup.Server({ port: 1080 }); + let server = new Soup.Server({port: 1080}); server.add_handler('/', handler); server.add_handler('/hello', helloHandler); server.run(); diff --git a/examples/webkit.js b/examples/webkit.js index 1d932cfc..f3c117a8 100644 --- a/examples/webkit.js +++ b/examples/webkit.js @@ -8,7 +8,7 @@ Gtk.init(null); let win = new Gtk.Window(); let view = new WebKit.WebView(); -view.load_uri("http://www.google.com/"); +view.load_uri('http://www.google.com/'); win.add(view); win.connect('destroy', () => { |