[gnome-maps/wip/mattiasb/eslint-2.0-2] Lint: Disallow coercing comparisons



commit 12ab8faa6e289abe04ac948cd5d77948b712910d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Wed Feb 17 08:42:51 2016 +0100

    Lint: Disallow coercing comparisons
    
    In JavaScript when comparing two variables of different types with
    `==` and `!=` JavaScript silently coerces the variable types according
    to the Abstract Equality Comparison Algorithm[1], a rather obscure
    algorithm which can have unexpected results.
    
    Let's instead use the type safe alternatives `===` and `!==`.
    
    1: http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3

 .eslintrc.yaml                     |    2 ++
 src/locationServiceNotification.js |    2 +-
 src/osmEditDialog.js               |    8 ++++----
 src/osmTypes.js                    |    4 ++--
 src/osmUtils.js                    |    2 +-
 src/placeBubble.js                 |    2 +-
 src/translations.js                |    8 ++++----
 7 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/.eslintrc.yaml b/.eslintrc.yaml
index 5eedefe..bd32b83 100644
--- a/.eslintrc.yaml
+++ b/.eslintrc.yaml
@@ -34,3 +34,5 @@ rules:
         - 4
     no-var:
         - 2
+    eqeqeq:
+        - 2
diff --git a/src/locationServiceNotification.js b/src/locationServiceNotification.js
index 04c7040..e3bd2cf 100644
--- a/src/locationServiceNotification.js
+++ b/src/locationServiceNotification.js
@@ -55,7 +55,7 @@ const LocationServiceNotification = new Lang.Class({
                 if (!this.parent)
                     return;
 
-                if (Application.geoclue.state == Geoclue.State.ON)
+                if (Application.geoclue.state === Geoclue.State.ON)
                     this.dismiss();
             }).bind(this));
 
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
index 3308b32..35fa65e 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -335,7 +335,7 @@ const OSMEditDialog = new Lang.Class({
             let key = OSMTypes.OSM_TYPE_TAGS[i];
             let value = this._osmObject.get_tag(key);
 
-            if (value != null) {
+            if (value !== null) {
                 numTypeTags++;
                 lastTypeTag = key;
             }
@@ -352,7 +352,7 @@ const OSMEditDialog = new Lang.Class({
 
             /* if the type tag has a value we know of, and possible has
              * translations for */
-            if (typeTitle != null) {
+            if (typeTitle !== null) {
                 this._typeValueLabel.label = typeTitle;
                 this._typeLabel.visible = true;
                 this._typeButton.visible = true;
@@ -473,7 +473,7 @@ const OSMEditDialog = new Lang.Class({
                 return row;
 
             /* if we reached the end of the table */
-            if (label == null)
+            if (label === null)
                 return -1;
         }
 
@@ -673,7 +673,7 @@ const OSMEditDialog = new Lang.Class({
             let fieldSpec = OSM_FIELDS[i];
             let value = osmObject.get_tag(fieldSpec.tag);
 
-            if (value != null)
+            if (value !== null)
                 this._addOSMField(fieldSpec, value);
         }
 
diff --git a/src/osmTypes.js b/src/osmTypes.js
index c464a74..88d957b 100644
--- a/src/osmTypes.js
+++ b/src/osmTypes.js
@@ -81,7 +81,7 @@ function findMatches(prefix, maxMatches) {
         /* if the (locale-case-normalized) title matches parts of the search
          * string, or as a convenience for expert mappers, if the search string
          * is prefix of the raw OSM tag value */
-        if (normalizedTitle.indexOf(normalized) != -1
+        if (normalizedTitle.indexOf(normalized) !== -1
             || (prefixLength >= 3 && parts[1].startsWith(prefix))) {
             numMatches++;
             matches.push({key: parts[0], value: parts[1], title: title});
@@ -153,7 +153,7 @@ const RecentTypesStore = new Lang.Class({
         }
 
         /* remove the type if it was already found in the list */
-        if (pos != -1)
+        if (pos !== -1)
             this._recentTypes.splice(pos, 1);
 
         this._recentTypes.unshift({key: key, value: value});
diff --git a/src/osmUtils.js b/src/osmUtils.js
index 01235aa..1fc2a1f 100644
--- a/src/osmUtils.js
+++ b/src/osmUtils.js
@@ -32,7 +32,7 @@ function getWikipediaOSMArticleFormatFromUrl(url) {
     let regex = /https?:\/\/(..)\.wikipedia\.org\/wiki\/(.+)/;
     let match = url.match(regex);
 
-    if (match && match.length == 3) {
+    if (match && match.length === 3) {
         let lang = match[1];
         let article = match[2];
 
diff --git a/src/placeBubble.js b/src/placeBubble.js
index 197fa75..7854f97 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -205,7 +205,7 @@ const PlaceBubble = new Lang.Class({
             } else {
                 info.label = expandedContent[row].info;
             }
-            this._expandedContent.attach(info, col, row, col == 0 ? 2 : 1, 1);
+            this._expandedContent.attach(info, col, row, col === 0 ? 2 : 1, 1);
         }
 
         this._expandButton.visible = expandedContent.length > 0;
diff --git a/src/translations.js b/src/translations.js
index 020023e..e6651c9 100644
--- a/src/translations.js
+++ b/src/translations.js
@@ -105,7 +105,7 @@ function translateOpeningHours(string) {
 function _translateOpeningHoursPart(string) {
     let splitString = string.split(' ');
 
-    if (splitString.length == 2) {
+    if (splitString.length === 2) {
         let dayIntervalSpec =
             _translateOpeningHoursDayIntervalList(splitString[0].trim());
         let timeIntervalSpec =
@@ -268,7 +268,7 @@ function _translateOpeningHoursTimeInterval(string) {
 
     let splitString = string.split('-');
 
-    if (splitString.length == 2) {
+    if (splitString.length === 2) {
         let from = splitString[0].trim();
         let to = splitString[1].trim();
 
@@ -294,7 +294,7 @@ function _translateOpeningHoursTimeInterval(string) {
 function _translateOpeningHoursTime(string) {
     let splitString = string.split(':');
 
-    if (splitString.length == 2) {
+    if (splitString.length === 2) {
         let h = splitString[0];
         let min = splitString[1];
 
@@ -307,7 +307,7 @@ function _translateOpeningHoursTime(string) {
             return string;
 
         // should translate 24:00 to 00:00 to keep GDateTime happy
-        if (h == 24)
+        if (h === 24)
             h = 0;
 
         // create a dummy DateTime, we are just interested in the hour and


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