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

Commit

Permalink
Replace var with let or const. (#3977)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Feb 2, 2018
1 parent ed632d6 commit 6824d8b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ root: true

rules:
no-console: [error, {allow: [debug, error, info, trace, warn]}]
no-var: off # TODO: change to "error"
no-var: error
prefer-const: off # TODO: change to "error"
quotes: [off, double] # TODO: change to "error"

Expand Down
11 changes: 6 additions & 5 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"use strict";

// eslint-disable-next-line no-var
var global = this;

this.selectorLoader = (function() {
Expand Down Expand Up @@ -62,7 +63,7 @@ this.selectorLoader = (function() {
});
};

let loadingTabs = new Set();
const loadingTabs = new Set();

exports.loadModules = function(tabId, hasSeenOnboarding) {
loadingTabs.add(tabId);
Expand Down Expand Up @@ -91,7 +92,7 @@ this.selectorLoader = (function() {
return communication.sendToBootstrap("isHistoryEnabled").then((historyEnabled) => {
return communication.sendToBootstrap("isUploadDisabled").then((uploadDisabled) => {
return browser.tabs.get(tabId).then(tab => {
let downloadOnly = !historyEnabled || uploadDisabled || tab.incognito;
const downloadOnly = !historyEnabled || uploadDisabled || tab.incognito;
return browser.tabs.executeScript(tabId, {
// Note: `window` here refers to a global accessible to content
// scripts, but not the scripts in the underlying page. For more
Expand Down Expand Up @@ -130,12 +131,12 @@ this.selectorLoader = (function() {

exports.unloadModules = function() {
const watchFunction = catcher.watchFunction;
let allScripts = standardScripts.concat(onboardingScripts).concat(selectorScripts);
const allScripts = standardScripts.concat(onboardingScripts).concat(selectorScripts);
const moduleNames = allScripts.map((filename) =>
filename.replace(/^.*\//, "").replace(/\.js$/, ""));
moduleNames.reverse();
for (let moduleName of moduleNames) {
let moduleObj = global[moduleName];
for (const moduleName of moduleNames) {
const moduleObj = global[moduleName];
if (moduleObj && moduleObj.unload) {
try {
watchFunction(moduleObj.unload)();
Expand Down
2 changes: 1 addition & 1 deletion addon/webextension/background/takeshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ this.takeshot = (function() {

/** Combines two buffers or Uint8Array's */
function concatBuffers(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
Expand Down
1 change: 1 addition & 0 deletions addon/webextension/catcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

// eslint-disable-next-line no-var
var global = this;

this.catcher = (function() {
Expand Down
6 changes: 3 additions & 3 deletions addon/webextension/makeUuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ this.makeUuid = (function() {
// generates a v4 UUID
return function makeUuid() { // eslint-disable-line no-unused-vars
// get sixteen unsigned 8 bit random values
var randomValues = window
const randomValues = window
.crypto
.getRandomValues(new Uint8Array(36));

return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var i = Array.prototype.slice.call(arguments).slice(-2)[0]; // grab the `offset` parameter
var r = randomValues[i] % 16|0, v = c === 'x' ? r : (r & 0x3 | 0x8);
const i = Array.prototype.slice.call(arguments).slice(-2)[0]; // grab the `offset` parameter
const r = randomValues[i] % 16|0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
Expand Down
2 changes: 1 addition & 1 deletion addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ this.uicontrol = (function() {
let xpos = Math.floor(10 * (event.pageX - window.innerWidth / 2) / window.innerWidth);
let ypos = Math.floor(10 * (event.pageY - window.innerHeight / 2) / window.innerHeight)

for (var i = 0; i < 2; i++) {
for (let i = 0; i < 2; i++) {
let move = `translate(${xpos}px, ${ypos}px)`;
event.target.getElementsByClassName('eyeball')[i].style.transform = move;
}
Expand Down
14 changes: 7 additions & 7 deletions addon/webextension/selector/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ this.util = (function() { // eslint-disable-line no-unused-vars
};

// Pixels of wiggle the captured region gets in captureSelectedText:
var CAPTURE_WIGGLE = 10;
const CAPTURE_WIGGLE = 10;
const ELEMENT_NODE = document.ELEMENT_NODE;

exports.captureEnclosedText = function(box) {
var scrollX = window.scrollX;
var scrollY = window.scrollY;
var text = [];
const scrollX = window.scrollX;
const scrollY = window.scrollY;
const text = [];
function traverse(el) {
var elBox = el.getBoundingClientRect();
let elBox = el.getBoundingClientRect();
elBox = {
top: elBox.top + scrollY,
bottom: elBox.bottom + scrollY,
Expand All @@ -60,8 +60,8 @@ this.util = (function() { // eslint-disable-line no-unused-vars
elBox.right > box.right + CAPTURE_WIGGLE ||
elBox.left < box.left - CAPTURE_WIGGLE) {
// Partially outside the box
for (var i = 0; i < el.childNodes.length; i++) {
var child = el.childNodes[i];
for (let i = 0; i < el.childNodes.length; i++) {
let child = el.childNodes[i];
if (child.nodeType == ELEMENT_NODE) {
traverse(child);
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const envc = require("envc");
// files as a side effect. See `https://npmjs.org/envc` for more info.
envc({booleans: true});

var conf = convict({
const conf = convict({
port: {
doc: "The Screenshots server port",
format: "port",
Expand Down
2 changes: 1 addition & 1 deletion server/src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ exports.exec = function(sql, args) {

exports.markersForArgs = function(starting, numberOfArgs) {
let result = [];
for (var i = starting; i < starting + numberOfArgs; i++) {
for (let i = starting; i < starting + numberOfArgs; i++) {
result.push("$" + i);
}
return result.join(", ");
Expand Down
2 changes: 1 addition & 1 deletion server/src/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.installConsoleHandler = function() {
return function() {
let msg = "";
let stack = undefined;
for (var i = 0; i < arguments.length; i++) {
for (let i = 0; i < arguments.length; i++) {
let arg = arguments[i];
if (msg) {
msg += " ";
Expand Down
6 changes: 3 additions & 3 deletions server/src/servershot.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if (!config.useS3) {
get = (uid, contentType) => {
return new Promise((resolve, reject) => {
s3bucket.createBucket(() => {
var params = {Key: uid};
const params = {Key: uid};
s3bucket.getObject(params, function(err, data) {
if (err) {
mozlog.error("error-downloading-data", {err});
Expand All @@ -131,7 +131,7 @@ if (!config.useS3) {
put = (uid, body, comment) => {
return new Promise((resolve, reject) => {
s3bucket.createBucket(() => {
var params = {Key: uid, Body: body, ContentType: "image/png"};
const params = {Key: uid, Body: body, ContentType: "image/png"};
s3bucket.upload(params, function(err, result) {
if (err) {
reject(err);
Expand All @@ -147,7 +147,7 @@ if (!config.useS3) {
del = (uid) => {
return new Promise((resolve, reject) => {
s3bucket.createBucket(() => {
var params = {Key: uid};
const params = {Key: uid};
s3bucket.deleteObject(params, function(err, result) {
if (err) {
reject(err);
Expand Down
4 changes: 2 additions & 2 deletions shared/shot.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class AbstractShot {
asJson() {
let result = {};
for (let attr of this.REGULAR_ATTRS) {
var val = this[attr];
let val = this[attr];
if (val && val.asJson) {
val = val.asJson();
}
Expand All @@ -321,7 +321,7 @@ class AbstractShot {
asRecallJson() {
let result = {clips: {}};
for (let attr of this.RECALL_ATTRS) {
var val = this[attr];
let val = this[attr];
if (val && val.asJson) {
val = val.asJson();
}
Expand Down
24 changes: 11 additions & 13 deletions static/js/UITour-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ https://github.com/raw/mozilla/gecko-dev/f2a1911ad310bf8651f342d719e4
/* eslint valid-jsdoc: ["error", { "requireReturn": false }] */

// create namespace
if (typeof Mozilla == "undefined") {
var Mozilla = {};
}
let Mozilla = Mozilla || {};

(function($) {
"use strict";
Expand All @@ -34,7 +32,7 @@ if (typeof Mozilla == "undefined") {
Mozilla.UITour = {};
}

var themeIntervalId = null;
let themeIntervalId = null;
function _stopCyclingThemes() {
if (themeIntervalId) {
clearInterval(themeIntervalId);
Expand All @@ -43,7 +41,7 @@ if (typeof Mozilla == "undefined") {
}

function _sendEvent(action, data) {
var event = new CustomEvent("mozUITour", {
let event = new CustomEvent("mozUITour", {
bubbles: true,
detail: {
action,
Expand All @@ -59,7 +57,7 @@ if (typeof Mozilla == "undefined") {
}

function _waitForCallback(callback) {
var id = _generateCallbackID();
let id = _generateCallbackID();

function listener(event) {
if (typeof event.detail != "object")
Expand All @@ -75,7 +73,7 @@ if (typeof Mozilla == "undefined") {
return id;
}

var notificationListener = null;
let notificationListener = null;
function _notificationListener(event) {
if (typeof event.detail != "object")
return;
Expand Down Expand Up @@ -144,7 +142,7 @@ if (typeof Mozilla == "undefined") {
* @since 35
*/
Mozilla.UITour.ping = function(callback) {
var data = {};
let data = {};
if (callback) {
data.callbackID = _waitForCallback(callback);
}
Expand Down Expand Up @@ -272,9 +270,9 @@ if (typeof Mozilla == "undefined") {
* Mozilla.UITour.showInfo('appMenu', 'my title', 'my text', icon, buttons, options);
*/
Mozilla.UITour.showInfo = function(target, title, text, icon, buttons, options) {
var buttonData = [];
let buttonData = [];
if (Array.isArray(buttons)) {
for (var i = 0; i < buttons.length; i++) {
for (let i = 0; i < buttons.length; i++) {
buttonData.push({
label: buttons[i].label,
icon: buttons[i].icon,
Expand All @@ -284,7 +282,7 @@ if (typeof Mozilla == "undefined") {
}
}

var closeButtonCallbackID, targetCallbackID;
let closeButtonCallbackID, targetCallbackID;
if (options && options.closeButtonCallback)
closeButtonCallbackID = _waitForCallback(options.closeButtonCallback);
if (options && options.targetCallback)
Expand Down Expand Up @@ -376,7 +374,7 @@ if (typeof Mozilla == "undefined") {
}

function nextTheme() {
var theme = themes.shift();
let theme = themes.shift();
themes.push(theme);

_sendEvent("previewTheme", {
Expand Down Expand Up @@ -420,7 +418,7 @@ if (typeof Mozilla == "undefined") {
* });
*/
Mozilla.UITour.showMenu = function(name, callback) {
var showCallbackID;
let showCallbackID;
if (callback)
showCallbackID = _waitForCallback(callback);

Expand Down

0 comments on commit 6824d8b

Please sign in to comment.