Patchwork [2,of,7] hgweb: use strict equals in mercurial.js

login
register
mail settings
Submitter Anton Shestakov
Date Nov. 27, 2017, 9:28 a.m.
Message ID <01aaffb4652759bb0f2e.1511774889@neuro>
Download mbox | patch
Permalink /patch/25765/
State Accepted
Headers show

Comments

Anton Shestakov - Nov. 27, 2017, 9:28 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1511355179 -28800
#      Wed Nov 22 20:52:59 2017 +0800
# Node ID 01aaffb4652759bb0f2eca4e18c74eedd316b806
# Parent  89d0610c63cc9bb10ca5feec6a1274b65e524e8a
# EXP-Topic hgweb-cleanup
hgweb: use strict equals in mercurial.js

This patch changes "==" (equals operator) to "===" (strict equals operator).
The difference between them is that the latter doesn't do any type coercions.
It's handy to compare string '1' to number 1 sometimes, but most of the time
using "==" is inadvertent and can be replaced by an explicit type conversion.
(This corresponds to "eqeqeq" option of jshint).

Some of the changes in this patch are straightforward, e.g. when comparing
results of typeof (they could only be strings). The same goes for 'none' and
similar strings that can't be sensibly coerced to some other type. Two changes
that compare values to "1" and "0" can be clarified: getAttribute() returns
either a string or null, but comparing null to a string is always false, so no
logic is lost.

Patch

diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js
+++ b/mercurial/templates/static/mercurial.js
@@ -60,9 +60,9 @@  function Graph() {
 		// provides the multiplier that should be applied to
 		// the foreground colours.
 		var s;
-		if(typeof color == "string") {
+		if(typeof color === "string") {
 			s = "#" + color;
-		} else { //typeof color == "number"
+		} else { //typeof color === "number"
 			color %= colors.length;
 			var red = (colors[color][0] * fg) || bg;
 			var green = (colors[color][1] * fg) || bg;
@@ -124,7 +124,7 @@  function Graph() {
 					this.columns += 1;
 				}
 
-				if (start == this.columns && start > end) {
+				if (start === this.columns && start > end) {
 					fold = true;
 				}
 
@@ -229,7 +229,7 @@  function process_dates(parentSelector){
 		for (var unit in scales){
 			var s = scales[unit];
 			var n = Math.floor(delta / s);
-			if ((n >= 2) || (s == 1)){
+			if ((n >= 2) || (s === 1)){
 				if (future){
 					return format(n, unit) + ' from now';
 				} else {
@@ -257,7 +257,7 @@  function process_dates(parentSelector){
 
 function toggleDiffstat() {
     var curdetails = document.getElementById('diffstatdetails').style.display;
-    var curexpand = curdetails == 'none' ? 'inline' : 'none';
+    var curexpand = curdetails === 'none' ? 'inline' : 'none';
     document.getElementById('diffstatdetails').style.display = curexpand;
     document.getElementById('diffstatexpand').style.display = curdetails;
 }
@@ -380,7 +380,7 @@  function ajaxScrollInit(urlFormat,
                     appendFormatHTML(container, messageFormat, message);
                 },
                 function onsuccess(htmlText) {
-                    if (mode == 'graph') {
+                    if (mode === 'graph') {
                         var sizes = htmlText.match(/^\s*<canvas id="graph" width="(\d+)" height="(\d+)"><\/canvas>$/m);
                         var addWidth = sizes[1];
                         var addHeight = sizes[2];
@@ -457,7 +457,7 @@  function renderDiffOptsForm() {
         window.location.search = urlParams.toString();
     }
 
-    var allChecked = form.getAttribute("data-ignorews") == "1";
+    var allChecked = form.getAttribute("data-ignorews") === "1";
 
     for (var i = 0; i < KEYS.length; i++) {
         var key = KEYS[i];
@@ -468,10 +468,10 @@  function renderDiffOptsForm() {
         }
 
         currentValue = form.getAttribute("data-" + key);
-        checkbox.checked = currentValue != "0";
+        checkbox.checked = currentValue !== "0";
 
         // ignorews implies ignorewsamount and ignorewseol.
-        if (allChecked && (key == "ignorewsamount" || key == "ignorewseol")) {
+        if (allChecked && (key === "ignorewsamount" || key === "ignorewseol")) {
             checkbox.checked = true;
             checkbox.disabled = true;
         }