Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

eslint: Fix unicorn/prefer-split-limit.

Anders Kaseorg206901973580
diff --git a/starlight_help/src/components/NavigationSteps.astro b/starlight_help/src/components/NavigationSteps.astro
index 03e19d98b67..8998a5a5c40 100644
--- a/starlight_help/src/components/NavigationSteps.astro
+++ b/starlight_help/src/components/NavigationSteps.astro
@@ -3,7 +3,7 @@ import RelativeSteps from "./RelativeSteps.astro";
import SettingsSteps from "./SettingsSteps.astro";
const {target} = Astro.props;
-const navigation_link_type = target.split("/")[0];
+const [navigation_link_type, ...parts] = target.split("/");
if (navigation_link_type !== "settings" && navigation_link_type !== "relative") {
throw new Error("Invalid navigation link type. Only `settings` or `relative` is allowed.");
@@ -12,8 +12,8 @@ if (navigation_link_type !== "settings" && navigation_link_type !== "relative")
{
navigation_link_type === "settings" ? (
- <SettingsSteps setting_key={target.split("/")[1]} />
+ <SettingsSteps setting_key={parts[0]} />
) : (
- <RelativeSteps link_type={target.split("/")[1]} key={target.split("/")[2]} />
+ <RelativeSteps link_type={parts[0]} key={parts[1]} />
)
}
diff --git a/web/src/hash_parser.ts b/web/src/hash_parser.ts
index 0806b60e73a..eb886bbdcd8 100644
--- a/web/src/hash_parser.ts
+++ b/web/src/hash_parser.ts
@@ -5,7 +5,7 @@ import * as util from "./util.ts";
export function get_hash_category(hash?: string): string {
// given "#channels/subscribed", returns "channels"
- return hash ? hash.replace(/^#/, "").split(/\//)[0]! : "";
+ return hash ? hash.replace(/^#/, "").split(/\//, 1)[0]! : "";
}
export function get_hash_section(hash?: string): string {
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index e0d8cb6ad92..224665dfb33 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -179,7 +179,7 @@ export function by_conversation_and_time_url(message: Message): string {
"//" +
window.location.host +
"/" +
- window.location.pathname.split("/")[1];
+ window.location.pathname.split("/", 2)[1];
const suffix = "/near/" + internal_url.encodeHashComponent(message.id.toString());
diff --git a/web/src/markdown.ts b/web/src/markdown.ts
index 1363ac297d8..c61d09c29ee 100644
--- a/web/src/markdown.ts
+++ b/web/src/markdown.ts
@@ -583,7 +583,7 @@ function handleTimestamp(time_string: string): string {
// Use html5 <time> tag for valid timestamps.
// render time without milliseconds.
- const escaped_isotime = _.escape(timeobject.toISOString().split(".")[0] + "Z");
+ const escaped_isotime = _.escape(timeobject.toISOString().split(".", 1)[0] + "Z");
return `<time datetime="${escaped_isotime}">${escaped_time}</time>`;
}
diff --git a/web/src/user_profile.ts b/web/src/user_profile.ts
index 5a93b4bb223..be0bad5f410 100644
--- a/web/src/user_profile.ts
+++ b/web/src/user_profile.ts
@@ -1,5 +1,6 @@
import ClipboardJS from "clipboard";
import {parseISO} from "date-fns";
+import {parseOneAddress} from "email-addresses";
import $ from "jquery";
import _ from "lodash";
import assert from "minimalistic-assert";
@@ -850,7 +851,11 @@ export function show_edit_bot_info_modal(user_id: number, $container: JQuery): v
assert(bot.is_bot);
// Extract short_name from email (format: {short_name}-bot@domain)
- const short_name = bot.email.split("@")[0]!.slice(0, -4);
+ const parsed_address = parseOneAddress(bot.email);
+ assert(parsed_address?.type === "mailbox");
+ const short_name = parsed_address.local.endsWith("-bot")
+ ? parsed_address.local.slice(0, -"-bot".length)
+ : parsed_address.local;
const modal_content_html = render_edit_bot_form({
user_id,
is_active,
diff --git a/web/tests/scheduled_messages.test.cjs b/web/tests/scheduled_messages.test.cjs
index 5e191e03b3f..14809291f79 100644
--- a/web/tests/scheduled_messages.test.cjs
+++ b/web/tests/scheduled_messages.test.cjs
@@ -105,7 +105,7 @@ function get_expected_send_opts(day, expecteds) {
// 'today_four_pm'
// 'monday_nine_am'
for (const expect of expecteds) {
- const day = expect.split("_")[0]; // "today", "monday"
+ const day = expect.split("_", 1)[0]; // "today", "monday"
if (!modal_opts[`possible_send_later_${day}`]) {
modal_opts[`possible_send_later_${day}`] = {};
}
diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js
index ffde3eba901..fe8f7cab11f 100644
--- a/zerver/openapi/javascript_examples.js
+++ b/zerver/openapi/javascript_examples.js
@@ -20,10 +20,11 @@ const examples_handler = function () {
const make_result_object = (example, result, count = false) => {
const name = count !== false ? `${example.name}_${count}` : example.name;
+ const [endpoint, method] = example.endpoint.split(":", 2);
return {
name,
- endpoint: example.endpoint.split(":")[0],
- method: example.endpoint.split(":")[1],
+ endpoint,
+ method,
status_code: example.status_code.toString(),
result,
};