Patchwork [1,of,7] hgweb: use strict equals, remove non-breaking space in followlines.js

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

Comments

Anton Shestakov - Nov. 27, 2017, 9:28 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1511353927 -28800
#      Wed Nov 22 20:32:07 2017 +0800
# Node ID 89d0610c63cc9bb10ca5feec6a1274b65e524e8a
# Parent  32bb27dd52825236ba1b6c06fe60e140d6b5ea45
# EXP-Topic hgweb-cleanup
hgweb: use strict equals, remove non-breaking space in followlines.js

The first hunk had a non-breaking space character just before "{", it's not an
error or anything, but let's fix it while we're at it. (This corresponds to
"nonbsp" option of jshint).

Hunks 2 and 3 change "==" (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).

Most of this file already uses strict equals operator, and in the code affected
type coercion is not needed, because tagName and selectableTag are both strings
and endId and startId are both numbers.
Anton Shestakov - Nov. 27, 2017, 10:12 a.m.
Oops, I pressed "y" without looking at the "Cc:" prompt of patchbomb and
now there's Cc: y@mercurial-scm.org in this whole series. Sorry about
that.

Patch

diff --git a/mercurial/templates/static/followlines.js b/mercurial/templates/static/followlines.js
--- a/mercurial/templates/static/followlines.js
+++ b/mercurial/templates/static/followlines.js
@@ -13,7 +13,7 @@  document.addEventListener('DOMContentLoa
     }
     // URL to complement with "linerange" query parameter
     var targetUri = sourcelines.dataset.logurl;
-    if (typeof targetUri === 'undefined') {
+    if (typeof targetUri === 'undefined') {
         return;
     }
 
@@ -114,7 +114,7 @@  document.addEventListener('DOMContentLoa
         if (parent === null) {
             return null;
         }
-        if (element.tagName == selectableTag && parent.isSameNode(sourcelines)) {
+        if (element.tagName === selectableTag && parent.isSameNode(sourcelines)) {
             return element;
         }
         return selectableParent(parent);
@@ -182,7 +182,7 @@  document.addEventListener('DOMContentLoa
 
             // compute line range (startId, endId)
             var endId = parseInt(endElement.id.slice(1));
-            if (endId == startId) {
+            if (endId === startId) {
                 // clicked twice the same line, cancel and reset initial state
                 // (CSS, event listener for selection start)
                 removeSelectedCSSClass();