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



commit ba3fd3874d4a83118d33e5336ca93e47b5bd9e45
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sat Feb 27 04:35:49 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                |   13 ++++++-------
 7 files changed, 17 insertions(+), 16 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 c8d87e5..af88b4b 100644
--- a/src/osmEditDialog.js
+++ b/src/osmEditDialog.js
@@ -384,7 +384,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;
             }
@@ -401,7 +401,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;
@@ -771,7 +771,7 @@ const OSMEditDialog = new Lang.Class({
             if (fieldSpec.subtags) {
                 let hasAny = false;
                 fieldSpec.subtags.forEach(function(tag) {
-                    if (osmObject.get_tag(tag) != null)
+                    if (osmObject.get_tag(tag) !== null)
                         hasAny = true;
                 });
 
@@ -783,7 +783,7 @@ const OSMEditDialog = new Lang.Class({
                 }
             } else {
                 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 91c6b69..b3bc5c2 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..b5c2974 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,12 +294,11 @@ function _translateOpeningHoursTimeInterval(string) {
 function _translateOpeningHoursTime(string) {
     let splitString = string.split(':');
 
-    if (splitString.length == 2) {
-        let h = splitString[0];
-        let min = splitString[1];
+    if (splitString.length === 2) {
+        let [h, min] = splitString.map(Number);
 
         // if the parts aren't numbers
-        if (h % 1 !== 0 || min % 1 !== 0)
+        if (isNaN(h) || isNaN(min))
             return string;
 
         // if the hours or minute components are out of range
@@ -307,7 +306,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]