Skip to content

Commit

Permalink
remove implicit null and zero checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed May 24, 2024
1 parent d2f6bdd commit 30ce1b8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
);
8 changes: 4 additions & 4 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
});
Expand All @@ -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}'!`,
{
Expand Down
6 changes: 3 additions & 3 deletions src/select-zls-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!`,
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/semantic-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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}`;
}

Expand Down
2 changes: 1 addition & 1 deletion test/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function searchZLSRelease(
)
.bind(zlsVersion)
.first<string>("JsonData");
if (!jsonString) return null;
if (jsonString === null) return null;
return JSON.parse(jsonString) as D2JsonData;
}

Expand Down

0 comments on commit 30ce1b8

Please sign in to comment.