Merge pull request #3344 from github/robertbrignull/correct-types

Use correct types where possible instead of any
This commit is contained in:
Robert
2024-02-12 16:51:06 +00:00
committed by GitHub
7 changed files with 16 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ import { pathExists, readJson, writeJson } from "fs-extra";
import { resolve, relative } from "path"; import { resolve, relative } from "path";
import type { Octokit } from "@octokit/core"; import type { Octokit } from "@octokit/core";
import type { EndpointDefaults } from "@octokit/types";
import type { RestEndpointMethodTypes } from "@octokit/rest"; import type { RestEndpointMethodTypes } from "@octokit/rest";
import { throttling } from "@octokit/plugin-throttling"; import { throttling } from "@octokit/plugin-throttling";
@@ -42,7 +43,7 @@ const octokit = new MyOctokit({
throttle: { throttle: {
onRateLimit: ( onRateLimit: (
retryAfter: number, retryAfter: number,
options: any, options: EndpointDefaults,
octokit: Octokit, octokit: Octokit,
): boolean => { ): boolean => {
octokit.log.warn( octokit.log.warn(
@@ -53,7 +54,7 @@ const octokit = new MyOctokit({
}, },
onSecondaryRateLimit: ( onSecondaryRateLimit: (
_retryAfter: number, _retryAfter: number,
options: any, options: EndpointDefaults,
octokit: Octokit, octokit: Octokit,
): void => { ): void => {
octokit.log.warn( octokit.log.warn(

View File

@@ -243,7 +243,7 @@ type WorkflowRunListItem = {
async function replaceAsync( async function replaceAsync(
str: string, str: string,
regex: RegExp, regex: RegExp,
replacer: (substring: string, ...args: any[]) => Promise<string>, replacer: (substring: string, ...args: string[]) => Promise<string>,
) { ) {
const promises: Array<Promise<string>> = []; const promises: Array<Promise<string>> = [];
str.replace(regex, (match, ...args) => { str.replace(regex, (match, ...args) => {

View File

@@ -17,7 +17,7 @@ export function convertNonPrintableChars(label: string | undefined) {
* If the label contains certain non-printable characters, loop through each * If the label contains certain non-printable characters, loop through each
* character and replace it with the cooresponding unicode control label. * character and replace it with the cooresponding unicode control label.
*/ */
const convertedLabelArray: any[] = []; const convertedLabelArray: string[] = [];
for (let i = 0; i < label.length; i++) { for (let i = 0; i < label.length; i++) {
const labelCheck = label.codePointAt(i)!; const labelCheck = label.codePointAt(i)!;
if (labelCheck <= CONTROL_CODE) { if (labelCheck <= CONTROL_CODE) {

View File

@@ -16,7 +16,7 @@ export class MultiCancellationToken implements CancellationToken {
return this.tokens.some((t) => t.isCancellationRequested); return this.tokens.some((t) => t.isCancellationRequested);
} }
onCancellationRequested<T>(listener: (e: T) => any): Disposable { onCancellationRequested<T>(listener: (e: T) => void): Disposable {
return new DisposableObject( return new DisposableObject(
...this.tokens.map((t) => t.onCancellationRequested(listener)), ...this.tokens.map((t) => t.onCancellationRequested(listener)),
); );

View File

@@ -6,6 +6,7 @@ import type { BaseLogger } from "../common/logging";
import { AppOctokit } from "../common/octokit"; import { AppOctokit } from "../common/octokit";
import type { ProgressCallback } from "../common/vscode/progress"; import type { ProgressCallback } from "../common/vscode/progress";
import { UserCancellationException } from "../common/vscode/progress"; import { UserCancellationException } from "../common/vscode/progress";
import type { EndpointDefaults } from "@octokit/types";
export async function getCodeSearchRepositories( export async function getCodeSearchRepositories(
query: string, query: string,
@@ -54,14 +55,17 @@ async function provideOctokitWithThrottling(
const octokit = new MyOctokit({ const octokit = new MyOctokit({
auth, auth,
throttle: { throttle: {
onRateLimit: (retryAfter: number, options: any): boolean => { onRateLimit: (retryAfter: number, options: EndpointDefaults): boolean => {
void logger.log( void logger.log(
`Rate Limit detected for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds!`, `Rate Limit detected for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds!`,
); );
return true; return true;
}, },
onSecondaryRateLimit: (_retryAfter: number, options: any): void => { onSecondaryRateLimit: (
_retryAfter: number,
options: EndpointDefaults,
): void => {
void logger.log( void logger.log(
`Secondary Rate Limit detected for request ${options.method} ${options.url}`, `Secondary Rate Limit detected for request ${options.method} ${options.url}`,
); );

View File

@@ -590,7 +590,7 @@ export async function convertGithubNwoToDatabaseUrl(
repo, repo,
}); });
const languages = response.data.map((db: any) => db.language); const languages = response.data.map((db) => db.language);
if (!language || !languages.includes(language)) { if (!language || !languages.includes(language)) {
language = await promptForLanguage(languages, progress); language = await promptForLanguage(languages, progress);

View File

@@ -14,6 +14,7 @@ import { getErrorMessage } from "../common/helpers-pure";
import { FALLBACK_QLPACK_FILENAME, getQlPackFilePath } from "../common/ql"; import { FALLBACK_QLPACK_FILENAME, getQlPackFilePath } from "../common/ql";
import type { App } from "../common/app"; import type { App } from "../common/app";
import type { ExtensionApp } from "../common/vscode/vscode-app"; import type { ExtensionApp } from "../common/vscode/vscode-app";
import type { QlPackFile } from "../packaging/qlpack-file";
const QUICK_QUERIES_DIR_NAME = "quick-queries"; const QUICK_QUERIES_DIR_NAME = "quick-queries";
const QUICK_QUERY_QUERY_NAME = "quick-query.ql"; const QUICK_QUERY_QUERY_NAME = "quick-query.ql";
@@ -125,7 +126,7 @@ export async function displayQuickQuery(
// Only rewrite the qlpack file if the database has changed // Only rewrite the qlpack file if the database has changed
if (shouldRewrite) { if (shouldRewrite) {
const quickQueryQlpackYaml: any = { const quickQueryQlpackYaml: QlPackFile = {
name: "vscode/quick-query", name: "vscode/quick-query",
version: "1.0.0", version: "1.0.0",
dependencies: { dependencies: {
@@ -175,6 +176,6 @@ async function checkShouldRewrite(
if (!(await pathExists(qlPackFile))) { if (!(await pathExists(qlPackFile))) {
return true; return true;
} }
const qlPackContents: any = load(await readFile(qlPackFile, "utf8")); const qlPackContents = load(await readFile(qlPackFile, "utf8")) as QlPackFile;
return !qlPackContents.dependencies?.[newDependency]; return !qlPackContents.dependencies?.[newDependency];
} }