eslint: Enable arrow-body-style.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-01 16:41:40 -07:00 committed by Tim Abbott
parent aa838ec4bc
commit 615b7fcc2c
46 changed files with 226 additions and 435 deletions

View File

@ -17,6 +17,7 @@
"rules": { "rules": {
"array-callback-return": "error", "array-callback-return": "error",
"array-bracket-spacing": "error", "array-bracket-spacing": "error",
"arrow-body-style": "error",
"arrow-parens": "error", "arrow-parens": "error",
"arrow-spacing": [ "error", { "before": true, "after": true } ], "arrow-spacing": [ "error", { "before": true, "after": true } ],
"block-scoped-var": "error", "block-scoped-var": "error",

View File

@ -62,9 +62,7 @@ run_test("initialize", () => {
}; };
}; };
$("#payment-method").data = (key) => { $("#payment-method").data = (key) => document.querySelector("#payment-method").getAttribute("data-" + key);
return document.querySelector("#payment-method").getAttribute("data-" + key);
};
jquery_init(); jquery_init();

View File

@ -102,9 +102,7 @@ run_test('create_ajax_request', () => {
}; };
$("#autopay-form").serializeArray = () => { $("#autopay-form").serializeArray = () => jquery("#autopay-form").serializeArray();
return jquery("#autopay-form").serializeArray();
};
$.post = ({url, data, success, error}) => { $.post = ({url, data, success, error}) => {
assert.equal(state.form_input_section_hide, 1); assert.equal(state.form_input_section_hide, 1);

View File

@ -183,9 +183,7 @@ run_test('find_li w/force_render', () => {
assert.equal(li, stub_li); assert.equal(li, stub_li);
assert(shown); assert(shown);
buddy_list.get_li_from_key = () => { buddy_list.get_li_from_key = () => ({length: 0});
return {length: 0};
};
const undefined_li = buddy_list.find_li({ const undefined_li = buddy_list.find_li({
key: 'not-there', key: 'not-there',

View File

@ -1706,7 +1706,7 @@ run_test('nonexistent_stream_reply_error', () => {
}); });
run_test('narrow_button_titles', () => { run_test('narrow_button_titles', () => {
util.is_mobile = () => { return false; }; util.is_mobile = () => false;
compose.update_closed_compose_buttons_for_private(); compose.update_closed_compose_buttons_for_private();
assert.equal($("#left_bar_compose_stream_button_big").text(), i18n.t("New stream message")); assert.equal($("#left_bar_compose_stream_button_big").text(), i18n.t("New stream message"));

View File

@ -4,9 +4,7 @@ set_global('$', global.make_zjquery());
const noop = () => {}; const noop = () => {};
const _list_render = { const _list_render = {
create: () => { create: () => ({ init: noop }),
return { init: noop };
},
}; };
set_global('list_render', _list_render); set_global('list_render', _list_render);

View File

@ -152,9 +152,7 @@ function test_helper() {
assert_events: (expected_events) => { assert_events: (expected_events) => {
assert.deepEqual(expected_events, events); assert.deepEqual(expected_events, events);
}, },
get_narrow_terms: () => { get_narrow_terms: () => narrow_terms,
return narrow_terms;
},
}; };
} }

View File

@ -13,11 +13,9 @@ set_global('ui_util', {
place_caret_at_end: noop, place_caret_at_end: noop,
}); });
set_global('getSelection', () => { set_global('getSelection', () => ({
return {
anchorOffset: 0, anchorOffset: 0,
}; }));
});
let id_seq = 0; let id_seq = 0;
run_test('set_up_ids', () => { run_test('set_up_ids', () => {
@ -240,20 +238,16 @@ run_test('arrows on pills', () => {
let next_focused = false; let next_focused = false;
const pill_stub = { const pill_stub = {
prev: () => { prev: () => ({
return {
focus: () => { focus: () => {
prev_focused = true; prev_focused = true;
}, },
}; }),
}, next: () => ({
next: () => {
return {
focus: () => { focus: () => {
next_focused = true; next_focused = true;
}, },
}; }),
},
}; };
container.set_find_results('.pill:focus', pill_stub); container.set_find_results('.pill:focus', pill_stub);
@ -282,13 +276,11 @@ run_test('left arrow on input', () => {
let last_pill_focused = false; let last_pill_focused = false;
container.set_find_results('.pill', { container.set_find_results('.pill', {
last: () => { last: () => ({
return {
focus: () => { focus: () => {
last_pill_focused = true; last_pill_focused = true;
}, },
}; }),
},
}); });
key_handler({ key_handler({
@ -498,14 +490,12 @@ run_test('exit button on pill', () => {
}; };
const exit_button_stub = { const exit_button_stub = {
to_$: () => { to_$: () => ({
return {
closest: (sel) => { closest: (sel) => {
assert.equal(sel, '.pill'); assert.equal(sel, '.pill');
return curr_pill_stub; return curr_pill_stub;
}, },
}; }),
},
}; };
const e = { const e = {
@ -538,14 +528,12 @@ run_test('misc things', () => {
let shake_class_removed = false; let shake_class_removed = false;
const input_stub = { const input_stub = {
to_$: () => { to_$: () => ({
return {
removeClass: (cls) => { removeClass: (cls) => {
assert.equal(cls, 'shake'); assert.equal(cls, 'shake');
shake_class_removed = true; shake_class_removed = true;
}, },
}; }),
},
}; };
animation_end_handler.call(input_stub); animation_end_handler.call(input_stub);

View File

@ -59,9 +59,7 @@ run_test('single item list', () => {
cursor.adjust_scroll = () => {}; cursor.adjust_scroll = () => {};
conf.list.find_li = () => { conf.list.find_li = () => li_stub;
return li_stub;
};
cursor.go_to(valid_key); cursor.go_to(valid_key);

View File

@ -198,9 +198,7 @@ run_test('filtering', () => {
const opts = { const opts = {
filter: { filter: {
element: search_input, element: search_input,
predicate: (item, value) => { predicate: (item, value) => item.includes(value),
return item.includes(value);
},
}, },
modifier: (item) => div(item), modifier: (item) => div(item),
}; };
@ -294,9 +292,7 @@ function sort_button(opts) {
addClass: (cls) => { addClass: (cls) => {
classList.add(cls); classList.add(cls);
}, },
hasClass: (cls) => { hasClass: (cls) => classList.has(cls),
return classList.has(cls);
},
removeClass: (cls) => { removeClass: (cls) => {
classList.delete(cls); classList.delete(cls);
}, },
@ -332,11 +328,7 @@ run_test('wire up filter element', () => {
const opts = { const opts = {
filter: { filter: {
filterer: (list, value) => { filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)),
return list.filter((item) => {
return item.toLowerCase().includes(value);
});
},
element: filter_element, element: filter_element,
}, },
modifier: (s) => '(' + s + ')', modifier: (s) => '(' + s + ')',
@ -372,9 +364,7 @@ run_test('sorting', () => {
const opts = { const opts = {
name: 'sorting-list', name: 'sorting-list',
parent_container: sort_container, parent_container: sort_container,
modifier: (item) => { modifier: (item) => div(item.name) + div(item.salary),
return div(item.name) + div(item.salary);
},
filter: { filter: {
predicate: () => true, predicate: () => true,
}, },
@ -698,9 +688,7 @@ run_test('opts.get_item', () => {
['one', 'two', 'three', 'four'] ['one', 'two', 'three', 'four']
); );
const predicate = (item, value) => { const predicate = (item, value) => item.startsWith(value);
return item.startsWith(value);
};
const predicate_opts = { const predicate_opts = {
get_item: (n) => items[n], get_item: (n) => items[n],
@ -719,11 +707,7 @@ run_test('opts.get_item', () => {
const filterer_opts = { const filterer_opts = {
get_item: (n) => items[n], get_item: (n) => items[n],
filter: { filter: {
filterer: (items, value) => { filterer: (items, value) => items.filter((item) => predicate(item, value)),
return items.filter((item) => {
return predicate(item, value);
});
},
}, },
}; };
@ -821,9 +805,7 @@ run_test('render item', () => {
let rendering_item = false; let rendering_item = false;
const widget_3 = list_render.create(container, list, { const widget_3 = list_render.create(container, list, {
name: 'replace-list', name: 'replace-list',
modifier: (item) => { modifier: (item) => rendering_item ? undefined : `${item}\n`,
return rendering_item ? undefined : `${item}\n`;
},
get_item: get_item, get_item: get_item,
html_selector: (item) => `tr[data-item='${item}']`, html_selector: (item) => `tr[data-item='${item}']`,
}); });

View File

@ -18,9 +18,7 @@ const with_overrides = global.with_overrides; // make lint happy
function accept_all_filter() { function accept_all_filter() {
const filter = { const filter = {
predicate: () => { predicate: () => () => true,
return () => true;
},
}; };
return filter; return filter;

View File

@ -150,16 +150,14 @@ run_test('basics', () => {
const row = { const row = {
length: 1, length: 1,
offset: () => { return {top: 25}; }, offset: () => ({top: 25}),
}; };
current_msg_list.selected_id = () => { return -1; }; current_msg_list.selected_id = () => -1;
current_msg_list.get_row = () => { return row; }; current_msg_list.get_row = () => row;
message_list.all = { message_list.all = {
all_messages: () => { all_messages: () => messages,
return messages;
},
get: (msg_id) => { get: (msg_id) => {
assert.equal(msg_id, selected_id); assert.equal(msg_id, selected_id);
return selected_message; return selected_message;
@ -170,12 +168,8 @@ run_test('basics', () => {
}, },
}, },
empty: () => false, empty: () => false,
first: () => { first: () => ({id: 900}),
return {id: 900}; last: () => ({id: 1100}),
},
last: () => {
return {id: 1100};
},
}; };
let cont; let cont;
@ -214,9 +208,9 @@ run_test('basics', () => {
'tab_bar.initialize', 'tab_bar.initialize',
]); ]);
current_msg_list.selected_id = () => { return -1; }; current_msg_list.selected_id = () => -1;
current_msg_list.get_row = () => { return row; }; current_msg_list.get_row = () => row;
util.sorted_ids = () => { return []; }; util.sorted_ids = () => [];
narrow.activate([{ operator: 'is', operand: 'private' }], { narrow.activate([{ operator: 'is', operand: 'private' }], {
then_select_id: selected_id, then_select_id: selected_id,

View File

@ -855,9 +855,7 @@ run_test('get_people_for_search_bar', () => {
assert.equal(big_results.length, 20); assert.equal(big_results.length, 20);
message_store.user_ids = () => { message_store.user_ids = () => [1001, 1002, 1003, 1004, 1005, 1006];
return [1001, 1002, 1003, 1004, 1005, 1006];
};
const small_results = people.get_people_for_search_bar('Jones'); const small_results = people.get_people_for_search_bar('Jones');
@ -1126,13 +1124,11 @@ run_test('get_visible_email', function () {
}); });
run_test('get_active_message_people', function () { run_test('get_active_message_people', function () {
message_store.user_ids = () => { message_store.user_ids = () => [
return [
steven.user_id, steven.user_id,
maria.user_id, maria.user_id,
alice1.user_id, alice1.user_id,
]; ];
};
people.add_active_user(steven); people.add_active_user(steven);
people.add_active_user(maria); people.add_active_user(maria);

View File

@ -10,9 +10,7 @@ set_global('stream_popover', {
set_global('unread', {}); set_global('unread', {});
set_global('unread_ui', {}); set_global('unread_ui', {});
set_global('vdom', { set_global('vdom', {
render: () => { render: () => 'fake-dom-for-pm-list',
return 'fake-dom-for-pm-list';
},
}); });
set_global('pm_list_dom', {}); set_global('pm_list_dom', {});
@ -196,14 +194,12 @@ run_test('get_active_user_ids_string', () => {
undefined); undefined);
function set_filter_result(emails) { function set_filter_result(emails) {
narrow_state.filter = () => { narrow_state.filter = () => ({
return {
operands: (operand) => { operands: (operand) => {
assert.equal(operand, 'pm-with'); assert.equal(operand, 'pm-with');
return emails; return emails;
}, },
}; });
};
} }
set_filter_result([]); set_filter_result([]);
@ -224,14 +220,12 @@ run_test('is_all_privates', () => {
pm_list.is_all_privates(), pm_list.is_all_privates(),
false); false);
narrow_state.filter = () => { narrow_state.filter = () => ({
return {
operands: (operand) => { operands: (operand) => {
assert.equal(operand, 'is'); assert.equal(operand, 'is');
return ['private', 'starred']; return ['private', 'starred'];
}, },
}; });
};
assert.equal( assert.equal(
pm_list.is_all_privates(), pm_list.is_all_privates(),
@ -240,9 +234,7 @@ run_test('is_all_privates', () => {
function with_fake_list(f) { function with_fake_list(f) {
const orig = pm_list._build_private_messages_list; const orig = pm_list._build_private_messages_list;
pm_list._build_private_messages_list = () => { pm_list._build_private_messages_list = () => 'PM_LIST_CONTENTS';
return 'PM_LIST_CONTENTS';
};
f(); f();
pm_list._build_private_messages_list = orig; pm_list._build_private_messages_list = orig;
} }

View File

@ -63,11 +63,9 @@ const me = {
}; };
const target = $.create('click target'); const target = $.create('click target');
target.offset = () => { target.offset = () => ({
return {
top: 10, top: 10,
}; });
};
const e = { const e = {
stopPropagation: noop, stopPropagation: noop,
@ -87,14 +85,12 @@ function make_image_stubber() {
function stub_image() { function stub_image() {
const image = {}; const image = {};
image.to_$ = () => { image.to_$ = () => ({
return {
on: (name, f) => { on: (name, f) => {
assert.equal(name, "load"); assert.equal(name, "load");
image.load_f = f; image.load_f = f;
}, },
}; });
};
images.push(image); images.push(image);
return image; return image;
} }

View File

@ -4,12 +4,8 @@ let next_id = 0;
const messages = []; const messages = [];
set_global('message_util', { set_global('message_util', {
get_messages_in_topic: (stream_id, topic) => { get_messages_in_topic: (stream_id, topic) => messages.filter((x) => x.stream_id === stream_id &&
return messages.filter((x) => { x.topic.toLowerCase() === topic.toLowerCase()),
return x.stream_id === stream_id &&
x.topic.toLowerCase() === topic.toLowerCase();
});
},
}); });
run_test('process_message_for_senders', () => { run_test('process_message_for_senders', () => {

View File

@ -8,46 +8,36 @@ set_global('hashchange', {
exit_overlay: noop, exit_overlay: noop,
}); });
set_global('stream_data', { set_global('stream_data', {
get_sub_by_id: () => { get_sub_by_id: () => ({
return {
color: "", color: "",
invite_only: false, invite_only: false,
is_web_public: true, is_web_public: true,
}; }),
}, is_muted: () =>
is_muted: () => {
// We only test via muted topics for now. // We only test via muted topics for now.
// TODO: Make muted streams and test them. // TODO: Make muted streams and test them.
return false; false
}, ,
}); });
set_global('overlays', { set_global('overlays', {
open_overlay: (opts) => { open_overlay: (opts) => {
overlays.close_callback = opts.on_close; overlays.close_callback = opts.on_close;
}, },
recent_topics_open: () => { recent_topics_open: () => true,
return true;
},
}); });
set_global('people', { set_global('people', {
is_my_user_id: function (id) { is_my_user_id: function (id) {
return id === 1; return id === 1;
}, },
sender_info_with_small_avatar_urls_for_sender_ids: (ids) => { sender_info_with_small_avatar_urls_for_sender_ids: (ids) => ids,
return ids;
},
}); });
set_global('XDate', zrequire('XDate', 'xdate')); set_global('XDate', zrequire('XDate', 'xdate'));
set_global('timerender', { set_global('timerender', {
last_seen_status_from_date: () => { last_seen_status_from_date: () => "Just now",
return "Just now"; get_full_datetime: () => ({
},
get_full_datetime: () => {
return {
date: "date", date: "date",
time: "time", time: "time",
}; }),
},
}); });
set_global('unread', { set_global('unread', {
unread_topic_counter: { unread_topic_counter: {
@ -61,15 +51,11 @@ set_global('unread', {
}, },
}); });
set_global('hash_util', { set_global('hash_util', {
by_stream_uri: () => { by_stream_uri: () => "https://www.example.com",
return "https://www.example.com"; by_stream_topic_uri: () => "https://www.example.com",
},
by_stream_topic_uri: () => {
return "https://www.example.com";
},
}); });
set_global('recent_senders', { set_global('recent_senders', {
get_topic_recent_senders: () => { return [1, 2]; }, get_topic_recent_senders: () => [1, 2],
}); });
set_global('list_render', { set_global('list_render', {
modifier: noop, modifier: noop,
@ -93,9 +79,7 @@ set_global('list_render', {
return list_render; return list_render;
}, },
hard_redraw: noop, hard_redraw: noop,
render_item: (item) => { render_item: (item) => list_render.modifier(item),
return list_render.modifier(item);
},
}); });
// Custom Data // Custom Data
@ -142,9 +126,7 @@ set_global('message_list', {
}, },
}); });
set_global('message_store', { set_global('message_store', {
get: (msg_id) => { get: (msg_id) => messages[msg_id - 1],
return messages[msg_id - 1];
},
}); });
let id = 0; let id = 0;

View File

@ -9,9 +9,7 @@ run_test('basics', () => {
bar: schema.check_string, bar: schema.check_string,
}; };
const check_rec = (val) => { const check_rec = (val) => schema.check_record('my_rec', val, fields);
return schema.check_record('my_rec', val, fields);
};
assert.equal( assert.equal(
check_rec({foo: 'apple', bar: 'banana'}), check_rec({foo: 'apple', bar: 'banana'}),
@ -38,9 +36,7 @@ run_test('basics', () => {
'in my_rec bar is not a string' 'in my_rec bar is not a string'
); );
const check_array = (val) => { const check_array = (val) => schema.check_array('lst', val, schema.check_string);
return schema.check_array('lst', val, schema.check_string);
};
assert.equal( assert.equal(
check_array(['foo', 'bar']), check_array(['foo', 'bar']),

View File

@ -73,22 +73,18 @@ run_test('scroll_element_into_container', () => {
const elem1 = { const elem1 = {
innerHeight: () => 25, innerHeight: () => 25,
position: () => { position: () => ({
return {
top: 0, top: 0,
}; }),
},
}; };
scroll_util.scroll_element_into_container(elem1, container); scroll_util.scroll_element_into_container(elem1, container);
assert.equal(container.scrollTop(), 3); assert.equal(container.scrollTop(), 3);
const elem2 = { const elem2 = {
innerHeight: () => 15, innerHeight: () => 15,
position: () => { position: () => ({
return {
top: 250, top: 250,
}; }),
},
}; };
scroll_util.scroll_element_into_container(elem2, container); scroll_util.scroll_element_into_container(elem2, container);
assert.equal(container.scrollTop(), 250 - 100 + 3 + 15); assert.equal(container.scrollTop(), 250 - 100 + 3 + 15);

View File

@ -155,9 +155,7 @@ run_test('initialize', () => {
assert.deepEqual(raw_operators, operators); assert.deepEqual(raw_operators, operators);
assert.deepEqual(options, {trigger: 'search'}); assert.deepEqual(options, {trigger: 'search'});
}; };
search_pill.get_search_string_for_current_filter = () => { search_pill.get_search_string_for_current_filter = () => search_box_val;
return search_box_val;
};
}; };
operators = [{ operators = [{
@ -230,9 +228,7 @@ run_test('initialize', () => {
assert.deepEqual(raw_operators, operators); assert.deepEqual(raw_operators, operators);
assert.deepEqual(options, {trigger: 'search'}); assert.deepEqual(options, {trigger: 'search'});
}; };
search_pill.get_search_string_for_current_filter = () => { search_pill.get_search_string_for_current_filter = () => search_box_val;
return search_box_val;
};
}; };
operators = [{ operators = [{
@ -277,9 +273,7 @@ run_test('initialize', () => {
}; };
const search_pill_stub = $.create('.pill'); const search_pill_stub = $.create('.pill');
search_pill_stub.closest = () => { search_pill_stub.closest = () => ({ data: noop });
return { data: noop };
};
const stub_event = { const stub_event = {
relatedTarget: search_pill_stub, relatedTarget: search_pill_stub,
}; };

View File

@ -387,11 +387,9 @@ run_test('group_suggestions', () => {
function message(user_ids, timestamp) { function message(user_ids, timestamp) {
return { return {
type: 'private', type: 'private',
display_recipient: user_ids.map((id) => { display_recipient: user_ids.map((id) => ({
return {
id: id, id: id,
}; })),
}),
timestamp: timestamp, timestamp: timestamp,
}; };
} }

View File

@ -390,11 +390,9 @@ run_test('group_suggestions', () => {
function message(user_ids, timestamp) { function message(user_ids, timestamp) {
return { return {
type: 'private', type: 'private',
display_recipient: user_ids.map((id) => { display_recipient: user_ids.map((id) => ({
return {
id: id, id: id,
}; })),
}),
timestamp: timestamp, timestamp: timestamp,
}; };
} }

View File

@ -116,9 +116,7 @@ function set_up() {
$('#config_inputbox').children = () => { $('#config_inputbox').children = () => {
const mock_children = { const mock_children = {
hide: () => { hide: () => {},
return;
},
}; };
return mock_children; return mock_children;
}; };

View File

@ -57,9 +57,7 @@ const _realm_logo = {
}; };
const _list_render = { const _list_render = {
create: () => { create: () => ({ init: noop }),
return { init: noop };
},
}; };
set_global('channel', _channel); set_global('channel', _channel);
@ -221,25 +219,19 @@ function test_submit_settings_form(submit_form) {
let stubs = createSaveButtons(subsection); let stubs = createSaveButtons(subsection);
let save_button = stubs.save_button; let save_button = stubs.save_button;
save_button.attr('id', `org-submit-${subsection}`); save_button.attr('id', `org-submit-${subsection}`);
save_button.replace = () => { save_button.replace = () => `${subsection}`;
return `${subsection}`;
};
$("#id_realm_waiting_period_threshold").val(10); $("#id_realm_waiting_period_threshold").val(10);
const invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy"); const invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
invite_to_stream_policy_elem.val('1'); invite_to_stream_policy_elem.val('1');
invite_to_stream_policy_elem.attr("id", 'id_realm_invite_to_stream_policy'); invite_to_stream_policy_elem.attr("id", 'id_realm_invite_to_stream_policy');
invite_to_stream_policy_elem.data = () => { invite_to_stream_policy_elem.data = () => "number";
return "number";
};
const create_stream_policy_elem = $("#id_realm_create_stream_policy"); const create_stream_policy_elem = $("#id_realm_create_stream_policy");
create_stream_policy_elem.val('2'); create_stream_policy_elem.val('2');
create_stream_policy_elem.attr("id", 'id_realm_create_stream_policy'); create_stream_policy_elem.attr("id", 'id_realm_create_stream_policy');
create_stream_policy_elem.data = () => { create_stream_policy_elem.data = () => "number";
return "number";
};
const add_emoji_by_admins_only_elem = $("#id_realm_add_emoji_by_admins_only"); const add_emoji_by_admins_only_elem = $("#id_realm_add_emoji_by_admins_only");
add_emoji_by_admins_only_elem.val("by_anyone"); add_emoji_by_admins_only_elem.val("by_anyone");
@ -248,15 +240,11 @@ function test_submit_settings_form(submit_form) {
const bot_creation_policy_elem = $("#id_realm_bot_creation_policy"); const bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
bot_creation_policy_elem.val("1"); bot_creation_policy_elem.val("1");
bot_creation_policy_elem.attr('id', 'id_realm_bot_creation_policy'); bot_creation_policy_elem.attr('id', 'id_realm_bot_creation_policy');
bot_creation_policy_elem.data = () => { bot_creation_policy_elem.data = () => "number";
return "number";
};
const email_address_visibility_elem = $("#id_realm_email_address_visibility"); const email_address_visibility_elem = $("#id_realm_email_address_visibility");
email_address_visibility_elem.val("1"); email_address_visibility_elem.val("1");
email_address_visibility_elem.attr('id', 'id_realm_email_address_visibility'); email_address_visibility_elem.attr('id', 'id_realm_email_address_visibility');
email_address_visibility_elem.data = () => { email_address_visibility_elem.data = () => "number";
return "number";
};
let subsection_elem = $(`#org-${subsection}`); let subsection_elem = $(`#org-${subsection}`);
subsection_elem.closest = () => subsection_elem; subsection_elem.closest = () => subsection_elem;
@ -290,15 +278,11 @@ function test_submit_settings_form(submit_form) {
const realm_default_language_elem = $("#id_realm_default_language"); const realm_default_language_elem = $("#id_realm_default_language");
realm_default_language_elem.val("en"); realm_default_language_elem.val("en");
realm_default_language_elem.attr('id', 'id_realm_default_language'); realm_default_language_elem.attr('id', 'id_realm_default_language');
realm_default_language_elem.data = () => { realm_default_language_elem.data = () => "string";
return "string";
};
const realm_default_twenty_four_hour_time_elem = $("#id_realm_default_twenty_four_hour_time"); const realm_default_twenty_four_hour_time_elem = $("#id_realm_default_twenty_four_hour_time");
realm_default_twenty_four_hour_time_elem.val('true'); realm_default_twenty_four_hour_time_elem.val('true');
realm_default_twenty_four_hour_time_elem.attr('id', 'id_realm_default_twenty_four_hour_time'); realm_default_twenty_four_hour_time_elem.attr('id', 'id_realm_default_twenty_four_hour_time');
realm_default_twenty_four_hour_time_elem.data = () => { realm_default_twenty_four_hour_time_elem.data = () => "boolean";
return "boolean";
};
subsection_elem = $(`#org-${subsection}`); subsection_elem = $(`#org-${subsection}`);
subsection_elem.closest = () => subsection_elem; subsection_elem.closest = () => subsection_elem;
@ -732,11 +716,9 @@ function test_discard_changes_button(discard_changes) {
run_test('set_up', () => { run_test('set_up', () => {
const callbacks = {}; const callbacks = {};
const set_callback = (name) => { const set_callback = (name) => (f) => {
return (f) => {
callbacks[name] = f; callbacks[name] = f;
}; };
};
const verify_realm_domains = simulate_realm_domains_table(); const verify_realm_domains = simulate_realm_domains_table();
page_params.realm_available_video_chat_providers = { page_params.realm_available_video_chat_providers = {
@ -784,12 +766,10 @@ run_test('set_up', () => {
}; };
const dropdown_list_widget_backup = dropdown_list_widget; const dropdown_list_widget_backup = dropdown_list_widget;
window.dropdown_list_widget = () => { window.dropdown_list_widget = () => ({
return {
render: noop, render: noop,
update: noop, update: noop,
}; });
};
$("#id_realm_message_content_edit_limit_minutes").set_parent($.create('<stub edit limit parent>')); $("#id_realm_message_content_edit_limit_minutes").set_parent($.create('<stub edit limit parent>'));
$("#id_realm_message_content_delete_limit_minutes").set_parent($.create('<stub delete limit parent>')); $("#id_realm_message_content_delete_limit_minutes").set_parent($.create('<stub delete limit parent>'));
$("#id_realm_message_retention_days").set_parent($.create('<stub retention period parent>')); $("#id_realm_message_retention_days").set_parent($.create('<stub retention period parent>'));
@ -1018,9 +998,7 @@ run_test('misc', () => {
dropdown_list_parent.set_find_results('.dropdown_list_reset_button:not([disabled])', $.create('<disable button>')); dropdown_list_parent.set_find_results('.dropdown_list_reset_button:not([disabled])', $.create('<disable button>'));
widget_settings.forEach((name) => { widget_settings.forEach((name) => {
const elem = $.create(`#${name}_widget #${name}_name`); const elem = $.create(`#${name}_widget #${name}_name`);
elem.closest = () => { elem.closest = () => dropdown_list_parent;
return dropdown_list_parent;
};
}); });
// We do not define any settings we need in page_params yet, but we don't need to for this test. // We do not define any settings we need in page_params yet, but we don't need to for this test.

View File

@ -1075,7 +1075,7 @@ run_test('all_topics_in_cache', () => {
message_list.all.data.add_messages(messages); message_list.all.data.add_messages(messages);
assert.equal(stream_data.all_topics_in_cache(sub), false); assert.equal(stream_data.all_topics_in_cache(sub), false);
message_list.all.data.fetch_status.has_found_newest = () => {return true;}; message_list.all.data.fetch_status.has_found_newest = () => true;
assert.equal(stream_data.all_topics_in_cache(sub), true); assert.equal(stream_data.all_topics_in_cache(sub), true);
sub.first_message_id = 0; sub.first_message_id = 0;

View File

@ -718,9 +718,7 @@ run_test('refresh_pin', () => {
const li_stub = $.create('li stub'); const li_stub = $.create('li stub');
li_stub.length = 0; li_stub.length = 0;
global.stub_templates(() => { global.stub_templates(() => ({to_$: () => li_stub}));
return {to_$: () => li_stub};
});
stream_list.update_count_in_dom = noop; stream_list.update_count_in_dom = noop;
$('#stream_filters').append = noop; $('#stream_filters').append = noop;

View File

@ -92,9 +92,7 @@ run_test('is_complete_for_stream_id', () => {
has_found_newest: () => true, has_found_newest: () => true,
}, },
}, },
first: () => { first: () => ({id: 5}),
return {id: 5};
},
}; };
assert.equal( assert.equal(
@ -102,9 +100,7 @@ run_test('is_complete_for_stream_id', () => {
true); true);
// Now simulate a more recent message id. // Now simulate a more recent message id.
message_list.all.first = () => { message_list.all.first = () => ({id: sub.first_message_id + 1});
return {id: sub.first_message_id + 1};
};
// Note that we'll return `true` here due to // Note that we'll return `true` here due to
// fetched_stream_ids having the stream_id now. // fetched_stream_ids having the stream_id now.

View File

@ -80,9 +80,7 @@ run_test('get_list_info unreads', () => {
// Going forward, we just stub get_recent_topic_names // Going forward, we just stub get_recent_topic_names
// for simpler test setup. // for simpler test setup.
stream_topic_history.get_recent_topic_names = () => { stream_topic_history.get_recent_topic_names = () => _.range(15).map((i) => 'topic ' + i);
return _.range(15).map((i) => 'topic ' + i);
};
const unread_cnt = new Map(); const unread_cnt = new Map();
unread.num_unread_for_topic = (stream_id, topic_name) => { unread.num_unread_for_topic = (stream_id, topic_name) => {

View File

@ -88,17 +88,11 @@ run_test("initialize", () => {
assert.equal(schedule, "monthly"); assert.equal(schedule, "monthly");
}; };
$('input[type=radio][name=license_management]:checked').val = () => { $('input[type=radio][name=license_management]:checked').val = () => document.querySelector("input[type=radio][name=license_management]:checked").value;
return document.querySelector("input[type=radio][name=license_management]:checked").value;
};
$('input[type=radio][name=schedule]:checked').val = () => { $('input[type=radio][name=schedule]:checked').val = () => document.querySelector("input[type=radio][name=schedule]:checked").value;
return document.querySelector("input[type=radio][name=schedule]:checked").value;
};
$("#autopay-form").data = (key) => { $("#autopay-form").data = (key) => document.querySelector("#autopay-form").getAttribute("data-" + key);
return document.querySelector("#autopay-form").getAttribute("data-" + key);
};
jquery_init(); jquery_init();
@ -110,16 +104,12 @@ run_test("initialize", () => {
const invoice_click_handler = $('#invoice-button').get_on_handler('click'); const invoice_click_handler = $('#invoice-button').get_on_handler('click');
const request_sponsorship_click_handler = $('#sponsorship-button').get_on_handler('click'); const request_sponsorship_click_handler = $('#sponsorship-button').get_on_handler('click');
helpers.is_valid_input = () => { helpers.is_valid_input = () => true;
return true;
};
add_card_click_handler(e); add_card_click_handler(e);
invoice_click_handler(e); invoice_click_handler(e);
helpers.is_valid_input = () => { helpers.is_valid_input = () => false;
return false;
};
add_card_click_handler(e); add_card_click_handler(e);
invoice_click_handler(e); invoice_click_handler(e);

View File

@ -436,23 +436,17 @@ run_test('uppy_events', () => {
on: (event_name, callback) => { on: (event_name, callback) => {
callbacks[event_name] = callback; callbacks[event_name] = callback;
}, },
getFiles: () => { getFiles: () => [...files],
return [...files];
},
removeFile: (file_id) => { removeFile: (file_id) => {
files = files.filter((file) => { files = files.filter((file) => file.id !== file_id);
return file.id !== file_id;
});
}, },
getState: () => { getState: () => ({
return {
info: { info: {
type: state.type, type: state.type,
details: state.details, details: state.details,
message: state.message, message: state.message,
}, },
}; }),
},
}; };
} }
uppy_stub.Plugin = plugin_stub; uppy_stub.Plugin = plugin_stub;

View File

@ -102,13 +102,9 @@ run_test('attribute updates', () => {
}); });
function make_child(i, name) { function make_child(i, name) {
const render = () => { const render = () => '<li>' + name + '</li>';
return '<li>' + name + '</li>';
};
const eq = (other) => { const eq = (other) => name === other.name;
return name === other.name;
};
return { return {
key: i, key: i,
@ -207,10 +203,8 @@ run_test('partial updates', () => {
let patched_html; let patched_html;
find = () => { find = () => ({
return { children: () => ({
children: () => {
return {
eq: (i) => { eq: (i) => {
assert.equal(i, 0); assert.equal(i, 0);
return { return {
@ -219,10 +213,8 @@ run_test('partial updates', () => {
}, },
}; };
}, },
}; }),
}, });
};
};
const new_nodes = make_children([1, 2, 3]); const new_nodes = make_children([1, 2, 3]);
new_nodes[0] = make_child(1, 'modified1'); new_nodes[0] = make_child(1, 'modified1');

View File

@ -212,8 +212,8 @@ run_test('extensions', () => {
// using direct syntax: // using direct syntax:
const rect = $.create('rectangle'); const rect = $.create('rectangle');
rect.width = () => { return 5; }; rect.width = () => 5;
rect.height = () => { return 7; }; rect.height = () => 7;
assert.equal(rect.width(), 5); assert.equal(rect.width(), 5);
assert.equal(rect.height(), 7); assert.equal(rect.height(), 7);

View File

@ -17,9 +17,7 @@ const _ = global._;
// Create a helper function to avoid sneaky delays in tests. // Create a helper function to avoid sneaky delays in tests.
function immediate(f) { function immediate(f) {
return () => { return () => f();
return f();
};
} }
// Find the files we need to run. // Find the files we need to run.

View File

@ -165,12 +165,10 @@ class MarkdownComparer {
function returnComparer() { function returnComparer() {
if (!_markdownComparerInstance) { if (!_markdownComparerInstance) {
_markdownComparerInstance = new MarkdownComparer((actual, expected) => { _markdownComparerInstance = new MarkdownComparer((actual, expected) => [
return [
"Actual and expected output do not match. Showing diff", "Actual and expected output do not match. Showing diff",
mdiff.diff_strings(actual, expected), mdiff.diff_strings(actual, expected),
].join('\n'); ].join('\n'));
});
} }
return _markdownComparerInstance; return _markdownComparerInstance;
} }

View File

@ -19,9 +19,9 @@ function apply_color(input_string, changes) {
input_string = input_string.slice(2); input_string = input_string.slice(2);
const formatter = new Map([ const formatter = new Map([
["delete", (string) => { return "\u001b[31m" + string + "\u001b[0m"; }], ["delete", (string) => "\u001b[31m" + string + "\u001b[0m"],
["insert", (string) => { return "\u001b[32m" + string + "\u001b[0m"; }], ["insert", (string) => "\u001b[32m" + string + "\u001b[0m"],
["replace", (string) => { return "\u001b[33m" + string + "\u001b[0m"; }], ["replace", (string) => "\u001b[33m" + string + "\u001b[0m"],
]); ]);
changes.forEach((change) => { changes.forEach((change) => {
if (formatter.has(change.tag)) { if (formatter.has(change.tag)) {
@ -114,9 +114,7 @@ function diff_strings(string_0, string_1) {
} }
}); });
const emphasize_codes = (string) => { const emphasize_codes = (string) => "\u001b[34m" + string.slice(0, 1) + "\u001b[0m" + string.slice(1);
return "\u001b[34m" + string.slice(0, 1) + "\u001b[0m" + string.slice(1);
};
output_lines = output_lines.map(emphasize_codes); output_lines = output_lines.map(emphasize_codes);
return output_lines.join("\n"); return output_lines.join("\n");

View File

@ -75,9 +75,7 @@ exports.make_zblueslip = function () {
} }
}; };
lib.get_test_logs = (name) => { lib.get_test_logs = (name) => lib.test_logs[name];
return lib.test_logs[name];
};
// Create logging functions // Create logging functions
for (const name of names) { for (const name of names) {
@ -113,13 +111,9 @@ exports.make_zblueslip = function () {
return ex.message; return ex.message;
}; };
lib.start_timing = () => { lib.start_timing = () => () => {};
return () => {};
};
lib.preview_node = (node) => { lib.preview_node = (node) => 'node:' + node;
return 'node:' + node;
};
return lib; return lib;
}; };

View File

@ -916,9 +916,7 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
const error_area = $("#compose_invite_users"); const error_area = $("#compose_invite_users");
const existing_invites_area = $('#compose_invite_users .compose_invite_user'); const existing_invites_area = $('#compose_invite_users .compose_invite_user');
const existing_invites = Array.from($(existing_invites_area), (user_row) => { const existing_invites = Array.from($(existing_invites_area), (user_row) => parseInt($(user_row).data('user-id'), 10));
return parseInt($(user_row).data('user-id'), 10);
});
if (!existing_invites.includes(user_id)) { if (!existing_invites.includes(user_id)) {
const context = { const context = {

View File

@ -442,13 +442,9 @@ exports.get_pm_people = function (query) {
exports.get_person_suggestions = function (query, opts) { exports.get_person_suggestions = function (query, opts) {
query = typeahead.clean_query_lowercase(query); query = typeahead.clean_query_lowercase(query);
const person_matcher = (item) => { const person_matcher = (item) => exports.query_matches_person(query, item);
return exports.query_matches_person(query, item);
};
const group_matcher = (item) => { const group_matcher = (item) => query_matches_name_description(query, item);
return query_matches_name_description(query, item);
};
function filter_persons(all_persons) { function filter_persons(all_persons) {
let persons; let persons;

View File

@ -665,9 +665,7 @@ Filter.prototype = {
}, },
_fix_redundant_is_private: function (terms) { _fix_redundant_is_private: function (terms) {
const is_pm_with = (term) => { const is_pm_with = (term) => Filter.term_type(term) === 'pm-with';
return Filter.term_type(term) === 'pm-with';
};
if (!terms.some(is_pm_with)) { if (!terms.some(is_pm_with)) {
return terms; return terms;

View File

@ -45,9 +45,7 @@ exports.get_filtered_items = (value, list, opts) => {
return opts.filter.filterer(list, value); return opts.filter.filterer(list, value);
} }
const predicate = (item) => { const predicate = (item) => opts.filter.predicate(item, value);
return opts.filter.predicate(item, value);
};
if (get_item) { if (get_item) {
const result = []; const result = [];
@ -65,8 +63,7 @@ exports.get_filtered_items = (value, list, opts) => {
return list.filter(predicate); return list.filter(predicate);
}; };
exports.alphabetic_sort = (prop) => { exports.alphabetic_sort = (prop) => function (a, b) {
return function (a, b) {
// The conversion to uppercase helps make the sorting case insensitive. // The conversion to uppercase helps make the sorting case insensitive.
const str1 = a[prop].toUpperCase(); const str1 = a[prop].toUpperCase();
const str2 = b[prop].toUpperCase(); const str2 = b[prop].toUpperCase();
@ -78,11 +75,9 @@ exports.alphabetic_sort = (prop) => {
} }
return -1; return -1;
};
}; };
exports.numeric_sort = (prop) => { exports.numeric_sort = (prop) => function (a, b) {
return function (a, b) {
if (parseFloat(a[prop]) > parseFloat(b[prop])) { if (parseFloat(a[prop]) > parseFloat(b[prop])) {
return 1; return 1;
} else if (parseFloat(a[prop]) === parseFloat(b[prop])) { } else if (parseFloat(a[prop]) === parseFloat(b[prop])) {
@ -90,7 +85,6 @@ exports.numeric_sort = (prop) => {
} }
return -1; return -1;
};
}; };
exports.valid_filter_opts = (opts) => { exports.valid_filter_opts = (opts) => {

View File

@ -49,11 +49,9 @@ exports.get_messages_in_topic = function (stream_id, topic) {
// all the messages. Please only use it in case of // all the messages. Please only use it in case of
// very rare events like topic edits. Its primary // very rare events like topic edits. Its primary
// use case is the new experimental Recent Topics UI. // use case is the new experimental Recent Topics UI.
return message_list.all.all_messages().filter((x) => { return message_list.all.all_messages().filter((x) => x.type === 'stream' &&
return x.type === 'stream' &&
x.stream_id === stream_id && x.stream_id === stream_id &&
x.topic.toLowerCase() === topic.toLowerCase(); x.topic.toLowerCase() === topic.toLowerCase());
});
}; };
window.message_util = exports; window.message_util = exports;

View File

@ -1,13 +1,9 @@
const render_pm_list_item = require('../templates/pm_list_item.hbs'); const render_pm_list_item = require('../templates/pm_list_item.hbs');
exports.keyed_pm_li = (convo) => { exports.keyed_pm_li = (convo) => {
const render = () => { const render = () => render_pm_list_item(convo);
return render_pm_list_item(convo);
};
const eq = (other) => { const eq = (other) => _.isEqual(convo, other.convo);
return _.isEqual(convo, other.convo);
};
const key = convo.user_ids_string; const key = convo.user_ids_string;

View File

@ -114,7 +114,7 @@ exports.get_topic_recent_senders = function (stream_id, topic) {
} }
const sorted_senders = Array.from(sender_message_ids.entries()).sort( const sorted_senders = Array.from(sender_message_ids.entries()).sort(
(s1, s2) => { return s1[1] - s2[1]; } (s1, s2) => s1[1] - s2[1]
); );
const recent_senders = []; const recent_senders = [];
for (const item of sorted_senders) { for (const item of sorted_senders) {

View File

@ -558,7 +558,7 @@ exports.init_dropdown_widgets = () => {
exports.save_discard_widget_status_handler($(`#org-notifications`)); exports.save_discard_widget_status_handler($(`#org-notifications`));
}, },
default_text: i18n.t("Disabled"), default_text: i18n.t("Disabled"),
render_text: (x) => {return `#${x}`;}, render_text: (x) => `#${x}`,
null_value: -1, null_value: -1,
}; };
exports.notifications_stream_widget = dropdown_list_widget( exports.notifications_stream_widget = dropdown_list_widget(
@ -575,12 +575,10 @@ exports.init_dropdown_widgets = () => {
notification_stream_options)); notification_stream_options));
exports.default_code_language_widget = dropdown_list_widget({ exports.default_code_language_widget = dropdown_list_widget({
widget_name: 'realm_default_code_block_language', widget_name: 'realm_default_code_block_language',
data: Object.keys(pygments_data.langs).map((x) => { data: Object.keys(pygments_data.langs).map((x) => ({
return {
name: x, name: x,
value: x, value: x,
}; })),
}),
value: page_params.realm_default_code_block_language, value: page_params.realm_default_code_block_language,
on_update: () => { on_update: () => {
exports.save_discard_widget_status_handler($(`#org-other-settings`)); exports.save_discard_widget_status_handler($(`#org-other-settings`));

View File

@ -55,13 +55,9 @@ exports.zoom_out = function () {
}; };
exports.keyed_topic_li = (convo) => { exports.keyed_topic_li = (convo) => {
const render = () => { const render = () => render_topic_list_item(convo);
return render_topic_list_item(convo);
};
const eq = (other) => { const eq = (other) => _.isEqual(convo, other.convo);
return _.isEqual(convo, other.convo);
};
const key = 't:' + convo.topic_name; const key = 't:' + convo.topic_name;
@ -74,16 +70,12 @@ exports.keyed_topic_li = (convo) => {
}; };
exports.more_li = (more_topics_unreads) => { exports.more_li = (more_topics_unreads) => {
const render = () => { const render = () => render_more_topics({
return render_more_topics({
more_topics_unreads: more_topics_unreads, more_topics_unreads: more_topics_unreads,
}); });
};
const eq = (other) => { const eq = (other) => other.more_items &&
return other.more_items &&
more_topics_unreads === other.more_topics_unreads; more_topics_unreads === other.more_topics_unreads;
};
const key = 'more'; const key = 'more';
@ -97,13 +89,9 @@ exports.more_li = (more_topics_unreads) => {
}; };
exports.spinner_li = () => { exports.spinner_li = () => {
const render = () => { const render = () => render_more_topics_spinner();
return render_more_topics_spinner();
};
const eq = (other) => { const eq = (other) => other.spinner;
return other.spinner;
};
const key = 'more'; const key = 'more';

View File

@ -16,12 +16,10 @@ exports.eq_array = (a, b, eq) => {
return a.every((item, i) => eq(item, b[i])); return a.every((item, i) => eq(item, b[i]));
}; };
exports.ul = (opts) => { exports.ul = (opts) => ({
return {
tag_name: 'ul', tag_name: 'ul',
opts: opts, opts: opts,
}; });
};
exports.render_tag = (tag) => { exports.render_tag = (tag) => {
/* /*