diff --git a/.eslintrc.json b/.eslintrc.json index dcd2cc335..c010cf24c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,6 +8,8 @@ "node": true }, "rules": { + "no-await-in-loop": "warn", + "no-compare-neg-zero": "error", "no-extra-parens": ["warn", "all", { "nestedBinaryExpressions": false }], @@ -53,6 +55,7 @@ "no-new": "error", "no-octal-escape": "error", "no-return-assign": "error", + "no-return-await": "error", "no-self-compare": "error", "no-sequences": "error", "no-throw-literal": "error", @@ -61,8 +64,11 @@ "no-useless-call": "error", "no-useless-concat": "error", "no-useless-escape": "error", + "no-useless-return": "error", "no-void": "error", "no-warning-comments": "warn", + "prefer-promise-reject-errors": "error", + "require-await": "warn", "wrap-iife": "error", "yoda": "error", @@ -79,6 +85,7 @@ "array-bracket-spacing": "error", "block-spacing": "error", "brace-style": ["error", "1tbs", { "allowSingleLine": true }], + "capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }], "comma-dangle": ["error", "always-multiline"], "comma-spacing": "error", "comma-style": "error", @@ -107,6 +114,7 @@ "no-trailing-spaces": "error", "no-unneeded-ternary": "error", "no-whitespace-before-property": "error", + "nonblock-statement-body-position": "error", "object-curly-spacing": ["error", "always"], "operator-assignment": "error", "operator-linebreak": ["error", "after"], @@ -121,6 +129,7 @@ "space-infix-ops": "error", "space-unary-ops": "error", "spaced-comment": "error", + "template-tag-spacing": "error", "unicode-bom": "error", "arrow-body-style": "error", diff --git a/src/client/actions/GuildDelete.js b/src/client/actions/GuildDelete.js index de34437d4..2483e2833 100644 --- a/src/client/actions/GuildDelete.js +++ b/src/client/actions/GuildDelete.js @@ -17,18 +17,18 @@ class GuildDeleteAction extends Action { } if (guild.available && data.unavailable) { - // guild is unavailable + // Guild is unavailable guild.available = false; client.emit(Constants.Events.GUILD_UNAVAILABLE, guild); - // stops the GuildDelete packet thinking a guild was actually deleted, + // Stops the GuildDelete packet thinking a guild was actually deleted, // handles emitting of event itself return { guild: null, }; } - // delete guild + // Delete guild client.guilds.delete(guild.id); this.deleted.set(guild.id, guild); this.scheduleForDeletion(guild.id); diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 015a1e14d..685141f49 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -354,7 +354,7 @@ class RESTMethods { }); } - // untested but probably will work + // Untested but probably will work deleteGuild(guild) { return this.rest.makeRequest('del', Constants.Endpoints.guild(guild.id), true).then(() => this.client.actions.GuildDelete.handle({ id: guild.id }).guild @@ -486,7 +486,7 @@ class RESTMethods { if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role); let endpoint = Constants.Endpoints.guildMember(member.guild.id, member.id); - // fix your endpoints, discord ;-; + // Fix your endpoints, discord ;-; if (member.id === this.client.user.id) { const keys = Object.keys(data); if (keys.length === 1 && keys[0] === 'nick') { diff --git a/src/client/rest/RequestHandlers/RequestHandler.js b/src/client/rest/RequestHandlers/RequestHandler.js index a1a2f3475..22bb53fa2 100644 --- a/src/client/rest/RequestHandlers/RequestHandler.js +++ b/src/client/rest/RequestHandlers/RequestHandler.js @@ -43,9 +43,7 @@ class RequestHandler { /** * Attempts to get this RequestHandler to process its current queue */ - handle() { - return; - } + handle() {} // eslint-disable-line no-empty-function } module.exports = RequestHandler; diff --git a/src/client/voice/VoiceBroadcast.js b/src/client/voice/VoiceBroadcast.js index 024f3fa04..85a8261a1 100644 --- a/src/client/voice/VoiceBroadcast.js +++ b/src/client/voice/VoiceBroadcast.js @@ -267,6 +267,7 @@ class VoiceBroadcast extends VolumeInterface { _startPlaying() { if (this.tickInterval) clearInterval(this.tickInterval); + // Old code? // this.tickInterval = this.client.setInterval(this.tick.bind(this), 20); this._startTime = Date.now(); this._count = 0; diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index 9c3b56303..b07e09c21 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -203,6 +203,7 @@ class StreamDispatcher extends VolumeInterface { if (this.paused) { this.setSpeaking(false); + // Old code? // data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0; data.pausedTime += data.length * 10; this.player.voiceConnection.voiceManager.client.setTimeout(() => this.process(), data.length * 10); diff --git a/src/client/voice/opus/BaseOpusEngine.js b/src/client/voice/opus/BaseOpusEngine.js index 47c88c7c6..3262ce549 100644 --- a/src/client/voice/opus/BaseOpusEngine.js +++ b/src/client/voice/opus/BaseOpusEngine.js @@ -11,9 +11,7 @@ class BaseOpus { return buffer; } - destroy() { - return; - } + destroy() {} // eslint-disable-line no-empty-function } module.exports = BaseOpus; diff --git a/src/client/voice/receiver/VoiceReadable.js b/src/client/voice/receiver/VoiceReadable.js index 50ace27ae..d34942802 100644 --- a/src/client/voice/receiver/VoiceReadable.js +++ b/src/client/voice/receiver/VoiceReadable.js @@ -7,9 +7,7 @@ class VoiceReadable extends Readable { this.open = true; } - _read() { - return; - } + _read() {} // eslint-disable-line no-empty-function _push(d) { if (this.open) this.push(d); diff --git a/src/client/voice/receiver/VoiceReceiver.js b/src/client/voice/receiver/VoiceReceiver.js index de78322eb..48e086fad 100644 --- a/src/client/voice/receiver/VoiceReceiver.js +++ b/src/client/voice/receiver/VoiceReceiver.js @@ -20,7 +20,7 @@ class VoiceReceiver extends EventEmitter { constructor(connection) { super(); /* - need a queue because we don't get the ssrc of the user speaking until after the first few packets, + Need a queue because we don't get the ssrc of the user speaking until after the first few packets, so we queue up unknown SSRCs until they become known, then empty the queue. */ this.queues = new Map(); @@ -68,7 +68,6 @@ class VoiceReceiver extends EventEmitter { if (!this.destroyed) return; this.voiceConnection.sockets.udp.socket.on('message', this._listener); this.destroyed = false; - return; } /** diff --git a/src/client/websocket/packets/handlers/GuildCreate.js b/src/client/websocket/packets/handlers/GuildCreate.js index c7fbd7e7c..d7c180377 100644 --- a/src/client/websocket/packets/handlers/GuildCreate.js +++ b/src/client/websocket/packets/handlers/GuildCreate.js @@ -8,12 +8,12 @@ class GuildCreateHandler extends AbstractHandler { const guild = client.guilds.get(data.id); if (guild) { if (!guild.available && !data.unavailable) { - // a newly available guild + // A newly available guild guild.setup(data); this.packetManager.ws.checkIfReady(); } } else { - // a new guild + // A new guild client.dataManager.newGuild(data); } } diff --git a/src/client/websocket/packets/handlers/GuildEmojisUpdate.js b/src/client/websocket/packets/handlers/GuildEmojisUpdate.js index 523f2de2c..cf8522b54 100644 --- a/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +++ b/src/client/websocket/packets/handlers/GuildEmojisUpdate.js @@ -16,22 +16,22 @@ class GuildEmojisUpdate extends AbstractHandler { const deletions = mappify(guild.emojis.entries()); for (const emoji of data.emojis) { - // determine type of emoji event + // Determine type of emoji event const cachedEmoji = guild.emojis.get(emoji.id); if (cachedEmoji) { deletions.delete(emoji.id); if (!cachedEmoji.equals(emoji, true)) { - // emoji updated + // Emoji updated client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji); } } else { - // emoji added + // Emoji added client.actions.GuildEmojiCreate.handle(guild, emoji); } } for (const emoji of deletions.values()) { - // emoji deleted + // Emoji deleted client.actions.GuildEmojiDelete.handle(emoji); } } diff --git a/src/client/websocket/packets/handlers/GuildMembersChunk.js b/src/client/websocket/packets/handlers/GuildMembersChunk.js index 17994ae86..68571c206 100644 --- a/src/client/websocket/packets/handlers/GuildMembersChunk.js +++ b/src/client/websocket/packets/handlers/GuildMembersChunk.js @@ -1,6 +1,6 @@ const AbstractHandler = require('./AbstractHandler'); const Constants = require('../../../../util/Constants'); -// uncomment in v12 +// Uncomment in v12 // const Collection = require('../../../../util/Collection'); class GuildMembersChunkHandler extends AbstractHandler { @@ -10,7 +10,7 @@ class GuildMembersChunkHandler extends AbstractHandler { const guild = client.guilds.get(data.guild_id); if (!guild) return; - // uncomment in v12 + // Uncomment in v12 // const members = new Collection(); // // for (const member of data.members) members.set(member.id, guild._addMember(member, false)); diff --git a/src/client/websocket/packets/handlers/PresenceUpdate.js b/src/client/websocket/packets/handlers/PresenceUpdate.js index 01af53f06..53b0808f1 100644 --- a/src/client/websocket/packets/handlers/PresenceUpdate.js +++ b/src/client/websocket/packets/handlers/PresenceUpdate.js @@ -9,7 +9,7 @@ class PresenceUpdateHandler extends AbstractHandler { let user = client.users.get(data.user.id); const guild = client.guilds.get(data.guild_id); - // step 1 + // Step 1 if (!user) { if (data.user.username) { user = client.dataManager.newUser(data.user); diff --git a/src/client/websocket/packets/handlers/VoiceStateUpdate.js b/src/client/websocket/packets/handlers/VoiceStateUpdate.js index def598b72..d0369229d 100644 --- a/src/client/websocket/packets/handlers/VoiceStateUpdate.js +++ b/src/client/websocket/packets/handlers/VoiceStateUpdate.js @@ -17,7 +17,7 @@ class VoiceStateUpdateHandler extends AbstractHandler { member.voiceChannel.members.delete(oldVoiceChannelMember.id); } - // if the member left the voice channel, unset their speaking property + // If the member left the voice channel, unset their speaking property if (!data.channel_id) member.speaking = null; if (member.user.id === client.user.id && data.channel_id) { diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index 4eefa79c8..2916d2469 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -37,25 +37,26 @@ class DMChannel extends Channel { } // These are here only for documentation purposes - they are implemented by TextBasedChannel - send() { return; } - sendMessage() { return; } - sendEmbed() { return; } - sendFile() { return; } - sendFiles() { return; } - sendCode() { return; } - fetchMessage() { return; } - fetchMessages() { return; } - fetchPinnedMessages() { return; } - search() { return; } - startTyping() { return; } - stopTyping() { return; } - get typing() { return; } - get typingCount() { return; } - createCollector() { return; } - awaitMessages() { return; } - // doesn't work on DM channels; bulkDelete() { return; } - acknowledge() { return; } - _cacheMessage() { return; } + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + awaitMessages() {} + // Doesn't work on DM channels; bulkDelete() {} + acknowledge() {} + _cacheMessage() {} } TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete']); diff --git a/src/structures/GroupDMChannel.js b/src/structures/GroupDMChannel.js index 74a7945d3..7b1a7987d 100644 --- a/src/structures/GroupDMChannel.js +++ b/src/structures/GroupDMChannel.js @@ -153,25 +153,26 @@ class GroupDMChannel extends Channel { } // These are here only for documentation purposes - they are implemented by TextBasedChannel - send() { return; } - sendMessage() { return; } - sendEmbed() { return; } - sendFile() { return; } - sendFiles() { return; } - sendCode() { return; } - fetchMessage() { return; } - fetchMessages() { return; } - fetchPinnedMessages() { return; } - search() { return; } - startTyping() { return; } - stopTyping() { return; } - get typing() { return; } - get typingCount() { return; } - createCollector() { return; } - awaitMessages() { return; } - // doesn't work on group DMs; bulkDelete() { return; } - acknowledge() { return; } - _cacheMessage() { return; } + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + awaitMessages() {} + // Doesn't work on group DMs; bulkDelete() {} + acknowledge() {} + _cacheMessage() {} } TextBasedChannel.applyToClass(GroupDMChannel, true, ['bulkDelete']); diff --git a/src/structures/Guild.js b/src/structures/Guild.js index cdaf3fd4d..b3e2f4d10 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -371,7 +371,7 @@ class Guild { fetchMembers(query = '', limit = 0) { return new Promise((resolve, reject) => { if (this.memberCount === this.members.size) { - // uncomment in v12 + // Uncomment in v12 // resolve(this.members) resolve(this); return; @@ -388,10 +388,9 @@ class Guild { if (guild.id !== this.id) return; if (this.memberCount === this.members.size || members.length < 1000) { this.client.removeListener(Constants.Events.GUILD_MEMBERS_CHUNK, handler); - // uncomment in v12 + // Uncomment in v12 // resolve(this.members) resolve(this); - return; } }; this.client.on(Constants.Events.GUILD_MEMBERS_CHUNK, handler); diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index cfa1ea155..6fc8e9074 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -501,11 +501,12 @@ class GuildMember { } // These are here only for documentation purposes - they are implemented by TextBasedChannel - send() { return; } - sendMessage() { return; } - sendEmbed() { return; } - sendFile() { return; } - sendCode() { return; } + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendCode() {} } TextBasedChannel.applyToClass(GuildMember); diff --git a/src/structures/MessageCollector.js b/src/structures/MessageCollector.js index 9299cb162..f35cb8c81 100644 --- a/src/structures/MessageCollector.js +++ b/src/structures/MessageCollector.js @@ -119,7 +119,7 @@ class MessageCollector extends EventEmitter { const onEnd = (...args) => { cleanup(); - reject(...args); + reject(...args); // eslint-disable-line prefer-promise-reject-errors }; this.once('message', onMessage); diff --git a/src/structures/MessageReaction.js b/src/structures/MessageReaction.js index acaa45a65..0a530183d 100644 --- a/src/structures/MessageReaction.js +++ b/src/structures/MessageReaction.js @@ -42,7 +42,7 @@ class MessageReaction { */ get emoji() { if (this._emoji instanceof Emoji) return this._emoji; - // check to see if the emoji has become known to the client + // Check to see if the emoji has become known to the client if (this._emoji.id) { const emojis = this.message.client.emojis; if (emojis.has(this._emoji.id)) { @@ -62,7 +62,7 @@ class MessageReaction { remove(user = this.message.client.user) { const message = this.message; user = this.message.client.resolver.resolveUserID(user); - if (!user) return Promise.reject('Couldn\'t resolve the user ID to remove from the reaction.'); + if (!user) return Promise.reject(new Error('Couldn\'t resolve the user ID to remove from the reaction.')); return message.client.rest.methods.removeMessageReaction( message, this.emoji.identifier, user ); diff --git a/src/structures/OAuth2Application.js b/src/structures/OAuth2Application.js index 68c003183..2b45335fd 100644 --- a/src/structures/OAuth2Application.js +++ b/src/structures/OAuth2Application.js @@ -90,7 +90,7 @@ class OAuth2Application { this.flags = data.flags; /** - * oauth2 secret for the app + * OAuth2 secret for the application * @type {boolean} */ this.secret = data.secret; diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index f6b8de38d..274eb8eb1 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -73,25 +73,26 @@ class TextChannel extends GuildChannel { } // These are here only for documentation purposes - they are implemented by TextBasedChannel - send() { return; } - sendMessage() { return; } - sendEmbed() { return; } - sendFile() { return; } - sendFiles() { return; } - sendCode() { return; } - fetchMessage() { return; } - fetchMessages() { return; } - fetchPinnedMessages() { return; } - search() { return; } - startTyping() { return; } - stopTyping() { return; } - get typing() { return; } - get typingCount() { return; } - createCollector() { return; } - awaitMessages() { return; } - bulkDelete() { return; } - acknowledge() { return; } - _cacheMessage() { return; } + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + awaitMessages() {} + bulkDelete() {} + acknowledge() {} + _cacheMessage() {} } TextBasedChannel.applyToClass(TextChannel, true); diff --git a/src/structures/User.js b/src/structures/User.js index 48b2e5759..257609ff7 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -280,11 +280,12 @@ class User { } // These are here only for documentation purposes - they are implemented by TextBasedChannel - send() { return; } - sendMessage() { return; } - sendEmbed() { return; } - sendFile() { return; } - sendCode() { return; } + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendCode() {} } TextBasedChannel.applyToClass(User); diff --git a/src/structures/UserConnection.js b/src/structures/UserConnection.js index 6ee9fc5b4..7a1c0ab98 100644 --- a/src/structures/UserConnection.js +++ b/src/structures/UserConnection.js @@ -38,7 +38,7 @@ class UserConnection { this.revoked = data.revoked; /** - * an array of partial server integrations (not yet implemented in this lib) + * Partial server integrations (not yet implemented) * @type {Object[]} */ this.integrations = data.integrations; diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index 06394b59d..2901835c3 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -81,7 +81,6 @@ class TextBasedChannel { if (options.embed && options.embed.file) options.file = options.embed.file; - // backward compat if (options.file) { if (options.files) options.files.push(options.file); else options.files = [options.file]; diff --git a/src/util/Constants.js b/src/util/Constants.js index c78b36d9a..35e6cd591 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -82,7 +82,7 @@ const PROTOCOL_VERSION = exports.PROTOCOL_VERSION = 6; const HOST = exports.HOST = `https://discordapp.com`; const API = exports.API = `${HOST}/api/v${PROTOCOL_VERSION}`; const Endpoints = exports.Endpoints = { - // general + // General login: `${API}/auth/login`, logout: `${API}/auth/logout`, gateway: `${API}/gateway`, @@ -92,7 +92,7 @@ const Endpoints = exports.Endpoints = { assets: asset => `${HOST}/assets/${asset}`, CDN: 'https://cdn.discordapp.com', - // users + // Users user: userID => `${API}/users/${userID}`, userChannels: userID => `${Endpoints.user(userID)}/channels`, userProfile: userID => `${Endpoints.user(userID)}/profile`, @@ -110,7 +110,7 @@ const Endpoints = exports.Endpoints = { voiceRegions: `${API}/voice/regions`, - // guilds + // Guilds guilds: `${API}/guilds`, guild: guildID => `${Endpoints.guilds}/${guildID}`, guildIcon: (guildID, hash) => `${Endpoints.CDN}/icons/${guildID}/${hash}.jpg`, @@ -132,7 +132,7 @@ const Endpoints = exports.Endpoints = { guildSearch: guildID => `${Endpoints.guild(guildID)}/messages/search`, guildVoiceRegions: guildID => `${Endpoints.guild(guildID)}/regions`, - // channels + // Channels channels: `${API}/channels`, channel: channelID => `${Endpoints.channels}/${channelID}`, channelMessages: channelID => `${Endpoints.channel(channelID)}/messages`, @@ -145,7 +145,7 @@ const Endpoints = exports.Endpoints = { dmChannelRecipient: (channelID, recipientID) => `${Endpoints.channel(channelID)}/recipients/${recipientID}`, - // message reactions + // Message reactions messageReactions: (channelID, messageID) => `${Endpoints.channelMessage(channelID, messageID)}/reactions`, messageReaction: (channel, msg, emoji, limit) => @@ -156,14 +156,14 @@ const Endpoints = exports.Endpoints = { userMessageReaction: (channel, msg, emoji, limit, id) => `${Endpoints.messageReaction(channel, msg, emoji, limit)}/${id}`, - // webhooks + // Webhooks webhook: (webhookID, token) => `${API}/webhooks/${webhookID}${token ? `/${token}` : ''}`, - // oauth + // OAuth oauth2Application: appID => `${API}/oauth2/applications/${appID}`, getApp: id => `${API}/oauth2/authorize?client_id=${id}`, - // emoji + // Emoji emoji: emojiID => `${Endpoints.CDN}/emojis/${emojiID}.png`, };