From 9028df0fda0daee258537ce875f8561923b44e27 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 19 Jul 2022 04:27:40 +0200 Subject: [PATCH] DEV: Use `includes()` instead of `indexOf() >= 0` (#17553) Missed those cases in #17541 --- app/assets/javascripts/admin/addon/mixins/setting-object.js | 2 +- .../javascripts/discourse-common/addon/lib/icon-library.js | 2 +- .../discourse/app/components/color-picker-choice.js | 2 +- app/assets/javascripts/discourse/app/lib/uploads.js | 4 ++-- app/assets/javascripts/discourse/app/models/topic-list.js | 2 +- app/assets/javascripts/discourse/app/models/topic.js | 4 +--- app/assets/javascripts/discourse/app/models/user-action.js | 6 +++--- .../discourse/app/routes/discovery-categories.js | 2 +- app/assets/javascripts/discourse/app/widgets/post-cooked.js | 2 +- .../components/mini-tag-chooser/selected-collection.js | 2 +- 10 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/admin/addon/mixins/setting-object.js b/app/assets/javascripts/admin/addon/mixins/setting-object.js index 63567ebde67..1830cc89847 100644 --- a/app/assets/javascripts/admin/addon/mixins/setting-object.js +++ b/app/assets/javascripts/admin/addon/mixins/setting-object.js @@ -63,7 +63,7 @@ export default Mixin.create({ @discourseComputed("valid_values") allowsNone(validValues) { - if (validValues && validValues.indexOf("") >= 0) { + if (validValues?.includes("")) { return "admin.settings.none"; } }, diff --git a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js b/app/assets/javascripts/discourse-common/addon/lib/icon-library.js index 62d280e6124..86650a1c701 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js +++ b/app/assets/javascripts/discourse-common/addon/lib/icon-library.js @@ -121,7 +121,7 @@ export function setIconList(iconList) { } export function isExistingIconId(id) { - return _iconList && _iconList.indexOf(id) >= 0; + return _iconList.includes(id); } function warnIfMissing(id) { diff --git a/app/assets/javascripts/discourse/app/components/color-picker-choice.js b/app/assets/javascripts/discourse/app/components/color-picker-choice.js index a5773f73212..0dabe8c810a 100644 --- a/app/assets/javascripts/discourse/app/components/color-picker-choice.js +++ b/app/assets/javascripts/discourse/app/components/color-picker-choice.js @@ -10,7 +10,7 @@ export default Component.extend({ @discourseComputed("color", "usedColors") isUsed(color, usedColors) { - return (usedColors || []).indexOf(color.toUpperCase()) >= 0; + return (usedColors || []).includes(color.toUpperCase()); }, @discourseComputed("isUsed") diff --git a/app/assets/javascripts/discourse/app/lib/uploads.js b/app/assets/javascripts/discourse/app/lib/uploads.js index eb316d3f883..d019cfd84ef 100644 --- a/app/assets/javascripts/discourse/app/lib/uploads.js +++ b/app/assets/javascripts/discourse/app/lib/uploads.js @@ -198,8 +198,8 @@ function authorizedImagesExtensions(staff, siteSettings) { export function authorizesAllExtensions(staff, siteSettings) { return ( - siteSettings.authorized_extensions.indexOf("*") >= 0 || - (siteSettings.authorized_extensions_for_staff.indexOf("*") >= 0 && staff) + siteSettings.authorized_extensions.includes("*") || + (siteSettings.authorized_extensions_for_staff.includes("*") && staff) ); } diff --git a/app/assets/javascripts/discourse/app/models/topic-list.js b/app/assets/javascripts/discourse/app/models/topic-list.js index b019da21827..c108f8b41e9 100644 --- a/app/assets/javascripts/discourse/app/models/topic-list.js +++ b/app/assets/javascripts/discourse/app/models/topic-list.js @@ -120,7 +120,7 @@ const TopicList = RestModel.extend({ loadBefore(topic_ids, storeInSession) { // refresh dupes this.topics.removeObjects( - this.topics.filter((topic) => topic_ids.indexOf(topic.id) >= 0) + this.topics.filter((topic) => topic_ids.includes(topic.id)) ); const url = `${getURL("/")}${this.filter}.json?topic_ids=${topic_ids.join( diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js index 200436454d8..53b4af4e209 100644 --- a/app/assets/javascripts/discourse/app/models/topic.js +++ b/app/assets/javascripts/discourse/app/models/topic.js @@ -61,9 +61,7 @@ const Topic = RestModel.extend({ @discourseComputed("posters.[]") lastPoster(posters) { if (posters && posters.length > 0) { - const latest = posters.filter( - (p) => p.extras && p.extras.indexOf("latest") >= 0 - )[0]; + const latest = posters.filter((p) => p.extras?.includes("latest"))[0]; return latest || posters.firstObject; } }, diff --git a/app/assets/javascripts/discourse/app/models/user-action.js b/app/assets/javascripts/discourse/app/models/user-action.js index a1a567720ec..15ff9e0a3f7 100644 --- a/app/assets/javascripts/discourse/app/models/user-action.js +++ b/app/assets/javascripts/discourse/app/models/user-action.js @@ -31,7 +31,7 @@ const UserAction = RestModel.extend({ @discourseComputed("action_type") descriptionKey(action) { - if (action === null || UserAction.TO_SHOW.indexOf(action) >= 0) { + if (action === null || UserAction.TO_SHOW.includes(action)) { if (this.isPM) { return this.sameUser ? "sent_by_you" : "sent_by_user"; } else { @@ -180,7 +180,7 @@ UserAction.reopenClass({ const found = uniq[key]; if (found === void 0) { let current; - if (UserAction.TO_COLLAPSE.indexOf(item.action_type) >= 0) { + if (UserAction.TO_COLLAPSE.includes(item.action_type)) { current = UserAction.create(item); item.switchToActing(); current.addChild(item); @@ -191,7 +191,7 @@ UserAction.reopenClass({ collapsed[pos] = current; pos += 1; } else { - if (UserAction.TO_COLLAPSE.indexOf(item.action_type) >= 0) { + if (UserAction.TO_COLLAPSE.includes(item.action_type)) { item.switchToActing(); collapsed[found].addChild(item); } else { diff --git a/app/assets/javascripts/discourse/app/routes/discovery-categories.js b/app/assets/javascripts/discourse/app/routes/discovery-categories.js index f689c27e87d..d7b1970d3fb 100644 --- a/app/assets/javascripts/discourse/app/routes/discovery-categories.js +++ b/app/assets/javascripts/discourse/app/routes/discovery-categories.js @@ -47,7 +47,7 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, { return function (topic_ids, storeInSession) { // refresh dupes this.topics.removeObjects( - this.topics.filter((topic) => topic_ids.indexOf(topic.id) >= 0) + this.topics.filter((topic) => topic_ids.includes(topic.id)) ); const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join(",")}`; diff --git a/app/assets/javascripts/discourse/app/widgets/post-cooked.js b/app/assets/javascripts/discourse/app/widgets/post-cooked.js index 5ccbde2f92a..9cceb2cc51f 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-cooked.js +++ b/app/assets/javascripts/discourse/app/widgets/post-cooked.js @@ -129,7 +129,7 @@ export default class PostCooked { // this might be an attachment if (lc.internal && /^\/uploads\//.test(lc.url)) { - valid = href.indexOf(lc.url) >= 0; + valid = href.includes(lc.url); } // Match server-side behaviour for internal links with query params diff --git a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser/selected-collection.js b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser/selected-collection.js index 9ccbe516280..fc563c4698d 100644 --- a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser/selected-collection.js +++ b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser/selected-collection.js @@ -17,7 +17,7 @@ export default Component.extend({ let tags = this.selectedTags; if (tags.length >= 20 && this.selectKit.filter) { - tags = tags.filter((t) => t.indexOf(this.selectKit.filter) >= 0); + tags = tags.filter((t) => t.includes(this.selectKit.filter)); } else if (tags.length >= 20) { tags = tags.slice(0, 20); }