lint: Replace local variables named 'msgid' with 'message_id'.

Follow up of commit 2a1305d. Replace all local variables named 'msgid'
with 'message_id' in all JS and HTML files, and adds a linter rule for
it as well.

Resolves #12952.
This commit is contained in:
Vinit Singh 2019-08-28 21:16:10 +05:30 committed by Tim Abbott
parent c6fb8c048a
commit d09a80260b
8 changed files with 28 additions and 26 deletions

View File

@ -714,7 +714,7 @@ exports.register_click_handlers = function () {
}); });
$("body").on("click", ".actions_popover .reaction_button", function (e) { $("body").on("click", ".actions_popover .reaction_button", function (e) {
var msgid = $(e.currentTarget).data('message-id'); var message_id = $(e.currentTarget).data('message-id');
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
// HACK: Because we need the popover to be based off an // HACK: Because we need the popover to be based off an
@ -723,7 +723,7 @@ exports.register_click_handlers = function () {
// element is not present, we use the message's // element is not present, we use the message's
// .fa-chevron-down element as the base for the popover. // .fa-chevron-down element as the base for the popover.
var elem = $(".selected_message .actions_hover")[0]; var elem = $(".selected_message .actions_hover")[0];
emoji_picker.toggle_emoji_popover(elem, msgid); emoji_picker.toggle_emoji_popover(elem, message_id);
}); });
$("body").on("click", ".emoji-popover-tab-item", function (e) { $("body").on("click", ".emoji-popover-tab-item", function (e) {

View File

@ -704,24 +704,24 @@ exports.reify_message_id = function (opts) {
// update that link as well // update that link as well
_.each($('#out-of-view-notification a'), function (e) { _.each($('#out-of-view-notification a'), function (e) {
var elem = $(e); var elem = $(e);
var msgid = elem.data('msgid'); var message_id = elem.data('message-id');
if (msgid === old_id) { if (message_id === old_id) {
elem.data('msgid', new_id); elem.data('message-id', new_id);
} }
}); });
}; };
exports.register_click_handlers = function () { exports.register_click_handlers = function () {
$('#out-of-view-notification').on('click', '.compose_notification_narrow_by_topic', function (e) { $('#out-of-view-notification').on('click', '.compose_notification_narrow_by_topic', function (e) {
var msgid = $(e.currentTarget).data('msgid'); var message_id = $(e.currentTarget).data('message-id');
narrow.by_topic(msgid, {trigger: 'compose_notification'}); narrow.by_topic(message_id, {trigger: 'compose_notification'});
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });
$('#out-of-view-notification').on('click', '.compose_notification_scroll_to_message', function (e) { $('#out-of-view-notification').on('click', '.compose_notification_scroll_to_message', function (e) {
var msgid = $(e.currentTarget).data('msgid'); var message_id = $(e.currentTarget).data('message-id');
current_msg_list.select_id(msgid); current_msg_list.select_id(message_id);
navigate.scroll_to_selected(); navigate.scroll_to_selected();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();

View File

@ -901,8 +901,8 @@ exports.register_click_handlers = function () {
}); });
$('body').on('click', '.reminder_button', function (e) { $('body').on('click', '.reminder_button', function (e) {
var msgid = $(e.currentTarget).data('message-id'); var message_id = $(e.currentTarget).data('message-id');
popovers.render_actions_remind_popover($(".selected_message .actions_hover")[0], msgid); popovers.render_actions_remind_popover($(".selected_message .actions_hover")[0], message_id);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });
@ -967,8 +967,8 @@ exports.register_click_handlers = function () {
e.preventDefault(); e.preventDefault();
}); });
$('body').on('click', '.popover_toggle_collapse', function (e) { $('body').on('click', '.popover_toggle_collapse', function (e) {
var msgid = $(e.currentTarget).data('message-id'); var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(msgid); var row = current_msg_list.get_row(message_id);
var message = current_msg_list.get(rows.id(row)); var message = current_msg_list.get(rows.id(row));
popovers.hide_actions_popover(); popovers.hide_actions_popover();
@ -985,16 +985,16 @@ exports.register_click_handlers = function () {
e.preventDefault(); e.preventDefault();
}); });
$('body').on('click', '.popover_edit_message', function (e) { $('body').on('click', '.popover_edit_message', function (e) {
var msgid = $(e.currentTarget).data('message-id'); var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(msgid); var row = current_msg_list.get_row(message_id);
popovers.hide_actions_popover(); popovers.hide_actions_popover();
message_edit.start(row); message_edit.start(row);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });
$('body').on('click', '.view_edit_history', function (e) { $('body').on('click', '.view_edit_history', function (e) {
var msgid = $(e.currentTarget).data('msgid'); var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(msgid); var row = current_msg_list.get_row(message_id);
var message = current_msg_list.get(rows.id(row)); var message = current_msg_list.get(rows.id(row));
var message_history_cancel_btn = $('#message-history-cancel'); var message_history_cancel_btn = $('#message-history-cancel');
@ -1026,9 +1026,9 @@ exports.register_click_handlers = function () {
}); });
$('body').on('click', '.delete_message', function (e) { $('body').on('click', '.delete_message', function (e) {
var msgid = $(e.currentTarget).data('message-id'); var message_id = $(e.currentTarget).data('message-id');
popovers.hide_actions_popover(); popovers.hide_actions_popover();
message_edit.delete_message(msgid); message_edit.delete_message(message_id);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });

View File

@ -91,8 +91,8 @@ exports.schedule_message = function (request) {
transmit.send_message(request, success, error); transmit.send_message(request, success, error);
}; };
exports.do_set_reminder_for_message = function (msgid, timestamp) { exports.do_set_reminder_for_message = function (message_id, timestamp) {
var row = $("[zid='" + msgid + "']"); var row = $("[zid='" + message_id + "']");
function error() { function error() {
row.find(".alert-msg") row.find(".alert-msg")
.text(i18n.t("Reminder not set!")) .text(i18n.t("Reminder not set!"))
@ -103,7 +103,7 @@ exports.do_set_reminder_for_message = function (msgid, timestamp) {
}); });
} }
var message = current_msg_list.get(msgid); var message = current_msg_list.get(message_id);
if (!message.raw_content) { if (!message.raw_content) {
var msg_list = current_msg_list; var msg_list = current_msg_list;
@ -113,7 +113,7 @@ exports.do_set_reminder_for_message = function (msgid, timestamp) {
success: function (data) { success: function (data) {
if (current_msg_list === msg_list) { if (current_msg_list === msg_list) {
message.raw_content = data.raw_content; message.raw_content = data.raw_content;
exports.do_set_reminder_for_message(msgid, timestamp); exports.do_set_reminder_for_message(message_id, timestamp);
} }
}, },
error: error, error: error,

View File

@ -42,7 +42,7 @@ function message_hover(message_row) {
!message.status_message) { !message.status_message) {
message_row.find(".edit_content").html('<i class="fa fa-pencil edit_content_button" aria-hidden="true" title="Edit (e)"></i>'); message_row.find(".edit_content").html('<i class="fa fa-pencil edit_content_button" aria-hidden="true" title="Edit (e)"></i>');
} else { } else {
message_row.find(".edit_content").html('<i class="fa fa-file-text-o edit_content_button" aria-hidden="true" title="View source (e)" data-msgid="' + id + '"></i>'); message_row.find(".edit_content").html('<i class="fa fa-file-text-o edit_content_button" aria-hidden="true" title="View source (e)" data-message-id="' + id + '"></i>');
} }
} }

View File

@ -45,7 +45,7 @@
{{#if should_display_edit_history_option}} {{#if should_display_edit_history_option}}
<li> <li>
<a href="#" class="view_edit_history" data-msgid="{{message_id}}"> <a href="#" class="view_edit_history" data-message-id="{{message_id}}">
<i class="fa fa-clock-o" aria-hidden="true"></i> <i class="fa fa-clock-o" aria-hidden="true"></i>
{{t "View edit history" }} {{t "View edit history" }}
</a> </a>

View File

@ -1,5 +1,5 @@
{{! Content of sent-message notifications }} {{! Content of sent-message notifications }}
<div class="compose-notifications-content"> <div class="compose-notifications-content">
{{note}} {{#if link_class}}<a href="#" class="{{link_class}}" data-msgid="{{link_msg_id}}">{{link_text}}</a>{{/if}} {{note}} {{#if link_class}}<a href="#" class="{{link_class}}" data-message-id="{{link_msg_id}}">{{link_text}}</a>{{/if}}
<button type="button" class="out-of-view-notification-close close">&times;</button> <button type="button" class="out-of-view-notification-close close">&times;</button>
</div> </div>

View File

@ -119,6 +119,8 @@ js_rules = RuleList(
'bad_lines': ['subject="foo"', ' MAX_SUBJECT_LEN']}, 'bad_lines': ['subject="foo"', ' MAX_SUBJECT_LEN']},
{'pattern': r'[^_]function\(', {'pattern': r'[^_]function\(',
'description': 'The keyword "function" should be followed by a space'}, 'description': 'The keyword "function" should be followed by a space'},
{'pattern': 'msgid|MSGID',
'description': 'Avoid using "msgid" as a variable name; use "message_id" instead.'},
{'pattern': r'.*blueslip.warning\(.*', {'pattern': r'.*blueslip.warning\(.*',
'description': 'The module blueslip has no function warning, try using blueslip.warn'}, 'description': 'The module blueslip has no function warning, try using blueslip.warn'},
{'pattern': '[)]{$', {'pattern': '[)]{$',