Skip to content

Commit

Permalink
Favor includes over indexOf.
Browse files Browse the repository at this point in the history
Change-Id: I78a8334c025fe11d485cb2f9cb7cb4cb7dcb6c2c
  • Loading branch information
TheModMaker committed Jun 27, 2019
1 parent a27f50d commit 28cc9f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const commonNoRestrictedSyntax = [
'selector': 'MemberExpression[property.name="prototype"]',
'message': 'Use ES6 classes not .prototype.',
},
{
'selector': 'BinaryExpression[operator=/^([<>!=]=?)$/] > ' +
'CallExpression[callee.property.name=indexOf]',
'message': 'Use Array.includes instead of indexOf.',
},
];

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions lib/media/adaptation_set_criteria.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ shaka.media.PreferenceBasedCriteria = class {
return variants.filter((variant) => {
const audio = variant.audio;
const video = variant.video;
return (audio && audio.roles.indexOf(preferredRole) >= 0) ||
(video && video.roles.indexOf(preferredRole) >= 0);
return (audio && audio.roles.includes(preferredRole)) ||
(video && video.roles.includes(preferredRole));
});
}
};
2 changes: 1 addition & 1 deletion lib/offline/indexeddb/eme_session_storage_cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ shaka.offline.indexeddb.EmeSessionStorageCell = class {
const op = this.connection_.startReadWriteOperation(this.store_);

await op.forEachEntry((key, value, cursor) => {
if (sessionIds.indexOf(value.sessionId) >= 0) {
if (sessionIds.includes(value.sessionId)) {
cursor.delete();
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ shaka.offline.Storage = class {
const deletedSessionIds = await deleter.delete(drmConfig, net, sessions);
await sessionIdCell.remove(deletedSessionIds);
await sessionIdCell.add(sessions.filter(
(session) => deletedSessionIds.indexOf(session.sessionId) == -1));
(session) => !deletedSessionIds.includes(session.sessionId)));
}

/**
Expand Down

0 comments on commit 28cc9f6

Please sign in to comment.