Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Use eqeqeq. (#3977)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Feb 2, 2018
1 parent eefee3d commit 35f01a4
Show file tree
Hide file tree
Showing 37 changed files with 170 additions and 169 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins:
root: true

rules:
eqeqeq: error
no-console: [error, {allow: [debug, error, info, trace, warn]}]
no-var: error
prefer-const: error
Expand Down
8 changes: 4 additions & 4 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const prefObserver = {
observe(aSubject, aTopic, aData) {
// aSubject is the nsIPrefBranch we're observing (after appropriate QI)
// aData is the name of the pref that's been changed (relative to aSubject)
if (aData == USER_DISABLE_PREF) {
if (aData === USER_DISABLE_PREF) {
// eslint-disable-next-line promise/catch-or-return
appStartupPromise = appStartupPromise.then(handleStartup);
}
Expand Down Expand Up @@ -74,7 +74,7 @@ const LibraryButton = {
if (permissionPages.length > 1) {
Cu.reportError(new Error("Should not have more than 1 permission page, but got: " + JSON.stringify(permissionPages)));
}
this.PAGE_TO_OPEN = permissionPages.length == 1 ? permissionPages[0].replace(/\*$/, "") : "https://screenshots.firefox.com/";
this.PAGE_TO_OPEN = permissionPages.length === 1 ? permissionPages[0].replace(/\*$/, "") : "https://screenshots.firefox.com/";
this.PAGE_TO_OPEN += "shots";
this.ICON_URL = webExtension.extension.getURL("icons/icon-16-v2.svg");
this.ICON_URL_2X = webExtension.extension.getURL("icons/icon-32-v2.svg");
Expand Down Expand Up @@ -194,7 +194,7 @@ function start(webExtension) {
}

function stop(webExtension, reason) {
if (reason != APP_SHUTDOWN) {
if (reason !== APP_SHUTDOWN) {
LibraryButton.uninit();
if (photonPageAction) {
photonPageAction.remove();
Expand Down Expand Up @@ -263,7 +263,7 @@ function initPhotonPageAction(api, webExtension) {

// Establish a port to the WebExtension side.
api.browser.runtime.onConnect.addListener((listenerPort) => {
if (listenerPort.name != "photonPageActionPort") {
if (listenerPort.name !== "photonPageActionPort") {
return;
}
port = listenerPort;
Expand Down
2 changes: 1 addition & 1 deletion addon/webextension/background/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ this.analytics = (function() {
if (action === 'internal') {
return Promise.resolve();
}
if (typeof label == "object" && (!options)) {
if (typeof label === "object" && (!options)) {
options = label;
label = undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions addon/webextension/background/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ this.auth = (function() {
req.open("POST", registerUrl);
req.setRequestHeader("content-type", "application/json");
req.onload = catcher.watchFunction(() => {
if (req.status == 200) {
if (req.status === 200) {
log.info("Registered login");
initialized = true;
saveAuthInfo(JSON.parse(req.responseText));
Expand Down Expand Up @@ -82,7 +82,7 @@ this.auth = (function() {
const req = new XMLHttpRequest();
req.open("POST", loginUrl);
req.onload = catcher.watchFunction(() => {
if (req.status == 404) {
if (req.status === 404) {
if (noRegister) {
resolve(false);
} else {
Expand Down
8 changes: 4 additions & 4 deletions addon/webextension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ this.main = (function() {
const event = active ? "start-shot" : "cancel-shot";
sendEvent(event, "toolbar-button", {incognito: tab.incognito});
}, (error) => {
if ((!hasSeenOnboarding) && error.popupMessage == "UNSHOOTABLE_PAGE") {
if ((!hasSeenOnboarding) && error.popupMessage === "UNSHOOTABLE_PAGE") {
sendEvent("goto-onboarding", "selection-button", {incognito: tab.incognito});
return forceOnboarding();
}
Expand Down Expand Up @@ -159,7 +159,7 @@ this.main = (function() {
return false;
}
const path = url.substr(backend.length).replace(/^\/*/, "").replace(/[?#].*/, "");
if (path == "shots") {
if (path === "shots") {
return true;
}
if (/^[^/]{1,4000}\/[^/]{1,4000}$/.test(path)) {
Expand Down Expand Up @@ -228,10 +228,10 @@ this.main = (function() {
const url = URL.createObjectURL(blob);
let downloadId;
const onChangedCallback = catcher.watchFunction(function(change) {
if (!downloadId || downloadId != change.id) {
if (!downloadId || downloadId !== change.id) {
return;
}
if (change.state && change.state.current != "in_progress") {
if (change.state && change.state.current !== "in_progress") {
URL.revokeObjectURL(url);
browser.downloads.onChanged.removeListener(onChangedCallback);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/webextension/blobConverters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ this.blobConverters = (function() {
exports.dataUrlToBlob = function(url) {
const binary = atob(url.split(',', 2)[1]);
let contentType = exports.getTypeFromDataUrl(url);
if (contentType != "image/png" && contentType != "image/jpeg") {
if (contentType !== "image/png" && contentType !== "image/jpeg") {
contentType = "image/png";
}
const data = Uint8Array.from(binary, char => char.charCodeAt(0));
Expand Down
4 changes: 2 additions & 2 deletions addon/webextension/onboarding/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ this.slides = (function() {
callbacks.onEnd();
})));
doc.querySelector("#slide-overlay").addEventListener("click", watchFunction(assertIsTrusted((event) => {
if (event.target == doc.querySelector("#slide-overlay")) {
if (event.target === doc.querySelector("#slide-overlay")) {
shooter.sendEvent("cancel-slides", "background-click");
callbacks.onEnd();
}
Expand Down Expand Up @@ -201,7 +201,7 @@ this.slides = (function() {
const slideEl = doc.querySelector("#slide-container");
for (let i = 1; i <= numberOfSlides; i++) {
const className = `active-slide-${i}`;
if (i == currentSlide) {
if (i === currentSlide) {
slideEl.classList.add(className);
} else {
slideEl.classList.remove(className);
Expand Down
10 changes: 5 additions & 5 deletions addon/webextension/selector/shooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
const canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
const ctx = canvas.getContext('2d');
let expand = window.devicePixelRatio !== 1;
if (captureType == 'fullPage' || captureType == 'fullPageTruncated') {
if (captureType === 'fullPage' || captureType === 'fullPageTruncated') {
expand = false;
canvas.width = width;
canvas.height = height;
Expand Down Expand Up @@ -79,8 +79,8 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
// isSaving indicates we're aleady in the middle of saving
// we use a timeout so in the case of a failure the button will
// still start working again
if (Math.floor(selectedPos.left) == Math.floor(selectedPos.right) ||
Math.floor(selectedPos.top) == Math.floor(selectedPos.bottom)) {
if (Math.floor(selectedPos.left) === Math.floor(selectedPos.right) ||
Math.floor(selectedPos.top) === Math.floor(selectedPos.bottom)) {
const exc = new Error("Empty selection");
exc.popupMessage = "EMPTY_SELECTION";
exc.noReport = true;
Expand Down Expand Up @@ -144,15 +144,15 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
return callBackground("openShot", { url, copied });
});
}, (error) => {
if ('popupMessage' in error && (error.popupMessage == "REQUEST_ERROR" || error.popupMessage == 'CONNECTION_ERROR')) {
if ('popupMessage' in error && (error.popupMessage === "REQUEST_ERROR" || error.popupMessage === 'CONNECTION_ERROR')) {
// The error has been signaled to the user, but unlike other errors (or
// success) we should not abort the selection
deactivateAfterFinish = false;
// We need to unhide the UI since screenshotPage() hides it.
ui.iframe.unhide();
return;
}
if (error.name != "BackgroundError") {
if (error.name !== "BackgroundError") {
// BackgroundError errors are reported in the Background page
throw error;
}
Expand Down
6 changes: 3 additions & 3 deletions addon/webextension/selector/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ this.ui = (function() { // eslint-disable-line no-unused-vars

draggerDirection(target) {
while (target) {
if (target.nodeType == document.ELEMENT_NODE) {
if (target.nodeType === document.ELEMENT_NODE) {
if (target.classList.contains("mover-target")) {
for (const name of movements) {
if (target.classList.contains("direction-" + name)) {
Expand All @@ -762,7 +762,7 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
if (target.tagName === "BUTTON") {
return false;
}
if (target.nodeType == document.ELEMENT_NODE && target.classList.contains("highlight")) {
if (target.nodeType === document.ELEMENT_NODE && target.classList.contains("highlight")) {
return true;
}
target = target.parentNode;
Expand Down Expand Up @@ -878,7 +878,7 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
if (name.startsWith("iframe")) {
continue;
}
if (typeof exports[name] == "object" && exports[name].remove) {
if (typeof exports[name] === "object" && exports[name].remove) {
exports[name].remove();
}
}
Expand Down
28 changes: 14 additions & 14 deletions addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,13 @@ this.uicontrol = (function() {
start() {
dataUrl = shooter.screenshotPage(selectedPos, captureType);
ui.iframe.usePreview();
ui.Preview.display(dataUrl, captureType == "fullPageTruncated");
ui.Preview.display(dataUrl, captureType === "fullPageTruncated");
}
};

stateHandlers.onboarding = {
start() {
if (typeof slides == "undefined") {
if (typeof slides === "undefined") {
throw new Error("Attempted to set state to onboarding without loading slides");
}
catcher.watchPromise(slides.display({
Expand Down Expand Up @@ -555,12 +555,12 @@ this.uicontrol = (function() {
evenBetterElement(node, origRect) {
let el = node.parentNode;
const ELEMENT_NODE = document.ELEMENT_NODE;
while (el && el.nodeType == ELEMENT_NODE) {
while (el && el.nodeType === ELEMENT_NODE) {
if (!el.getAttribute) {
return null;
}
const role = el.getAttribute("role");
if (role === "article" || (el.className && typeof el.className == "string" && el.className.search("tweet ") !== -1)) {
if (role === "article" || (el.className && typeof el.className === "string" && el.className.search("tweet ") !== -1)) {
const rect = Selection.getBoundingClientRect(el);
if (!rect) {
return null;
Expand Down Expand Up @@ -672,15 +672,15 @@ this.uicontrol = (function() {
return null;
}
const isGoodEl = (el) => {
if (el.nodeType != document.ELEMENT_NODE) {
if (el.nodeType !== document.ELEMENT_NODE) {
return false;
}
if (el.tagName == "IMG") {
if (el.tagName === "IMG") {
const rect = el.getBoundingClientRect();
return rect.width >= this.minAutoImageWidth && rect.height >= this.minAutoImageHeight;
}
const display = window.getComputedStyle(el).display;
if (['block', 'inline-block', 'table'].indexOf(display) != -1) {
if (['block', 'inline-block', 'table'].indexOf(display) !== -1) {
return true;
// FIXME: not sure if this is useful:
// let rect = el.getBoundingClientRect();
Expand Down Expand Up @@ -745,7 +745,7 @@ this.uicontrol = (function() {

mousedown(event) {
const target = event.target;
if (target.tagName == "HTML") {
if (target.tagName === "HTML") {
// This happens when you click on the scrollbar
return undefined;
}
Expand Down Expand Up @@ -790,7 +790,7 @@ this.uicontrol = (function() {
sendEvent("selection-resized");
ui.Box.display(selectedPos, standardDisplayCallbacks);
if (resizeHasMoved) {
if (resizeDirection == "move") {
if (resizeDirection === "move") {
const startPos = new Pos(resizeStartSelected.left, resizeStartSelected.top);
const endPos = new Pos(selectedPos.left, selectedPos.top);
sendEvent(
Expand All @@ -801,7 +801,7 @@ this.uicontrol = (function() {
"resize-selection", "mouseup",
eventOptionsForResize(resizeStartSelected, selectedPos));
}
} else if (resizeDirection == "move") {
} else if (resizeDirection === "move") {
sendEvent("keep-resize-selection", "mouseup");
} else {
sendEvent("keep-move-selection", "mouseup");
Expand All @@ -815,14 +815,14 @@ this.uicontrol = (function() {
const movement = movements[resizeDirection];
if (movement[0]) {
let moveX = movement[0];
moveX = moveX == "*" ? ["x1", "x2"] : [moveX];
moveX = moveX === "*" ? ["x1", "x2"] : [moveX];
for (const moveDir of moveX) {
selectedPos[moveDir] = util.truncateX(resizeStartSelected[moveDir] + diffX);
}
}
if (movement[1]) {
let moveY = movement[1];
moveY = moveY == "*" ? ["y1", "y2"] : [moveY];
moveY = moveY === "*" ? ["y1", "y2"] : [moveY];
for (const moveDir of moveY) {
selectedPos[moveDir] = util.truncateY(resizeStartSelected[moveDir] + diffY);
}
Expand Down Expand Up @@ -909,7 +909,7 @@ this.uicontrol = (function() {
}

function isFrameset() {
return document.body.tagName == "FRAMESET";
return document.body.tagName === "FRAMESET";
}

exports.deactivate = function() {
Expand Down Expand Up @@ -943,7 +943,7 @@ this.uicontrol = (function() {
function addHandlers() {
["mouseup", "mousedown", "mousemove", "click"].forEach((eventName) => {
const fn = watchFunction(assertIsTrusted((function(eventName, event) {
if (typeof event.button == "number" && event.button !== 0) {
if (typeof event.button === "number" && event.button !== 0) {
// Not a left click
return undefined;
}
Expand Down
6 changes: 3 additions & 3 deletions addon/webextension/selector/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ this.util = (function() { // eslint-disable-line no-unused-vars
// Partially outside the box
for (let i = 0; i < el.childNodes.length; i++) {
const child = el.childNodes[i];
if (child.nodeType == ELEMENT_NODE) {
if (child.nodeType === ELEMENT_NODE) {
traverse(child);
}
}
Expand All @@ -72,9 +72,9 @@ this.util = (function() { // eslint-disable-line no-unused-vars
}
function addText(el) {
let t;
if (el.tagName == "IMG") {
if (el.tagName === "IMG") {
t = el.getAttribute("alt") || el.getAttribute("title");
} else if (el.tagName == "A") {
} else if (el.tagName === "A") {
t = el.innerText;
if (el.getAttribute("href") && !el.getAttribute("href").startsWith("#")) {
t += " (" + el.href + ")";
Expand Down
6 changes: 3 additions & 3 deletions addon/webextension/sitehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ this.sitehelper = (function() {


function sendCustomEvent(name, detail) {
if (typeof detail == "object") {
if (typeof detail === "object") {
// Note sending an object can lead to security problems, while a string
// is safe to transfer:
detail = JSON.stringify(detail);
Expand All @@ -33,7 +33,7 @@ this.sitehelper = (function() {

// This is a very minimal attempt to verify that the XMLHttpRequest object we got
// is legitimate. It is not a good test.
if (Object.toString.apply(ContentXMLHttpRequest) != "function XMLHttpRequest() {\n [native code]\n}") {
if (Object.toString.apply(ContentXMLHttpRequest) !== "function XMLHttpRequest() {\n [native code]\n}") {
console.warn("Insecure copy of XMLHttpRequest");
return;
}
Expand All @@ -44,7 +44,7 @@ this.sitehelper = (function() {
}
req.send("");
req.onload = () => {
if (req.status != 200) {
if (req.status !== 200) {
console.warn("Attempt to set Screenshots cookie via /api/set-login-cookie failed:", req.status, req.statusText, req.responseText);
}
};
Expand Down
2 changes: 1 addition & 1 deletion server/src/ab-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Test {
}
if (excludes.includes("*")) {
for (const testName in tests) {
if (testName != this.name && tests[testName].value !== "exclude") {
if (testName !== this.name && tests[testName].value !== "exclude") {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/browser-send-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let sentEvent = false;

if (typeof window != "undefined" && window.sendEvent) {
if (typeof window !== "undefined" && window.sendEvent) {
module.exports = window.sendEvent;
} else {
module.exports = function() {
Expand Down
4 changes: 2 additions & 2 deletions server/src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ exports.insert = function(sql, args) {
return true;
}).catch(err => {
done();
if (err.code == '23505') {
if (err.code === '23505') {
// constraint error, duplicate key
return false;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ function initTiming() {
return doNothing;
}
const caller = getCallerPosition(2);
if (caller == "skip") {
if (caller === "skip") {
// This happens when getCallerPosition detects we shouldn't time this function call
return doNothing;
}
Expand Down
Loading

0 comments on commit 35f01a4

Please sign in to comment.