diff --git a/eslint.config.mjs b/eslint.config.mjs index de32bf1..343a24b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -16,5 +16,18 @@ export default tseslint.config( tsconfigRootDir: import.meta.dirname, }, }, + rules: { + "no-shadow": "off", + "@typescript-eslint/no-shadow": "error", + "@typescript-eslint/strict-boolean-expressions": [ + "error", + { + allowString: true, + allowNumber: false, + allowNullableObject: false, + }, + ], + "@typescript-eslint/switch-exhaustiveness-check": "error", + }, }, ); diff --git a/src/publish.ts b/src/publish.ts index 6caec36..b9ae812 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -23,7 +23,7 @@ function checkRequestAuthentication( expectedPassword: Buffer, ): Response | "ok" { const authorization = request.headers.get("Authorization"); - if (!authorization) { + if (authorization === null) { return new Response("Authorization failed", { status: 401, // Unauthorized headers: { @@ -240,14 +240,14 @@ export async function handlePublish( } if (key.endsWith(".minisign")) { - assert(!artifactMinisigns[key]); // keys are unique + assert(artifactMinisigns[key] === undefined); // keys are unique artifactMinisigns[key] = file; continue; } const match = key.match(artifactRegex); - if (!match) { + if (match === null) { return new Response(`failed to parse artifact '${key}'!`, { status: 400, // Bad Request }); @@ -264,7 +264,7 @@ export async function handlePublish( // `os=${os}, arch=${arch}, version=${version}, extension=${extension}, shasum=${file_hash.digest("hex")}, size=${value.size.toString()}`, // ); - if (!SemanticVersion.parse(version)) { + if (SemanticVersion.parse(version) === null) { return new Response( `artifact '${key}' has an invalid version '${version}'!`, { diff --git a/src/select-zls-version.ts b/src/select-zls-version.ts index 45ec3a0..ec3df03 100644 --- a/src/select-zls-version.ts +++ b/src/select-zls-version.ts @@ -92,7 +92,7 @@ export async function handleSelectZLSVersion( const zigVersion = SemanticVersion.parse(zigVersionString); - if (!zigVersion) { + if (zigVersion === null) { return new Response( `Query component 'zig_version' with value '${zigVersionString}' is not a valid version!`, { @@ -139,7 +139,7 @@ async function selectOnTaggedRelease( .bind(zigVersion.major, zigVersion.minor) .first<{ JsonData: string }>(); - if (!selectedRelease) return null; + if (selectedRelease === null) return null; return JSON.parse(selectedRelease.JsonData) as D2JsonData; } @@ -221,7 +221,7 @@ async function selectOnDevelopmentBuild( .bind(zigVersion.major, zigVersion.minor) .all<{ JsonData: string }>(); - if (!releases.results.length) return null; + if (releases.results.length === 0) return null; const oldestRelease = releases.results[0]; const oldestReleaseData = JSON.parse(oldestRelease.JsonData) as D2JsonData; diff --git a/src/semantic-version.ts b/src/semantic-version.ts index 55026ae..2ff010f 100644 --- a/src/semantic-version.ts +++ b/src/semantic-version.ts @@ -22,7 +22,7 @@ export class SemanticVersion { const regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-dev\.(\d+)\+([0-9a-fA-F]{7,9}))?$/; const match = string.match(regex); - if (!match) return null; + if (match === null) return null; const semver = new SemanticVersion(); semver.major = parseInt(match[1]); @@ -71,7 +71,7 @@ export class SemanticVersion { public toString(): string { const a = `${this.major.toString()}.${this.minor.toString()}.${this.patch.toString()}`; if (this.isRelease) return a; - assert(this.commitHeight && this.commitID); + assert(this.commitHeight !== undefined && this.commitID !== undefined); return `${a}-dev.${this.commitHeight.toString()}+${this.commitID}`; } diff --git a/test/publish.test.ts b/test/publish.test.ts index 860af1c..c46125f 100644 --- a/test/publish.test.ts +++ b/test/publish.test.ts @@ -18,7 +18,7 @@ async function searchZLSRelease( ) .bind(zlsVersion) .first("JsonData"); - if (!jsonString) return null; + if (jsonString === null) return null; return JSON.parse(jsonString) as D2JsonData; }