Skip to content

Commit 11f6955

Browse files
refactor: use proper variable names in callbacks (#9840)
* refactor: use proper variable names in callbacks * refactor: change parameter names * refactor: change remaining parameter names * refactor: change remaining variable names * refactor(GuildAuditLogsEntry): abstract reduce logic into a new function * chore: undo unrelated changes This undoes commit b2d93dc as it's unrelated * refactor: more name changes * chore: fix tests failing * refactor: use option instead of opt --------- Co-authored-by: Jiralite <[email protected]>
1 parent 2aa3250 commit 11f6955

34 files changed

+104
-79
lines changed

packages/discord.js/src/client/Client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class Client extends BaseClient {
369369
*/
370370
async fetchStickerPacks() {
371371
const data = await this.rest.get(Routes.stickerPacks());
372-
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
372+
return new Collection(data.sticker_packs.map(stickerPack => [stickerPack.id, new StickerPack(this, stickerPack)]));
373373
}
374374

375375
/**

packages/discord.js/src/client/websocket/WebSocketManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class WebSocketManager extends EventEmitter {
364364
*/
365365
checkShardsReady() {
366366
if (this.status === Status.Ready) return;
367-
if (this.shards.size !== this.totalShards || this.shards.some(s => s.status !== Status.Ready)) {
367+
if (this.shards.size !== this.totalShards || this.shards.some(shard => shard.status !== Status.Ready)) {
368368
return;
369369
}
370370

packages/discord.js/src/client/websocket/WebSocketShard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class WebSocketShard extends EventEmitter {
140140
*/
141141
this.emit(WebSocketShardEvents.Ready);
142142

143-
this.expectedGuilds = new Set(packet.guilds.map(d => d.id));
143+
this.expectedGuilds = new Set(packet.guilds.map(guild => guild.id));
144144
this.status = Status.WaitingForGuilds;
145145
}
146146

packages/discord.js/src/managers/ApplicationCommandManager.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ class ApplicationCommandManager extends CachedManager {
169169
*/
170170
async set(commands, guildId) {
171171
const data = await this.client.rest.put(this.commandPath({ guildId }), {
172-
body: commands.map(c => this.constructor.transformCommand(c)),
172+
body: commands.map(command => this.constructor.transformCommand(command)),
173173
});
174-
return data.reduce((coll, command) => coll.set(command.id, this._add(command, true, guildId)), new Collection());
174+
return data.reduce(
175+
(collection, command) => collection.set(command.id, this._add(command, true, guildId)),
176+
new Collection(),
177+
);
175178
}
176179

177180
/**
@@ -253,7 +256,7 @@ class ApplicationCommandManager extends CachedManager {
253256
nsfw: command.nsfw,
254257
description_localizations: command.descriptionLocalizations ?? command.description_localizations,
255258
type: command.type,
256-
options: command.options?.map(o => ApplicationCommand.transformOption(o)),
259+
options: command.options?.map(option => ApplicationCommand.transformOption(option)),
257260
default_member_permissions,
258261
dm_permission: command.dmPermission ?? command.dm_permission,
259262
};

packages/discord.js/src/managers/ApplicationCommandPermissionsManager.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ class ApplicationCommandPermissionsManager extends BaseManager {
210210
);
211211
}
212212

213-
let existing = [];
213+
let existingPermissions = [];
214214
try {
215-
existing = await this.fetch({ guild: guildId, command: commandId });
215+
existingPermissions = await this.fetch({ guild: guildId, command: commandId });
216216
} catch (error) {
217217
if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
218218
}
219219

220220
const newPermissions = permissions.slice();
221-
for (const perm of existing) {
222-
if (!newPermissions.some(x => x.id === perm.id)) {
223-
newPermissions.push(perm);
221+
for (const existingPermission of existingPermissions) {
222+
if (!newPermissions.some(newPermission => newPermission.id === existingPermission.id)) {
223+
newPermissions.push(existingPermission);
224224
}
225225
}
226226

packages/discord.js/src/managers/CategoryChannelChildManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CategoryChannelChildManager extends DataManager {
2323
* @readonly
2424
*/
2525
get cache() {
26-
return this.guild.channels.cache.filter(c => c.parentId === this.channel.id);
26+
return this.guild.channels.cache.filter(channel => channel.parentId === this.channel.id);
2727
}
2828

2929
/**

packages/discord.js/src/managers/GuildChannelManager.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class GuildChannelManager extends CachedManager {
166166
reason,
167167
}) {
168168
parent &&= this.client.channels.resolveId(parent);
169-
permissionOverwrites &&= permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
169+
permissionOverwrites &&= permissionOverwrites.map(overwrite => PermissionOverwrites.resolve(overwrite, this.guild));
170170

171171
const data = await this.client.rest.post(Routes.guildChannels(this.guild.id), {
172172
body: {
@@ -281,19 +281,21 @@ class GuildChannelManager extends CachedManager {
281281
await this.setPosition(channel, options.position, { position: options.position, reason: options.reason });
282282
}
283283

284-
let permission_overwrites = options.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
284+
let permission_overwrites = options.permissionOverwrites?.map(overwrite =>
285+
PermissionOverwrites.resolve(overwrite, this.guild),
286+
);
285287

286288
if (options.lockPermissions) {
287289
if (parent) {
288290
const newParent = this.guild.channels.resolve(parent);
289291
if (newParent?.type === ChannelType.GuildCategory) {
290-
permission_overwrites = newParent.permissionOverwrites.cache.map(o =>
291-
PermissionOverwrites.resolve(o, this.guild),
292+
permission_overwrites = newParent.permissionOverwrites.cache.map(overwrite =>
293+
PermissionOverwrites.resolve(overwrite, this.guild),
292294
);
293295
}
294296
} else if (channel.parent) {
295-
permission_overwrites = channel.parent.permissionOverwrites.cache.map(o =>
296-
PermissionOverwrites.resolve(o, this.guild),
297+
permission_overwrites = channel.parent.permissionOverwrites.cache.map(overwrite =>
298+
PermissionOverwrites.resolve(overwrite, this.guild),
297299
);
298300
}
299301
}
@@ -438,11 +440,11 @@ class GuildChannelManager extends CachedManager {
438440
* .catch(console.error);
439441
*/
440442
async setPositions(channelPositions) {
441-
channelPositions = channelPositions.map(r => ({
442-
id: this.client.channels.resolveId(r.channel),
443-
position: r.position,
444-
lock_permissions: r.lockPermissions,
445-
parent_id: r.parent !== undefined ? this.resolveId(r.parent) : undefined,
443+
channelPositions = channelPositions.map(channelPosition => ({
444+
id: this.client.channels.resolveId(channelPosition.channel),
445+
position: channelPosition.position,
446+
lock_permissions: channelPosition.lockPermissions,
447+
parent_id: channelPosition.parent !== undefined ? this.resolveId(channelPosition.parent) : undefined,
446448
}));
447449

448450
await this.client.rest.patch(Routes.guildChannels(this.guild.id), { body: channelPositions });

packages/discord.js/src/managers/GuildEmojiManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
130130
async edit(emoji, options) {
131131
const id = this.resolveId(emoji);
132132
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
133-
const roles = options.roles?.map(r => this.guild.roles.resolveId(r));
133+
const roles = options.roles?.map(role => this.guild.roles.resolveId(role));
134134
const newData = await this.client.rest.patch(Routes.guildEmoji(this.guild.id, id), {
135135
body: {
136136
name: options.name,

packages/discord.js/src/managers/MessageManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class MessageManager extends CachedManager {
8686
* @example
8787
* // Fetch messages and filter by a user id
8888
* channel.messages.fetch()
89-
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
89+
* .then(messages => console.log(`${messages.filter(message =>
90+
* message.author.id === '84484653687267328').size} messages`))
9091
* .catch(console.error);
9192
*/
9293
fetch(options) {

packages/discord.js/src/managers/RoleManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ class RoleManager extends CachedManager {
280280
*/
281281
async setPositions(rolePositions) {
282282
// Make sure rolePositions are prepared for API
283-
rolePositions = rolePositions.map(o => ({
284-
id: this.resolveId(o.role),
285-
position: o.position,
283+
rolePositions = rolePositions.map(rolePosition => ({
284+
id: this.resolveId(rolePosition.role),
285+
position: rolePosition.position,
286286
}));
287287

288288
// Call the API to update role positions

0 commit comments

Comments
 (0)