Skip to content

Commit

Permalink
Enable no-unsafe-return rule
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Jun 13, 2024
1 parent 2f54d9f commit 1ea11ca
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 26 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/require-await": "off",
Expand Down
2 changes: 1 addition & 1 deletion lib/api-client.js.map

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

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/upload-lib.js

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

2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export async function getWorkflowRelativePath(): Promise<string> {

const workflowResponse = await apiClient.request(`GET ${workflowUrl}`);

return workflowResponse.data.path;
return workflowResponse.data.path as string;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,10 @@ export function stubToolRunnerConstructor(
stderr?: string,
): sinon.SinonStub<any[], toolrunner.ToolRunner> {
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
const runnerConstructorStub = sinon.stub(toolrunner, "ToolRunner");
const runnerConstructorStub = sinon.stub(
toolrunner,
"ToolRunner",
) as sinon.SinonStub<any[], toolrunner.ToolRunner>;
let stderrListener: ((data: Buffer) => void) | undefined = undefined;
runnerConstructorStub.callsFake((_cmd, _args, options: ExecOptions) => {
stderrListener = options.listeners?.stderr;
Expand Down
16 changes: 8 additions & 8 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ function resolveFunction<T>(
const dummyMethod = () => {
throw new Error(`CodeQL ${methodName} method not correctly defined`);
};
return dummyMethod as any;
return dummyMethod as T;
}
return partialCodeql[methodName];
return partialCodeql[methodName] as T;
}

/**
Expand Down Expand Up @@ -740,7 +740,7 @@ export async function getCodeQLForCmd(
const output = await runTool(cmd, codeqlArgs);

try {
return JSON.parse(output);
return JSON.parse(output) as ResolveLanguagesOutput;
} catch (e) {
throw new Error(
`Unexpected output from codeql resolve languages: ${e}`,
Expand All @@ -759,7 +759,7 @@ export async function getCodeQLForCmd(
const output = await runTool(cmd, codeqlArgs);

try {
return JSON.parse(output);
return JSON.parse(output) as BetterResolveLanguagesOutput;
} catch (e) {
throw new Error(
`Unexpected output from codeql resolve languages with --format=betterjson: ${e}`,
Expand All @@ -783,7 +783,7 @@ export async function getCodeQLForCmd(
const output = await runTool(cmd, codeqlArgs);

try {
return JSON.parse(output);
return JSON.parse(output) as ResolveQueriesOutput;
} catch (e) {
throw new Error(`Unexpected output from codeql resolve queries: ${e}`);
}
Expand All @@ -805,7 +805,7 @@ export async function getCodeQLForCmd(
const output = await runTool(cmd, codeqlArgs);

try {
return JSON.parse(output);
return JSON.parse(output) as ResolveBuildEnvironmentOutput;
} catch (e) {
throw new Error(
`Unexpected output from codeql resolve build-environment: ${e} in\n${output}`,
Expand Down Expand Up @@ -1093,7 +1093,7 @@ export async function getCodeQLForCmd(
},
},
).exec();
return JSON.parse(extractorPath);
return JSON.parse(extractorPath) as string;
},
async mergeResults(
sarifFiles: string[],
Expand Down Expand Up @@ -1347,7 +1347,7 @@ async function generateCodeScanningConfig(
}

function cloneObject<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj));
return JSON.parse(JSON.stringify(obj)) as T;
}

// This constant sets the size of each TRAP cache in megabytes.
Expand Down
2 changes: 1 addition & 1 deletion src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ export async function getConfig(
const configString = fs.readFileSync(configFile, "utf8");
logger.debug("Loaded config:");
logger.debug(configString);
return JSON.parse(configString);
return JSON.parse(configString) as Config;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ class GitHubFeatureFlags {
this.logger.debug(
`Loading feature flags from ${this.featureFlagsFile}`,
);
return JSON.parse(fs.readFileSync(this.featureFlagsFile, "utf8"));
return JSON.parse(
fs.readFileSync(this.featureFlagsFile, "utf8"),
) as GitHubFeatureFlagsApiResponse;
}
} catch (e) {
this.logger.warning(
Expand Down
6 changes: 3 additions & 3 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async function uploadPayload(
payload: any,
repositoryNwo: RepositoryNwo,
logger: Logger,
) {
): Promise<string> {
logger.info("Uploading results");

// If in test mode we don't want to upload the results
Expand All @@ -323,7 +323,7 @@ async function uploadPayload(
);
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
return;
return "test-mode-sarif-id";
}

const client = api.getApiClient();
Expand All @@ -340,7 +340,7 @@ async function uploadPayload(

logger.debug(`response status: ${response.status}`);
logger.info("Successfully uploaded results");
return response.data.id;
return response.data.id as string;
} catch (e) {
if (util.isHTTPError(e)) {
switch (e.status) {
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function getExtraOptionsEnvParam(): object {
return {};
}
try {
return JSON.parse(raw);
return JSON.parse(raw) as object;
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
throw new ConfigurationError(
Expand Down Expand Up @@ -888,7 +888,7 @@ export function parseMatrixInput(
if (matrixInput === undefined || matrixInput === "null") {
return undefined;
}
return JSON.parse(matrixInput);
return JSON.parse(matrixInput) as { [key: string]: string };
}

function removeDuplicateLocations(locations: SarifLocation[]): SarifLocation[] {
Expand Down

0 comments on commit 1ea11ca

Please sign in to comment.