chore: Use .includes and .startsWith, not .indexOf (#7936)

Easier to read than the diverse collection of `=== 0` and `!== -1` and `> -1` tests.
This commit is contained in:
Neil Fraser
2024-03-15 00:03:55 +01:00
committed by GitHub
parent 81e2203f7f
commit 0ecbcde9fc
42 changed files with 62 additions and 64 deletions

View File

@@ -227,7 +227,7 @@ const LISTS_CREATE_WITH = {
// Disconnect any children that don't belong.
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i)!.connection!.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
if (connection && !connections.includes(connection)) {
connection.disconnect();
}
}

View File

@@ -858,7 +858,7 @@ const PROCEDURE_CALL_COMMON = {
if (
mutatorOpen &&
connection &&
paramIds.indexOf(this.quarkIds_[i]) === -1
!paramIds.includes(this.quarkIds_[i])
) {
// This connection should no longer be attached to this block.
connection.disconnect();
@@ -1043,7 +1043,7 @@ const PROCEDURE_CALL_COMMON = {
}
if (
event.type === Events.BLOCK_CREATE &&
(event as BlockCreate).ids!.indexOf(this.id) !== -1
(event as BlockCreate).ids!.includes(this.id)
) {
// Look for the case where a procedure call was created (usually through
// paste) and there is no matching definition. In this case, create
@@ -1288,7 +1288,7 @@ const PROCEDURES_IFRETURN = {
// Is the block nested in a procedure?
let block = this; // eslint-disable-line @typescript-eslint/no-this-alias
do {
if (this.FUNCTION_TYPES.indexOf(block.type) !== -1) {
if (this.FUNCTION_TYPES.includes(block.type)) {
legal = true;
break;
}

View File

@@ -829,7 +829,7 @@ const JOIN_MUTATOR_MIXIN = {
// Disconnect any children that don't belong.
for (let i = 0; i < this.itemCount_; i++) {
const connection = this.getInput('ADD' + i)!.connection!.targetConnection;
if (connection && connections.indexOf(connection) === -1) {
if (connection && !connections.includes(connection)) {
connection.disconnect();
}
}