[gnome-maps/wip/jshint] Add linting via jshint



commit eb961557d09477acc58f19fed58203a314003744
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu May 9 03:59:03 2013 +0200

    Add linting via jshint
    
    Constructed a .jshintrc-file which I think corresponds to our coding
    style and then fixed all issues found by jshint.
    This should keep our code a bit cleaner.

 .jshintrc           |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/mainWindow.js   |   14 ++++----
 src/mapLocation.js  |    4 +-
 src/mapView.js      |   42 ++++++++++++-------------
 src/userLocation.js |   18 ++++++-----
 src/utils.js        |    9 ++----
 6 files changed, 124 insertions(+), 45 deletions(-)
---
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..cd6c8cf
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,82 @@
+{
+    "maxerr"        : 50,       // {int} Maximum error before stopping
+
+    // Enforcing
+    "bitwise"       : false,    // true: Prohibit bitwise operators (&, |, ^, etc.)
+    "camelcase"     : false,    // true: Identifiers must be in camelCase
+    "curly"         : false,    // true: Require {} for every new block or scope
+    "eqeqeq"        : true,     // true: Require triple equals (===) for comparison
+    "forin"         : false,    // true: Require filtering for..in loops with obj.hasOwnProperty()
+    "immed"         : false,    // true: Require immediate invocations to be wrapped in parens e.g. 
`(function () { } ());`
+    "indent"        : 4,        // {int} Number of spaces to use for indentation
+    "latedef"       : true,     // true: Require variables/functions to be defined before being used
+    "newcap"        : true,     // true: Require capitalization of all constructor functions e.g. `new F()`
+    "noarg"         : true,     // true: Prohibit use of `arguments.caller` and `arguments.callee`
+    "noempty"       : true,     // true: Prohibit use of empty blocks
+    "nonew"         : false,    // true: Prohibit use of constructors for side-effects (without assignment)
+    "plusplus"      : false,    // true: Prohibit use of `++` & `--`
+    "quotmark"      : false,    // Quotation mark consistency:
+                                //   false    : do nothing (default)
+                                //   true     : ensure whatever is used is consistent
+                                //   "single" : require single quotes
+                                //   "double" : require double quotes
+    "undef"         : true,     // true: Require all non-global variables to be declared (prevents global 
leaks)
+    "unused"        : false,    // true: Require all defined variables be used
+    "strict"        : false,    // true: Requires all functions run in ES5 Strict Mode
+    "trailing"      : true,     // true: Prohibit trailing whitespaces
+    "maxparams"     : false,    // {int} Max number of formal params allowed per function
+    "maxdepth"      : false,    // {int} Max depth of nested blocks (within functions)
+    "maxstatements" : false,    // {int} Max number statements per function
+    "maxcomplexity" : false,    // {int} Max cyclomatic complexity per function
+    "maxlen"        : false,    // {int} Max number of characters per line
+
+    // Relaxing
+    "asi"           : false,     // true: Tolerate Automatic Semicolon Insertion (no semicolons)
+    "boss"          : false,     // true: Tolerate assignments where comparisons would be expected
+    "debug"         : false,     // true: Allow debugger statements e.g. browser breakpoints.
+    "eqnull"        : false,     // true: Tolerate use of `== null`
+    "esnext"        : true,      // true: Allow ES.next (ES6) syntax (ex: `const`)
+    "moz"           : true,      // true: Allow Mozilla specific syntax (extends and overrides esnext 
features)
+                                 // (ex: `for each`, multiple try/catch, function expression…)
+    "evil"          : false,     // true: Tolerate use of `eval` and `new Function()`
+    "expr"          : false,     // true: Tolerate `ExpressionStatement` as Programs
+    "funcscope"     : false,     // true: Tolerate defining variables inside control statements"
+    "globalstrict"  : false,     // true: Allow global "use strict" (also enables 'strict')
+    "iterator"      : false,     // true: Tolerate using the `__iterator__` property
+    "lastsemic"     : false,     // true: Tolerate omitting a semicolon for the last statement of a 1-line 
block
+    "laxbreak"      : false,     // true: Tolerate possibly unsafe line breakings
+    "laxcomma"      : false,     // true: Tolerate comma-first style coding
+    "loopfunc"      : false,     // true: Tolerate functions being defined in loops
+    "multistr"      : false,     // true: Tolerate multi-line strings
+    "proto"         : false,     // true: Tolerate using the `__proto__` property
+    "scripturl"     : false,     // true: Tolerate script-targeted URLs
+    "smarttabs"     : false,     // true: Tolerate mixed tabs/spaces when used for alignment
+    "shadow"        : false,     // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
+    "sub"           : false,     // true: Tolerate using `[]` notation when it can still be expressed in dot 
notation
+    "supernew"      : false,     // true: Tolerate `new function () { ... };` and `new Object;`
+    "validthis"     : false,     // true: Tolerate using this in a non-constructor function
+
+    // Environments
+    "browser"       : false,    // Web Browser (window, document, etc)
+    "couch"         : false,    // CouchDB
+    "devel"         : false,    // Development/debugging (alert, confirm, etc)
+    "dojo"          : false,    // Dojo Toolkit
+    "jquery"        : false,    // jQuery
+    "mootools"      : false,    // MooTools
+    "node"          : false,    // Node.js
+    "nonstandard"   : false,    // Widely adopted globals (escape, unescape, etc)
+    "prototypejs"   : false,    // Prototype and Scriptaculous
+    "rhino"         : false,    // Rhino
+    "worker"        : false,    // Web Workers
+    "wsh"           : false,    // Windows Scripting Host
+    "yui"           : false,    // Yahoo User Interface
+
+    // Legacy
+    "nomen"         : false,    // true: Prohibit dangling `_` in variables
+    "onevar"        : false,    // true: Allow only one `var` statement per function
+    "passfail"      : false,    // true: Stop on first error
+    "white"         : false,    // true: Check against strict whitespace and indentation rules
+
+    // Custom Globals
+    "predef"        : [ "log", "logError", "print", "printerr", "imports", "ARGV" ]
+}
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d0606b9..609ed76 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -57,12 +57,12 @@ const MainWindow = new Lang.Class({
         this.window.application = app;
 
         Utils.initActions(this.window, [
-            { 
-                properties: { name: 'about' }, 
+            {
+                properties: { name: 'about' },
                 signalHandlers: { activate: this._onAboutActivate }
             }, {
                 properties: {
-                    name: 'map-type-menu', 
+                    name: 'map-type-menu',
                     state: GLib.Variant.new('b', false)
                 },
                 signalHandlers: { activate: this._onMapTypeMenuActivate }
@@ -78,7 +78,7 @@ const MainWindow = new Lang.Class({
 
         // apply the last saved window size and position
         let size = Application.settings.get_value('window-size');
-        if (size.n_children() == 2) {
+        if (size.n_children() === 2) {
             let width = size.get_child_value(0);
             let height = size.get_child_value(1);
 
@@ -87,7 +87,7 @@ const MainWindow = new Lang.Class({
         }
 
         let position = Application.settings.get_value('window-position');
-        if (position.n_children() == 2) {
+        if (position.n_children() === 2) {
             let x = position.get_child_value(0);
             let y = position.get_child_value(1);
 
@@ -164,7 +164,7 @@ const MainWindow = new Lang.Class({
     },
 
     _onConfigureEvent: function(widget, event) {
-        if (this._configureId != 0) {
+        if (this._configureId !== 0) {
             Mainloop.source_remove(this._configureId);
             this._configureId = 0;
         }
@@ -195,7 +195,7 @@ const MainWindow = new Lang.Class({
 
     _quit: function() {
         // remove configure event handler if still there
-        if (this._configureId != 0) {
+        if (this._configureId !== 0) {
             Mainloop.source_remove(this._configureId);
             this._configureId = 0;
         }
diff --git a/src/mapLocation.js b/src/mapLocation.js
index 48677f5..afe0045 100644
--- a/src/mapLocation.js
+++ b/src/mapLocation.js
@@ -64,7 +64,7 @@ const MapLocation = new Lang.Class({
          * also give user a good idea of where the destination is compared to current
          * location.
          */
-        let locations = new Array();
+        let locations = [];
         locations[0] = new Geocode.Location({ latitude: this._view.get_center_latitude(),
                                               longitude: this._view.get_center_longitude() });
         locations[1] = this;
@@ -94,6 +94,6 @@ const MapLocation = new Lang.Class({
     showNGoTo: function(animate, layer) {
         this.show(layer);
         this.goTo(animate);
-    },
+    }
 });
 Signals.addSignalMethods(MapLocation.prototype);
diff --git a/src/mapView.js b/src/mapView.js
index 0bfe944..b8e70dc 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -42,10 +42,10 @@ const Geoclue = imports.geoclue;
 const _ = imports.gettext.gettext;
 
 const MapType = {
-   STREET:  Champlain.MAP_SOURCE_OSM_MAPQUEST,
-   AERIAL: Champlain.MAP_SOURCE_OSM_AERIAL_MAP,
-   CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
-   TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
+    STREET:  Champlain.MAP_SOURCE_OSM_MAPQUEST,
+    AERIAL:  Champlain.MAP_SOURCE_OSM_AERIAL_MAP,
+    CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
+    TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
 };
 
 const MapView = new Lang.Class({
@@ -86,23 +86,21 @@ const MapView = new Lang.Class({
     },
 
     geocodeSearch: function(string) {
-        let forward = Geocode.Forward.new_for_string(string);
-
-        forward.search_async (null, Lang.bind(this,
-            function(forward, res) {
+        Geocode.Forward
+            .new_for_string(string)
+            .search_async (null, Lang.bind(this, function(forward, res) {
                 try {
                     let places = forward.search_finish(res);
                     log (places.length + " places found");
-                    let mapLocations = new Array();
-                    places.forEach(Lang.bind(this,
-                        function(place) {
-                            let location = place.get_location();
-                            if (location == null)
-                                return;
-
-                            let mapLocation = new MapLocation.MapLocation(location, this);
-                            mapLocations.push(mapLocation);
-                        }));
+                    let mapLocations = [];
+                    places.forEach(Lang.bind(this, function(place) {
+                        let location = place.get_location();
+                        if (!location)
+                            return;
+
+                        let mapLocation = new MapLocation.MapLocation(location, this);
+                        mapLocations.push(mapLocation);
+                    }));
                     this._showLocations(mapLocations);
                 } catch (e) {
                     log ("Failed to search '" + string + "': " + e.message);
@@ -126,7 +124,7 @@ const MapView = new Lang.Class({
                     max_longitude = location.longitude;
                 if (location.longitude < min_longitude)
                     min_longitude = location.longitude;
-                }));
+            }));
 
         let bbox = new Champlain.BoundingBox();
         bbox.left = min_longitude;
@@ -157,7 +155,7 @@ const MapView = new Lang.Class({
 
         let onLocationChanged = Lang.bind(this,
             function() {
-                if (this._geoclue.location == null)
+                if (!this._geoclue.location)
                     return;
 
                 this._userLocation = new UserLocation.UserLocation(this._geoclue.location, this);
@@ -168,7 +166,7 @@ const MapView = new Lang.Class({
     },
 
     _showLocations: function(locations) {
-        if (locations.length == 0)
+        if (locations.length === 0)
             return;
         this._markerLayer.remove_all();
 
@@ -177,7 +175,7 @@ const MapView = new Lang.Class({
                 location.show(this._markerLayer);
             }));
 
-        if (locations.length == 1)
+        if (locations.length === 1)
             locations[0].goTo(true);
         else
             this.ensureVisible(locations);
diff --git a/src/userLocation.js b/src/userLocation.js
index fd9419a..293bc62 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -49,10 +49,10 @@ const UserLocation = new Lang.Class({
                                                      0);
             }));
         let pin_actor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/pin.svg");
-        if (pin_actor == null)
+        if (!pin_actor)
             return;
         let bubbleActor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/bubble.svg");
-        if (bubbleActor == null)
+        if (!bubbleActor)
             return;
         bubbleActor.set_x_expand(true);
         bubbleActor.set_y_expand(true);
@@ -65,13 +65,15 @@ const UserLocation = new Lang.Class({
                                                  blue: 255,
                                                  green: 255,
                                                  alpha: 255 }));
-        let layout = new Clutter.BinLayout();
-        let descriptionActor = new Clutter.Actor({ layout_manager: layout });
+        let descriptionActor = new Clutter.Actor({
+            layout_manager: new Clutter.BinLayout()
+        });
         descriptionActor.add_child(bubbleActor);
         descriptionActor.add_child(textActor);
 
-        let layout = new Clutter.BoxLayout({ vertical: true });
-        let locationActor = new Clutter.Actor({ layout_manager: layout });
+        let locationActor = new Clutter.Actor({
+            layout_manager: new Clutter.BoxLayout({ vertical: true })
+        });
         locationActor.add_child(descriptionActor);
         locationActor.add_child(pin_actor);
 
@@ -81,7 +83,7 @@ const UserLocation = new Lang.Class({
                                            descriptionActor, "visible",
                                            GObject.BindingFlags.SYNC_CREATE);
 
-        if (this.accuracy == 0) {
+        if (this.accuracy === 0) {
             layer.add_marker(this._locationMarker);
             return;
         }
@@ -131,5 +133,5 @@ const UserLocation = new Lang.Class({
             this._accuracyMarker.set_size(size);
             this._accuracyMarker.show();
         }
-    },
+    }
 });
diff --git a/src/utils.js b/src/utils.js
index 09df902..be7fd02 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -58,9 +58,6 @@ function addJSSignalMethods(proto) {
 }
 
 function loadStyleSheet(file) {
-    file = file || Gio.file_new_for_path(GLib.build_filenamev([pkg.pkgdatadir,
-                                                               'application.css']));
-
     let provider = new Gtk.CssProvider();
     provider.load_from_file(file);
     Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
@@ -91,7 +88,7 @@ function initActions(actionMap, simpleActionEntries, context) {
 
 // accuracy: double value in meters
 function getZoomLevelForAccuracy(accuracy) {
-    if (accuracy == Geocode.LOCATION_ACCURACY_UNKNOWN)
+    if (accuracy === Geocode.LOCATION_ACCURACY_UNKNOWN)
         return 12; // Accuracy is usually city-level when unknown
     else if (accuracy <= Geocode.LOCATION_ACCURACY_STREET)
         return 16;
@@ -106,9 +103,9 @@ function getZoomLevelForAccuracy(accuracy) {
 }
 
 function getDescriptionForAccuracy(accuracy) {
-    if (accuracy == Geocode.LOCATION_ACCURACY_UNKNOWN)
+    if (accuracy === Geocode.LOCATION_ACCURACY_UNKNOWN)
         return "Unknown";
-    else if (accuracy == 0)
+    else if (accuracy === 0)
         return "Exact";
     else {
         let area =  Math.PI * Math.pow(accuracy / 1000, 2);


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