DEV: Use `includes()` instead of `indexOf() >= 0` (#17553)

Missed those cases in #17541
This commit is contained in:
Jarek Radosz 2022-07-19 04:27:40 +02:00 committed by GitHub
parent 0db6ae1e1f
commit 9028df0fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 13 additions and 15 deletions

View File

@ -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";
}
},

View File

@ -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) {

View File

@ -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")

View File

@ -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)
);
}

View File

@ -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(

View File

@ -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;
}
},

View File

@ -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 {

View File

@ -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(",")}`;

View File

@ -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

View File

@ -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);
}