Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Fix no-useless-escape errors.
Anders Kaseorg569b38fe34ef
diff --git a/.eslintrc.json b/.eslintrc.jsonindex ab22195abff..9ef47515004 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -101,11 +101,6 @@],"no-use-before-define": "error","no-useless-constructor": "error",- // The Zulip codebase complies partially with the "no-useless-escape"- // rule; only regex expressions haven't been updated yet.- // Updated regex expressions are currently being tested in casper- // files and will decide about a potential future enforcement of this rule.- "no-useless-escape": "off","no-var": "error","space-unary-ops": "error","no-whitespace-before-property": "error",diff --git a/frontend_tests/casper_tests/06-settings.js b/frontend_tests/casper_tests/06-settings.jsindex 4a0e39110d2..e217a647b8b 100644--- a/frontend_tests/casper_tests/06-settings.js+++ b/frontend_tests/casper_tests/06-settings.js@@ -238,7 +238,7 @@ casper.then(function () {casper.click('#create_alert_word_button');casper.test.info('Checking that a success message is displayed');casper.waitUntilVisible('#alert_word_status', function () {- casper.test.assertSelectorHasText('.alert_word_status_text', 'Alert word \"some phrase\" added successfully!');+ casper.test.assertSelectorHasText('.alert_word_status_text', 'Alert word "some phrase" added successfully!');casper.test.info('Closing the status message');casper.click('.close-alert-word-status');casper.test.info('Checking the status message is hidden');diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.jsindex 93c30890a54..fbe30fc67fa 100644--- a/frontend_tests/node_tests/list_render.js+++ b/frontend_tests/node_tests/list_render.js@@ -749,7 +749,7 @@ run_test('render item', () => {`tr[data-item='${INITIAL_RENDER_COUNT - 1}']`];const item = INITIAL_RENDER_COUNT - 1;const new_html = `<tr data-item=${item}>updated: ${item}</tr>\n`;- const regex = new RegExp(`\\<tr data-item=${item}\\>.*?\<\\/tr\\>`);+ const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);assert(expected_queries.includes(query));if (query.includes(`data-item='${INITIAL_RENDER_COUNT}'`)) {return; // This item is not rendered, so we find nothingdiff --git a/static/js/alert_words.js b/static/js/alert_words.jsindex 8c0135b3ad8..209b5696981 100644--- a/static/js/alert_words.js+++ b/static/js/alert_words.js@@ -22,7 +22,7 @@ exports.has_alert_word = function (word) {// escape_user_regex taken from jquery-ui/autocomplete.js,// licensed under MIT license.function escape_user_regex(value) {- return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");+ return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");}exports.process_message = function (message) {diff --git a/static/js/common.js b/static/js/common.jsindex e316a6e681c..beda3c8ad3c 100644--- a/static/js/common.js+++ b/static/js/common.js@@ -117,7 +117,7 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {$(key_elem_class).each(function () {let key_text = $(this).text();- const keys = key_text.match(/[^\s\+]+/g) || [];+ const keys = key_text.match(/[^\s+]+/g) || [];if (key_text.includes('Ctrl') && require_cmd_style) {$(this).addClass("mac-cmd-key");diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.jsindex 4057db6e12e..9462e645b0e 100644--- a/static/js/composebox_typeahead.js+++ b/static/js/composebox_typeahead.js@@ -311,7 +311,7 @@ exports.tokenize_compose_str = function (s) {case '_':if (i === 0) {return s;- } else if (/[\s(){}\[\]]/.test(s[i - 1])) {+ } else if (/[\s(){}[\]]/.test(s[i - 1])) {return s.slice(i);}break;@@ -709,7 +709,7 @@ exports.get_candidates = function (query) {if (this.options.completions.topic) {// Stream regex modified from marked.js// Matches '#**stream name** >' at the end of a split.- const stream_regex = /#\*\*([^\*>]+)\*\*\s?>$/;+ const stream_regex = /#\*\*([^*>]+)\*\*\s?>$/;const should_jump_inside_typeahead = stream_regex.test(split[0]);if (should_jump_inside_typeahead) {this.completing = 'topic_jump';@@ -719,7 +719,7 @@ exports.get_candidates = function (query) {}// Matches '#**stream name>some text' at the end of a split.- const stream_topic_regex = /#\*\*([^\*>]+)>([^\*]*)$/;+ const stream_topic_regex = /#\*\*([^*>]+)>([^*]*)$/;const should_begin_typeahead = stream_topic_regex.test(split[0]);if (should_begin_typeahead) {this.completing = 'topic_list';@@ -736,7 +736,7 @@ exports.get_candidates = function (query) {}}if (this.options.completions.timestamp) {- const time_jump_regex = /<time(\:([^>]*?)>?)?$/;+ const time_jump_regex = /<time(:([^>]*?)>?)?$/;if (time_jump_regex.test(split[0])) {this.completing = 'time_jump';return [i18n.t('Mention a timezone-aware time')];diff --git a/static/js/markdown.js b/static/js/markdown.jsindex 829d1ac4bde..af4179fa4ad 100644--- a/static/js/markdown.js+++ b/static/js/markdown.js@@ -77,7 +77,7 @@ exports.contains_backend_only_syntax = function (content) {// then don't render it locally. It is workaround for the fact that// javascript regex doesn't support lookbehind.const false_filter_match = realm_filter_list.find((re) => {- const pattern = /(?:[^\s'"\(,:<])/.source + re[0].source + /(?![\w])/.source;+ const pattern = /(?:[^\s'"(,:<])/.source + re[0].source + /(?![\w])/.source;const regex = new RegExp(pattern);return regex.test(content);});@@ -487,7 +487,7 @@ exports.initialize = function (realm_filters, helper_config) {marked.InlineLexer.rules.zulip.strong = /^\*\*([\s\S]+?)\*\*(?!\*)/;// Make sure <del> syntax matches the backend processor- marked.InlineLexer.rules.zulip.del = /^(?!<\~)\~\~([^~]+)\~\~(?!\~)/;+ marked.InlineLexer.rules.zulip.del = /^(?!<~)~~([^~]+)~~(?!~)/;// Disable _emphasis_ (keeping *emphasis*)// Text inside ** must start and end with a word characterdiff --git a/static/js/settings_bots.js b/static/js/settings_bots.jsindex 3c0820415da..108e2577db3 100644--- a/static/js/settings_bots.js+++ b/static/js/settings_bots.js@@ -60,7 +60,7 @@ function add_bot_row(info) {function is_local_part(value, element) {// Adapted from Django's EmailValidator- return this.optional(element) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i.test(value);+ return this.optional(element) || /^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$/i.test(value);}exports.type_id_to_string = function (type_id) {diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.jsindex 53fb31a139c..518e00eef7d 100644--- a/static/js/typeahead_helper.js+++ b/static/js/typeahead_helper.js@@ -14,7 +14,7 @@ exports.get_cleaned_pm_recipients = function (query_string) {exports.build_highlight_regex = function (query) {// the regex below is based on bootstrap code- query = query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');+ query = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');const regex = new RegExp('(' + query + ')', 'ig');return regex;};diff --git a/static/js/util.js b/static/js/util.jsindex cddf5536ed2..4e6f0eea39a 100644--- a/static/js/util.js+++ b/static/js/util.js@@ -148,8 +148,7 @@ exports.strcmp = exports.make_strcmp();exports.escape_regexp = function (string) {// code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions- // Modified to escape the ^ to appease jslint. :/- return string.replace(/([.*+?\^=!:${}()|\[\]\/\\])/g, "\\$1");+ return string.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1");};exports.array_compare = function util_array_compare(a, b) {