Fix linter errors
This commit is contained in:
parent
5f644f971e
commit
10695e6a20
46 changed files with 93 additions and 62 deletions
|
|
@ -445,7 +445,7 @@ export async function createStatusReportBase(
|
|||
status,
|
||||
testing_environment: testingEnvironment,
|
||||
runner_os: runnerOs,
|
||||
action_version: pkg.version,
|
||||
action_version: pkg.version as string,
|
||||
};
|
||||
|
||||
// Add optional parameters
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ async function run() {
|
|||
let trapCacheUploadTime: number | undefined = undefined;
|
||||
let dbCreationTimings: DatabaseCreationTimings | undefined = undefined;
|
||||
let didUploadTrapCaches = false;
|
||||
util.initializeEnvironment(pkg.version);
|
||||
await util.checkActionVersion(pkg.version);
|
||||
util.initializeEnvironment(pkg.version as string);
|
||||
await util.checkActionVersion(pkg.version as string);
|
||||
|
||||
const logger = getActionsLogger();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ test("validateQueryFilters", (t) => {
|
|||
|
||||
t.throws(
|
||||
() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
return validateQueryFilters({ exclude: "foo" } as any);
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -454,7 +454,7 @@ export function createQuerySuiteContents(
|
|||
queryFilters: configUtils.QueryFilter[]
|
||||
) {
|
||||
return yaml.dump(
|
||||
queries.map((q: string) => ({ query: q })).concat(queryFilters as any)
|
||||
queries.map((q: string) => ({ query: q })).concat(queryFilters as any[])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ test.beforeEach(() => {
|
|||
pluginStub = sinon.stub(githubUtils.GitHub, "plugin");
|
||||
githubStub = sinon.stub();
|
||||
pluginStub.returns(githubStub);
|
||||
util.initializeEnvironment(pkg.version);
|
||||
util.initializeEnvironment(pkg.version as string);
|
||||
});
|
||||
|
||||
test("getApiClient", async (t) => {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ async function sendCompletedStatusReport(
|
|||
failingLanguage?: string,
|
||||
cause?: Error
|
||||
) {
|
||||
initializeEnvironment(pkg.version);
|
||||
initializeEnvironment(pkg.version as string);
|
||||
|
||||
const status = getActionsStatus(cause, failingLanguage);
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
|
|
@ -57,7 +57,7 @@ async function sendCompletedStatusReport(
|
|||
async function run() {
|
||||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
await checkActionVersion(pkg.version);
|
||||
await checkActionVersion(pkg.version as string);
|
||||
let currentLanguage: Language | undefined = undefined;
|
||||
let languages: Language[] | undefined = undefined;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -582,13 +582,13 @@ const injectedConfigMacro = test.macro({
|
|||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
const args = runnerConstructorStub.firstCall.args[1] as string[];
|
||||
// should have used an config file
|
||||
const configArg = args.find((arg: string) =>
|
||||
arg.startsWith("--codescanning-config=")
|
||||
);
|
||||
t.truthy(configArg, "Should have injected a codescanning config");
|
||||
const configFile = configArg.split("=")[1];
|
||||
const configFile = configArg!.split("=")[1];
|
||||
const augmentedConfig = yaml.load(fs.readFileSync(configFile, "utf8"));
|
||||
t.deepEqual(augmentedConfig, expectedConfig);
|
||||
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ async function downloadCodeQL(
|
|||
`Downloading CodeQL tools from ${codeqlURL}. This may take a while.`
|
||||
);
|
||||
|
||||
const dest = path.join(tempDir, uuidV4());
|
||||
const dest = path.join(tempDir, uuidV4() as string);
|
||||
const finalHeaders = Object.assign(
|
||||
{ "User-Agent": "CodeQL Action" },
|
||||
headers
|
||||
|
|
@ -987,7 +987,7 @@ async function getCodeQLForCmd(
|
|||
// Set trace command
|
||||
const ext = process.platform === "win32" ? ".cmd" : ".sh";
|
||||
const traceCommand = path.resolve(
|
||||
JSON.parse(extractorPath),
|
||||
JSON.parse(extractorPath) as string,
|
||||
"tools",
|
||||
`autobuild${ext}`
|
||||
);
|
||||
|
|
@ -1460,6 +1460,6 @@ async function generateCodeScanningConfig(
|
|||
return configLocation;
|
||||
}
|
||||
|
||||
function cloneObject(obj: any) {
|
||||
function cloneObject<T>(obj: T): T {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import * as sinon from "sinon";
|
|||
import * as api from "./api-client";
|
||||
import { getCachedCodeQL, PackDownloadOutput, setCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { RegistryConfigWithCredentials } from "./config-utils";
|
||||
import { Feature } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger, Logger } from "./logging";
|
||||
|
|
@ -51,6 +52,7 @@ function mockGetContents(
|
|||
};
|
||||
const spyGetContents = sinon
|
||||
.stub(client.repos, "getContent")
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
.resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
sinon.stub(api, "getApiClientWithExternalAuth").value(() => client);
|
||||
|
|
@ -66,6 +68,7 @@ function mockListLanguages(languages: string[]) {
|
|||
for (const language of languages) {
|
||||
response.data[language] = 123;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
sinon.stub(client.repos, "listLanguages").resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
}
|
||||
|
|
@ -2310,7 +2313,7 @@ test("downloadPacks-with-registries", async (t) => {
|
|||
|
||||
const expectedConfigFile = path.join(tmpDir, "qlconfig.yml");
|
||||
const packDownloadStub = sinon.stub();
|
||||
packDownloadStub.callsFake((packs, configFile) => {
|
||||
packDownloadStub.callsFake((packs, configFile: string) => {
|
||||
t.deepEqual(configFile, expectedConfigFile);
|
||||
// verify the env vars were set correctly
|
||||
t.deepEqual(process.env.GITHUB_TOKEN, sampleApiDetails.auth);
|
||||
|
|
@ -2439,7 +2442,7 @@ test("downloadPacks-with-registries fails with invalid registries block", async
|
|||
codeQL,
|
||||
[Language.javascript, Language.java, Language.python],
|
||||
{},
|
||||
registries as any,
|
||||
registries as RegistryConfigWithCredentials[] | undefined,
|
||||
sampleApiDetails,
|
||||
tmpDir,
|
||||
logger
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ export async function uploadDebugArtifacts(
|
|||
const matrix = getRequiredInput("matrix");
|
||||
if (matrix) {
|
||||
try {
|
||||
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
|
||||
for (const [, matrixVal] of Object.entries(
|
||||
JSON.parse(matrix) as any[][]
|
||||
).sort())
|
||||
suffix += `-${matrixVal}`;
|
||||
} catch (e) {
|
||||
core.info(
|
||||
|
|
@ -163,7 +165,7 @@ export async function uploadDatabaseBundleDebugArtifact(
|
|||
) {
|
||||
for (const language of config.languages) {
|
||||
try {
|
||||
let databaseBundlePath;
|
||||
let databaseBundlePath: string;
|
||||
if (!dbIsFinalized(config, language, logger)) {
|
||||
databaseBundlePath = await createPartialDatabaseBundle(
|
||||
config,
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ class GitHubFeatureFlags implements FeatureEnablement {
|
|||
}
|
||||
}
|
||||
|
||||
private async loadApiResponse() {
|
||||
private async loadApiResponse(): Promise<GitHubFeatureFlagsApiResponse> {
|
||||
// Do nothing when not running against github.com
|
||||
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
|
||||
this.logger.debug(
|
||||
|
|
@ -265,5 +265,6 @@ class GitHubFeatureFlags implements FeatureEnablement {
|
|||
);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ test("addFingerprints", async (t) => {
|
|||
fs
|
||||
.readFileSync(`${__dirname}/../src/testdata/fingerprinting.input.sarif`)
|
||||
.toString()
|
||||
);
|
||||
) as util.SarifFile;
|
||||
const expected = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
|
|
@ -229,7 +229,7 @@ test("missingRegions", async (t) => {
|
|||
fs
|
||||
.readFileSync(`${__dirname}/../src/testdata/fingerprinting2.input.sarif`)
|
||||
.toString()
|
||||
);
|
||||
) as util.SarifFile;
|
||||
const expected = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ type hashCallback = (lineNumber: number, hash: string) => void;
|
|||
*/
|
||||
export async function hash(callback: hashCallback, filepath: string) {
|
||||
// A rolling view in to the input
|
||||
const window = Array(BLOCK_SIZE).fill(0);
|
||||
const window: number[] = Array(BLOCK_SIZE).fill(0);
|
||||
|
||||
// If the character in the window is the start of a new line
|
||||
// then records the line number, otherwise will be -1.
|
||||
// Indexes match up with those from the window variable.
|
||||
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
|
||||
const lineNumbers: number[] = Array(BLOCK_SIZE).fill(-1);
|
||||
|
||||
// The current hash value, updated as we read each character
|
||||
let hashRaw = Long.ZERO;
|
||||
|
|
@ -120,7 +120,7 @@ export async function hash(callback: hashCallback, filepath: string) {
|
|||
const readStream = fs.createReadStream(filepath, "utf8");
|
||||
for await (const data of readStream) {
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
processCharacter(data.charCodeAt(i));
|
||||
processCharacter((data as string).charCodeAt(i));
|
||||
}
|
||||
}
|
||||
processCharacter(EOF);
|
||||
|
|
@ -201,7 +201,7 @@ export function resolveUriToFile(
|
|||
logger.debug(`Ignoring location as URI "${location.uri}" is invalid`);
|
||||
return undefined;
|
||||
}
|
||||
let uri = decodeURIComponent(location.uri);
|
||||
let uri = decodeURIComponent(location.uri as string);
|
||||
|
||||
// Remove a file scheme, and abort if the scheme is anything else
|
||||
const fileUriPrefix = "file://";
|
||||
|
|
|
|||
|
|
@ -138,8 +138,8 @@ async function sendSuccessStatusReport(
|
|||
async function run() {
|
||||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
initializeEnvironment(pkg.version);
|
||||
await checkActionVersion(pkg.version);
|
||||
initializeEnvironment(pkg.version as string);
|
||||
await checkActionVersion(pkg.version as string);
|
||||
|
||||
let config: configUtils.Config;
|
||||
let codeql: CodeQL;
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ export function mockLanguagesInRepo(languages: string[]) {
|
|||
url: "GET /repos/:owner/:repo/languages",
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
mockClient.returns({
|
||||
repos: {
|
||||
listLanguages,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ export async function downloadTrapCaches(
|
|||
languages: Language[],
|
||||
logger: Logger
|
||||
): Promise<Partial<Record<Language, string>>> {
|
||||
const result = {};
|
||||
const result: Partial<Record<Language, string>> = {};
|
||||
const languagesSupportingCaching = await getLanguagesSupportingCaching(
|
||||
codeql,
|
||||
languages,
|
||||
|
|
|
|||
|
|
@ -226,7 +226,8 @@ export function countResultsInSarif(sarif: string): number {
|
|||
// Throws an error if the file is invalid.
|
||||
export function validateSarifFileSchema(sarifFilePath: string, logger: Logger) {
|
||||
const sarif = JSON.parse(fs.readFileSync(sarifFilePath, "utf8"));
|
||||
const schema = require("../src/sarif_v2.1.0_schema.json");
|
||||
const schema =
|
||||
require("../src/sarif_v2.1.0_schema.json") as jsonschema.Schema;
|
||||
|
||||
const result = new jsonschema.Validator().validate(sarif, schema);
|
||||
if (!result.valid) {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ async function sendSuccessStatusReport(
|
|||
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
initializeEnvironment(pkg.version);
|
||||
await checkActionVersion(pkg.version);
|
||||
initializeEnvironment(pkg.version as string);
|
||||
await checkActionVersion(pkg.version as string);
|
||||
if (
|
||||
!(await actionsUtil.sendStatusReport(
|
||||
await actionsUtil.createStatusReportBase(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ test("getToolNames", (t) => {
|
|||
`${__dirname}/../src/testdata/tool-names.sarif`,
|
||||
"utf8"
|
||||
);
|
||||
const toolNames = util.getToolNames(JSON.parse(input));
|
||||
const toolNames = util.getToolNames(JSON.parse(input) as util.SarifFile);
|
||||
t.deepEqual(toolNames, ["CodeQL command-line toolchain", "ESLint"]);
|
||||
});
|
||||
|
||||
|
|
@ -204,6 +204,7 @@ function mockGetMetaVersionHeader(
|
|||
};
|
||||
const spyGetContents = sinon
|
||||
.stub(client.meta, "get")
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
.resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
return spyGetContents;
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
push: 1,
|
||||
pull_request: 1,
|
||||
},
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
|
@ -153,13 +153,14 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
...errorCodes(
|
||||
getWorkflowErrors({
|
||||
on: 1,
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
...errorCodes(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: 1,
|
||||
|
|
@ -170,6 +171,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
|
||||
t.deepEqual(
|
||||
...errorCodes(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: [1],
|
||||
|
|
@ -183,7 +185,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { 1: 1 },
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
|
@ -193,7 +195,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { test: 1 },
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
|
@ -203,13 +205,14 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { test: [1] },
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
...errorCodes(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { test: { steps: 1 } },
|
||||
|
|
@ -220,6 +223,7 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
|
||||
t.deepEqual(
|
||||
...errorCodes(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { test: { steps: [{ notrun: "git checkout HEAD^2" }] } },
|
||||
|
|
@ -233,15 +237,16 @@ test("getWorkflowErrors() for a range of malformed workflows", (t) => {
|
|||
getWorkflowErrors({
|
||||
on: 1,
|
||||
jobs: { test: [undefined] },
|
||||
} as any),
|
||||
} as Workflow),
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
t.deepEqual(...errorCodes(getWorkflowErrors(1 as any), []));
|
||||
t.deepEqual(...errorCodes(getWorkflowErrors(1 as Workflow), []));
|
||||
|
||||
t.deepEqual(
|
||||
...errorCodes(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getWorkflowErrors({
|
||||
on: {
|
||||
push: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue