fix: make sure the tool has a default version before using it

This commit is contained in:
Amin Yahyaabadi 2023-06-14 00:22:24 -07:00
parent 775ff238d7
commit 18a5143dce
6 changed files with 9 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@ function getLLVMDefault() {
}
}
export const DefaultVersions: Record<string, string> = {
export const DefaultVersions: Record<string, string | undefined> = {
llvm: getLLVMDefault(), // https://github.com/llvm/llvm-project/releases
clangtidy: getLLVMDefault(),
clangformat: getLLVMDefault(),

View File

@ -5,11 +5,11 @@ import { DefaultLinuxVersion, DefaultVersions } from "./default_versions"
/** Get the default version if passed true or undefined, otherwise return the version itself */
export function getVersion(name: string, version: string | undefined, osVersion: number[] | null = null) {
if (isDefault(version, name)) {
if (process.platform === "linux" && osVersion !== null && name in DefaultLinuxVersion) {
if (process.platform === "linux" && osVersion !== null) {
return getDefaultLinuxVersion(name, osVersion)
}
// anything else
return DefaultVersions[name]
return DefaultVersions[name]! // checked by isDefault
} else {
return version ?? ""
}
@ -28,8 +28,8 @@ function getDefaultLinuxVersion(name: string, osVersion: number[]) {
return satisfyingVersion === undefined ? "" : DefaultLinuxVersion[name][satisfyingVersion]
}
export function isDefault(version: string | undefined, name: string) {
return version === "true" || (version === undefined && name in DefaultVersions)
function isDefault(version: string | undefined, name: string) {
return (version === "true" || version === undefined) && name in DefaultLinuxVersion
}
/**