Skip to content

Commit

Permalink
refactor(ts-ignore): use 'ts-expect-error' to keep track when annotat…
Browse files Browse the repository at this point in the history
…ion is not necessary anymore
  • Loading branch information
oscard0m committed Mar 10, 2022
1 parent 7625ff5 commit 596782e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore
// @ts-expect-error
import BottleneckLight from "bottleneck/light";
import { Octokit } from "@octokit/core";
import { OctokitOptions } from "@octokit/core/dist-types/types.d";
Expand All @@ -20,29 +20,29 @@ const triggersNotification = regex.test.bind(regex);

const groups = {};

// @ts-ignore
// @ts-expect-error
const createGroups = function (Bottleneck, common) {
// @ts-ignore
// @ts-expect-error
groups.global = new Bottleneck.Group({
id: "octokit-global",
maxConcurrent: 10,
...common,
});
// @ts-ignore
// @ts-expect-error
groups.search = new Bottleneck.Group({
id: "octokit-search",
maxConcurrent: 1,
minTime: 2000,
...common,
});
// @ts-ignore
// @ts-expect-error
groups.write = new Bottleneck.Group({
id: "octokit-write",
maxConcurrent: 1,
minTime: 1000,
...common,
});
// @ts-ignore
// @ts-expect-error
groups.notifications = new Bottleneck.Group({
id: "octokit-notifications",
maxConcurrent: 1,
Expand Down Expand Up @@ -72,7 +72,7 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
}
const common = { connection, timeout };

// @ts-ignore
// @ts-expect-error
if (groups.global == null) {
createGroups(Bottleneck, common);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {

const events = {};
const emitter = new Bottleneck.Events(events);
// @ts-ignore
// @ts-expect-error
events.on(
"secondary-limit",
isUsingDeprecatedOnAbuseLimitHandler
Expand All @@ -125,14 +125,14 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
}
: state.onSecondaryRateLimit
);
// @ts-ignore
// @ts-expect-error
events.on("rate-limit", state.onRateLimit);
// @ts-ignore
// @ts-expect-error
events.on("error", (e) =>
octokit.log.warn("Error in throttling-plugin limit handler", e)
);

// @ts-ignore
// @ts-expect-error
state.retryLimiter.on("failed", async function (error, info) {
const options = info.args[info.args.length - 1];
const { pathname } = new URL(options.url, "http://github.test");
Expand Down Expand Up @@ -193,7 +193,7 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {

if (wantRetry) {
options.request.retryCount++;
// @ts-ignore
// @ts-expect-error
return retryAfter * state.retryAfterBaseValue;
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/route-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// @ts-ignore
// @ts-expect-error
export function routeMatcher(paths) {
// EXAMPLE. For the following paths:
/* [
"/orgs/{org}/invitations",
"/repos/{owner}/{repo}/collaborators/{username}"
] */

// @ts-ignore
// @ts-expect-error
const regexes = paths.map((path) =>
path
.split("/")
// @ts-ignore
// @ts-expect-error
.map((c) => (c.startsWith("{") ? "(?:.+?)" : c))
.join("/")
);
Expand All @@ -20,7 +20,7 @@ export function routeMatcher(paths) {
'/repos/(?:.+?)/(?:.+?)/collaborators/(?:.+?)'
] */

// @ts-ignore
// @ts-expect-error
const regex = `^(?:${regexes.map((r) => `(?:${r})`).join("|")})[^/]*$`;
// 'regex' would contain:
/*
Expand Down
8 changes: 4 additions & 4 deletions src/wrap-request.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const noop = () => Promise.resolve();

// @ts-ignore
// @ts-expect-error
export function wrapRequest(state, request, options) {
return state.retryLimiter.schedule(doRequest, state, request, options);
}

// @ts-ignore
// @ts-expect-error
async function doRequest(state, request, options) {
const isWrite = options.method !== "GET" && options.method !== "HEAD";
const { pathname } = new URL(options.url, "http://github.test");
Expand All @@ -17,7 +17,7 @@ async function doRequest(state, request, options) {
if (state.clustering) {
// Remove a job from Redis if it has not completed or failed within 60s
// Examples: Node process terminated, client disconnected, etc.
// @ts-ignore
// @ts-expect-error
jobOptions.expiration = 1000 * 60;
}

Expand All @@ -43,7 +43,7 @@ async function doRequest(state, request, options) {

if (
res.data.errors != null &&
// @ts-ignore
// @ts-expect-error
res.data.errors.some((error) => error.type === "RATE_LIMITED")
) {
const error = Object.assign(new Error("GraphQL Rate Limit Exceeded"), {
Expand Down

0 comments on commit 596782e

Please sign in to comment.