diff --git a/packages/eslint-config-discordeno/index.js b/packages/eslint-config-discordeno/index.js index f6f632e6e..c6c043f65 100644 --- a/packages/eslint-config-discordeno/index.js +++ b/packages/eslint-config-discordeno/index.js @@ -1,21 +1,22 @@ module.exports = { env: { es2021: true, - node: true + node: true, }, - extends: ['standard-with-typescript','prettier'], + extends: ['standard-with-typescript', 'prettier', 'plugin:require-extensions/recommended'], overrides: [ { files: ['*.spec.ts'], rules: { - '@typescript-eslint/no-unused-expressions': 'off' - } - } + '@typescript-eslint/no-unused-expressions': 'off', + }, + }, ], + plugins: ['require-extensions'], parserOptions: { ecmaVersion: 'latest', sourceType: 'module', - project: ['./tsconfig.json'] + project: ['./tsconfig.json'], }, rules: { '@typescript-eslint/strict-boolean-expressions': 'off', @@ -25,5 +26,5 @@ module.exports = { '@typescript-eslint/no-invalid-void-type': 'off', '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/no-misused-promises': 'off', - } + }, } diff --git a/packages/eslint-config-discordeno/package.json b/packages/eslint-config-discordeno/package.json index 7186eaae8..a4831e401 100644 --- a/packages/eslint-config-discordeno/package.json +++ b/packages/eslint-config-discordeno/package.json @@ -12,6 +12,7 @@ "eslint-plugin-import": "^2.25.2", "eslint-plugin-n": "^15.0.0", "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-require-extensions": "^0.1.1", "typescript": "^4.9.3" }, "publishConfig": { diff --git a/packages/rest/src/queue.ts b/packages/rest/src/queue.ts index 69a158087..b492b7c9b 100644 --- a/packages/rest/src/queue.ts +++ b/packages/rest/src/queue.ts @@ -1,5 +1,5 @@ import { delay } from '@discordeno/utils' -import type { RestManager, SendRequestOptions } from './manager' +import type { RestManager, SendRequestOptions } from './manager.js' export class Queue { /** The rest manager */ @@ -27,7 +27,7 @@ export class Queue { /** When requests started being made to determine when the interval will reset it. */ frozenAt: number = 0 - constructor (rest: RestManager, options: QueueOptions) { + constructor(rest: RestManager, options: QueueOptions) { this.rest = rest this.url = options.url @@ -38,12 +38,12 @@ export class Queue { } /** Check if there is any remaining requests that are allowed. */ - isRequestAllowed (): boolean { + isRequestAllowed(): boolean { return this.remaining > 0 } /** Pauses the execution until a request is allowed to be made. */ - async waitUntilRequestAvailable (): Promise { + async waitUntilRequestAvailable(): Promise { // eslint-disable-next-line no-async-promise-executor return await new Promise(async (resolve) => { // If whatever amount of requests is left is more than the safety margin, allow the request @@ -58,7 +58,7 @@ export class Queue { } /** Process the queue of requests waiting to be handled. */ - async processWaiting (): Promise { + async processWaiting(): Promise { // If already processing, that loop will handle all waiting requests. if (this.processing) return // Mark as processing so other loops don't start @@ -78,7 +78,7 @@ export class Queue { } /** Process the queue of all requests pending to be sent. */ - async processPending (): Promise { + async processPending(): Promise { // If already processing, that loop will handle all pending requests. if (this.processingPending || !this.pending.length) return @@ -95,10 +95,7 @@ export class Queue { const request = this.pending[0] if (request) { - const basicURL = this.rest.simplifyUrl( - request.url, - request.method - ) + const basicURL = this.rest.simplifyUrl(request.url, request.method) // IF THIS URL IS STILL RATE LIMITED, TRY AGAIN // If this url is still rate limited, try again @@ -106,10 +103,7 @@ export class Queue { if (urlResetIn) await delay(urlResetIn) // IF A BUCKET EXISTS, CHECK THE BUCKET'S RATE LIMITS - const bucketResetIn = - request.bucketId - ? this.rest.checkRateLimits(request.bucketId) - : false + const bucketResetIn = request.bucketId ? this.rest.checkRateLimits(request.bucketId) : false if (bucketResetIn) await delay(bucketResetIn) this.firstRequest = false @@ -127,7 +121,8 @@ export class Queue { // Check if this request is able to be made globally await this.rest.invalidBucket.waitUntilRequestAvailable() - await this.rest.sendRequest(request) + await this.rest + .sendRequest(request) // Should be handled in sendRequest, this catch just prevents bots from dying .catch(() => null) } @@ -138,7 +133,7 @@ export class Queue { this.cleanup() } - handleCompletedRequest (headers: { max?: number, interval?: number, remaining?: number }): void { + handleCompletedRequest(headers: { max?: number; interval?: number; remaining?: number }): void { if (headers.max === 0) { this.remaining++ return @@ -156,14 +151,14 @@ export class Queue { } } - async makeRequest (options: SendRequestOptions): Promise { + async makeRequest(options: SendRequestOptions): Promise { await this.waitUntilRequestAvailable() this.pending.push(options) this.processPending() } /** Cleans up the queue by checking if there is nothing left and removing it. */ - cleanup (): void { + cleanup(): void { if (!this.isQueueClearable()) { this.processPending() return @@ -180,7 +175,7 @@ export class Queue { }, 60000) } - isQueueClearable (): boolean { + isQueueClearable(): boolean { if (this.firstRequest) return false if (this.waiting.length > 0) return false if (this.pending.length > 0) return false diff --git a/yarn.lock b/yarn.lock index cc65764aa..c639f8b0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1880,6 +1880,7 @@ __metadata: eslint-plugin-import: ^2.25.2 eslint-plugin-n: ^15.0.0 eslint-plugin-promise: ^6.0.0 + eslint-plugin-require-extensions: ^0.1.1 typescript: ^4.9.3 languageName: unknown linkType: soft @@ -2008,6 +2009,15 @@ __metadata: languageName: node linkType: hard +"eslint-plugin-require-extensions@npm:^0.1.1": + version: 0.1.1 + resolution: "eslint-plugin-require-extensions@npm:0.1.1" + peerDependencies: + eslint: "*" + checksum: 1207d33b0c8c86384737acfdb4675db77a9d5579334b19ce9f404c5913e249c6bebc015fa77942c942b18d40bb7e34baaeaafb62f2c8f80cd2c0044a40e0e546 + languageName: node + linkType: hard + "eslint-scope@npm:^5.1.1": version: 5.1.1 resolution: "eslint-scope@npm:5.1.1"