From a194d9c37fa05152738efe26a5e698cf7716d282 Mon Sep 17 00:00:00 2001 From: Almeida Date: Mon, 4 Oct 2021 23:04:53 +0100 Subject: [PATCH] refactor: use optional chaining (#6757) --- src/rest/APIRequest.js | 2 +- src/rest/RequestHandler.js | 2 +- src/structures/Guild.js | 2 +- test/sendtest.js | 2 +- test/webhooktest.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 6397b204f..2ec64baa3 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -48,7 +48,7 @@ class APIRequest { if (this.options.headers) headers = Object.assign(headers, this.options.headers); let body; - if (this.options.files && this.options.files.length) { + if (this.options.files?.length) { body = new FormData(); for (const file of this.options.files) { if (file?.file) body.append(file.key ?? file.name, file.file, file.name); diff --git a/src/rest/RequestHandler.js b/src/rest/RequestHandler.js index dbf930674..d80570dac 100644 --- a/src/rest/RequestHandler.js +++ b/src/rest/RequestHandler.js @@ -177,7 +177,7 @@ class RequestHandler { } let sublimitTimeout; - if (res && res.headers) { + if (res.headers) { const serverDate = res.headers.get('date'); const limit = res.headers.get('x-ratelimit-limit'); const remaining = res.headers.get('x-ratelimit-remaining'); diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 5f4abb7fe..7c245f28b 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -926,7 +926,7 @@ class Guild extends AnonymousGuild { const welcome_channels = welcomeChannels?.map(welcomeChannelData => { const emoji = this.emojis.resolve(welcomeChannelData.emoji); return { - emoji_id: emoji && emoji.id, + emoji_id: emoji?.id, emoji_name: emoji?.name ?? welcomeChannelData.emoji, channel_id: this.channels.resolveId(welcomeChannelData.channel), description: welcomeChannelData.description, diff --git a/test/sendtest.js b/test/sendtest.js index d30d5a014..3f7f712a7 100644 --- a/test/sendtest.js +++ b/test/sendtest.js @@ -92,7 +92,7 @@ const tests = [ client.on('messageCreate', async message => { if (message.author.id !== owner) return; const match = message.content.match(/^do (.+)$/); - if (match && match[1] === 'it') { + if (match?.[1] === 'it') { /* eslint-disable no-await-in-loop */ for (const [i, test] of tests.entries()) { await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``); diff --git a/test/webhooktest.js b/test/webhooktest.js index aed75e40e..f42285a79 100644 --- a/test/webhooktest.js +++ b/test/webhooktest.js @@ -101,7 +101,7 @@ client.on('messageCreate', async message => { { type: 'TextChannel#fetchWebhooks', hook: await message.channel.fetchWebhooks().then(x => x.first()) }, { type: 'Guild#fetchWebhooks', hook: await message.guild.fetchWebhooks().then(x => x.first()) }, ]; - if (match && match[1] === 'it') { + if (match?.[1] === 'it') { /* eslint-disable no-await-in-loop */ for (const { type, hook } of hooks) { for (const [i, test] of tests.entries()) {