Skip to content

Commit

Permalink
chore: Minor code cleanup (#137)
Browse files Browse the repository at this point in the history
* feat(ci): Tag semver major too

* chore: Prefer `for...of` loops over `forEach` methods where appropriate
  • Loading branch information
AverageHelper authored Aug 28, 2024
1 parent 0b968b5 commit 96b28e3
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 96 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
Expand Down
2 changes: 1 addition & 1 deletion .vscode/i18n-ally-custom-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ languageIds:
# To help with this, you can use https://www.freeformatter.com/json-escape.html
usageMatchRegex:
# Detect `localizations("your.i18n.keys")`
- "[^\\w\\d]localizations\\(['\"`]({key})['\"`]\\)"
- "[^\\w\\d]localizations\\([\r\n\t]*['\"`]({key})['\"`][\r\n\t,]*\\)"
# Detect `t("your.i18n.keys"`
- "[^\\w\\d]t\\(\\s*['\"`]({key})['\"`]"
# Detect `translate("your.i18n.keys"`
Expand Down
124 changes: 62 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"baseline": "./node_modules/.bin/prisma migrate resolve --applied 20220915022732_initial_state",
"migrate": "./node_modules/.bin/prisma migrate deploy",
"prisma:introspect": "./node_modules/.bin/prisma db pull",
"prisma:generate": "./node_modules/.bin/prisma generate --schema ./prisma/schema.prisma",
"prisma:generate": "./node_modules/.bin/prisma generate --no-hints --schema ./prisma/schema.prisma",
"migrations:generate": "./node_modules/.bin/prisma migrate dev --create-only",
"lint": "npm run export-version && npm run lintonly",
"lint:fix": "npm run export-version && npm run lintonly -- --fix",
Expand Down Expand Up @@ -51,7 +51,7 @@
"homepage": "https://github.com/AverageHelper/Gamgee#readme",
"dependencies": {
"@averagehelper/job-queue": "3.0.0",
"@prisma/client": "5.9.1",
"@prisma/client": "5.18.0",
"discord.js": "14.9.0",
"htmlmetaparser": "2.1.2",
"htmlparser2": "8.0.1",
Expand Down Expand Up @@ -97,7 +97,7 @@
"keep-a-changelog": "2.5.3",
"nodemon": "3.1.4",
"prettier": "3.2.5",
"prisma": "5.9.1",
"prisma": "5.18.0",
"rollup": "4.12.0",
"rollup-plugin-analyzer": "4.0.0",
"rollup-plugin-esbuild": "6.1.1",
Expand Down
8 changes: 4 additions & 4 deletions src/actions/messages/editMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function stopEscapingUriInString(content: string): string {

let freed = content.slice(0);

uris.reverse().forEach(range => {
for (const range of uris.reverse()) {
// Remove tails
if (freed[range.end] === ">") {
freed = freed.slice(0, range.end) + freed.slice(range.end + 1);
Expand All @@ -87,7 +87,7 @@ export function stopEscapingUriInString(content: string): string {
if (freed[range.start - 1] === "<") {
freed = freed.slice(0, range.start - 1) + freed.slice(range.start);
}
});
}

return freed;
}
Expand All @@ -105,7 +105,7 @@ export function escapeUriInString(content: string): string {
let suppressed = content.slice(0);
let delta = 0;

uris.forEach(range => {
for (const range of uris) {
// Add heads
if (suppressed[range.start - 1 + delta] !== "<") {
suppressed = `${suppressed.slice(0, range.start + delta)}<${suppressed.slice(
Expand All @@ -121,7 +121,7 @@ export function escapeUriInString(content: string): string {
)}`;
delta += 1;
}
});
}

return suppressed;
}
Expand Down
20 changes: 9 additions & 11 deletions src/actions/queue/useQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,29 @@ function queueMessageFromEntry(
export async function playtimeRemainingInQueue(queueChannel: TextChannel): Promise<number> {
const queue = await getAllStoredEntries(queueChannel);
let duration = 0;
queue
.filter(e => !e.isDone)
.forEach(e => {
duration += e.seconds;
});
for (const e of queue.filter(e => !e.isDone)) {
duration += e.seconds;
}
return duration;
}

/** Retrieves the total playtime (in seconds) of the queue's entries. */
export async function playtimeTotalInQueue(queueChannel: TextChannel): Promise<number> {
const queue = await getAllStoredEntries(queueChannel);
let duration = 0;
queue.forEach(e => {
for (const e of queue) {
duration += e.seconds;
});
}
return duration;
}

/** Retrieves the average playtime (in seconds) of the queue's entries. */
export async function playtimeAverageInQueue(queueChannel: TextChannel): Promise<number> {
const queue = await getAllStoredEntries(queueChannel);
let average = 0;
queue.forEach(e => {
for (const e of queue) {
average += e.seconds;
});
}
average /= queue.length;
return average;
}
Expand Down Expand Up @@ -157,9 +155,9 @@ export async function averageSubmissionPlaytimeForUser(
const entries = await getAllStoredEntriesFromSender(userId, queueChannel);
let average = 0;

entries.forEach(entry => {
for (const entry of entries) {
average += entry.seconds;
});
}
average /= entries.length;

return average;
Expand Down
4 changes: 3 additions & 1 deletion src/commands/CommandContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
InteractionReplyOptions,
LocaleString,
Message,
MessageMentionOptions,
MessageReplyOptions,
User,
} from "discord.js";
Expand Down Expand Up @@ -102,9 +103,10 @@ interface BaseCommandContext {
readonly followUp: (
options:
| string
| Omit<MessageReplyOptions, "flags">
| (Omit<MessageReplyOptions, "flags"> & { readonly allowedMentions?: MessageMentionOptions })
| (Omit<InteractionReplyOptions, "flags"> & {
readonly reply?: boolean;
readonly allowedMentions?: MessageMentionOptions;
}),
) => Promise<Message | boolean>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ function addMock(command: Command): void {
}

// Add all commands to our mock commands list
_allCommands.forEach(cmd => addMock(cmd));
_allCommands.forEach(addMock);
4 changes: 2 additions & 2 deletions src/commands/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const languages: GlobalCommand = {
}

let totalUse = 0;
Object.values(languages).forEach(val => {
for (const val of Object.values(languages)) {
totalUse += val ?? 0;
});
}

const stats = Object.entries(languages).map(([languageName, languageUse]) => {
const use = (languageUse ?? 0) / totalUse;
Expand Down
Loading

0 comments on commit 96b28e3

Please sign in to comment.