blueslip: Apply ESLint.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-10-28 15:39:19 -07:00 committed by Tim Abbott
parent 8fd51a0ab5
commit 87b23720f5
2 changed files with 37 additions and 30 deletions

View File

@ -1,3 +1,10 @@
static/js/blueslip.js # This is intended for generated files and vendored third-party files.
static/webpack-bundles # For our source code, instead of adding files here, consider using
static/js/js_typings/zulip/index.d.ts # specific eslint-disable comments in the files themselves.
/docs/_build
/static/generated
/static/third
/static/webpack-bundles
/var
/zulip-py3-venv

View File

@ -36,11 +36,10 @@ Logger.prototype = (function () {
pad(now.getUTCMilliseconds(), 3) + ' UTC'; pad(now.getUTCMilliseconds(), 3) + ' UTC';
var str_args = _.map(arguments, function (x) { var str_args = _.map(arguments, function (x) {
if (typeof(x) === 'object') { if (typeof x === 'object') {
return JSON.stringify(x); return JSON.stringify(x);
} else {
return x;
} }
return x;
}); });
var log_entry = date_str + " " + name.toUpperCase() + var log_entry = date_str + " " + name.toUpperCase() +
@ -62,12 +61,12 @@ Logger.prototype = (function () {
var proto = { var proto = {
get_log: function Logger_get_log() { get_log: function Logger_get_log() {
return this._memory_log; return this._memory_log;
} },
}; };
var methods = ['debug', 'log', 'info', 'warn', 'error']; var methods = ['debug', 'log', 'info', 'warn', 'error'];
var i; var i;
for (i = 0; i < methods.length; i++) { for (i = 0; i < methods.length; i += 1) {
proto[methods[i]] = make_logger_func(methods[i]); proto[methods[i]] = make_logger_func(methods[i]);
} }
@ -98,10 +97,9 @@ function report_error(msg, stack, opts) {
var key = ':' + msg + stack; var key = ':' + msg + stack;
if (reported_errors.hasOwnProperty(key) if (reported_errors.hasOwnProperty(key)
|| (last_report_attempt.hasOwnProperty(key) || last_report_attempt.hasOwnProperty(key)
// Only try to report a given error once every 5 minutes // Only try to report a given error once every 5 minutes
&& (Date.now() - last_report_attempt[key] <= 60 * 5 * 1000))) && Date.now() - last_report_attempt[key] <= 60 * 5 * 1000) {
{
return; return;
} }
@ -112,18 +110,20 @@ function report_error(msg, stack, opts) {
// elegant thing to do in that case is to either wait until that // elegant thing to do in that case is to either wait until that
// setup is done or do it ourselves and then retry. // setup is done or do it ourselves and then retry.
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/json/report/error', url: '/json/report/error',
dataType: 'json', dataType: 'json',
data: { message: msg, data: {
stacktrace: stack, message: msg,
ui_message: opts.show_ui_msg, stacktrace: stack,
more_info: JSON.stringify(opts.more_info), ui_message: opts.show_ui_msg,
href: window.location.href, more_info: JSON.stringify(opts.more_info),
user_agent: window.navigator.userAgent, href: window.location.href,
log: logger.get_log().join("\n")}, user_agent: window.navigator.userAgent,
timeout: 3*1000, log: logger.get_log().join("\n"),
success: function () { },
timeout: 3 * 1000,
success: function () {
reported_errors[key] = true; reported_errors[key] = true;
if (opts.show_ui_msg && ui_report !== undefined) { if (opts.show_ui_msg && ui_report !== undefined) {
// There are a few races here (and below in the error // There are a few races here (and below in the error
@ -158,7 +158,7 @@ function report_error(msg, stack, opts) {
"Please try reloading the page.", "Please try reloading the page.",
$("#home-error"), "alert-error"); $("#home-error"), "alert-error");
} }
} },
}); });
if (page_params.save_stacktraces) { if (page_params.save_stacktraces) {
@ -217,22 +217,22 @@ function build_arg_list(msg, more_info) {
return args; return args;
} }
exports.debug = function blueslip_debug (msg, more_info) { exports.debug = function blueslip_debug(msg, more_info) {
var args = build_arg_list(msg, more_info); var args = build_arg_list(msg, more_info);
logger.debug.apply(logger, args); logger.debug.apply(logger, args);
}; };
exports.log = function blueslip_log (msg, more_info) { exports.log = function blueslip_log(msg, more_info) {
var args = build_arg_list(msg, more_info); var args = build_arg_list(msg, more_info);
logger.log.apply(logger, args); logger.log.apply(logger, args);
}; };
exports.info = function blueslip_info (msg, more_info) { exports.info = function blueslip_info(msg, more_info) {
var args = build_arg_list(msg, more_info); var args = build_arg_list(msg, more_info);
logger.info.apply(logger, args); logger.info.apply(logger, args);
}; };
exports.warn = function blueslip_warn (msg, more_info) { exports.warn = function blueslip_warn(msg, more_info) {
var args = build_arg_list(msg, more_info); var args = build_arg_list(msg, more_info);
logger.warn.apply(logger, args); logger.warn.apply(logger, args);
if (page_params.debug_mode) { if (page_params.debug_mode) {
@ -240,7 +240,7 @@ exports.warn = function blueslip_warn (msg, more_info) {
} }
}; };
exports.error = function blueslip_error (msg, more_info, stack) { exports.error = function blueslip_error(msg, more_info, stack) {
if (stack === undefined) { if (stack === undefined) {
stack = Error().stack; stack = Error().stack;
} }
@ -253,7 +253,7 @@ exports.error = function blueslip_error (msg, more_info, stack) {
} }
}; };
exports.fatal = function blueslip_fatal (msg, more_info) { exports.fatal = function blueslip_fatal(msg, more_info) {
report_error(msg, Error().stack, {more_info: more_info}); report_error(msg, Error().stack, {more_info: more_info});
throw new BlueslipError(msg, more_info); throw new BlueslipError(msg, more_info);
}; };
@ -276,7 +276,7 @@ exports.preview_node = function (node) {
(className ? " class='" + className + "'" : "") + (className ? " class='" + className + "'" : "") +
"></" + tag + ">"; "></" + tag + ">";
return node_preview; return node_preview;
}; };
window.blueslip = exports; window.blueslip = exports;