Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(fs): cleanup use of @std/assert #4948

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor(fs): cleanup use of @std/assert
  • Loading branch information
iuioiua committed Jun 4, 2024
commit abe7ac35ff7bf5da91107cdb8bb6a6791d609e02
31 changes: 18 additions & 13 deletions fs/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { join } from "@std/path/join";
import { resolve } from "@std/path/resolve";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { assert } from "@std/assert/assert";
import { getFileInfoType } from "./_get_file_info_type.ts";
import { toPathString } from "./_to_path_string.ts";
import { isSubdir } from "./_is_subdir.ts";
Expand Down Expand Up @@ -34,6 +33,12 @@
isFolder?: boolean;
}

function assertIsDate(date: Date | null, name: string): asserts date is Date {
if (date === null) {
throw new ReferenceError(`${name} is unavailable`);
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 39 in fs/copy.ts

View check run for this annotation

Codecov / codecov/patch

fs/copy.ts#L38-L39

Added lines #L38 - L39 were not covered by tests
}

async function ensureValidCopy(
src: string | URL,
dest: string | URL,
Expand Down Expand Up @@ -99,8 +104,8 @@
await Deno.copyFile(src, dest);
if (options.preserveTimestamps) {
const statInfo = await Deno.stat(src);
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(statInfo.atime, "statInfo.atime");
assertIsDate(statInfo.mtime, "statInfo.mtime");
await Deno.utime(dest, statInfo.atime, statInfo.mtime);
}
}
Expand All @@ -114,8 +119,8 @@
Deno.copyFileSync(src, dest);
if (options.preserveTimestamps) {
const statInfo = Deno.statSync(src);
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(statInfo.atime, "statInfo.atime");
assertIsDate(statInfo.mtime, "statInfo.mtime");
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
}
}
Expand All @@ -138,8 +143,8 @@
}
if (options.preserveTimestamps) {
const statInfo = await Deno.lstat(src);
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(statInfo.atime, "statInfo.atime");
assertIsDate(statInfo.mtime, "statInfo.mtime");

Check warning on line 147 in fs/copy.ts

View check run for this annotation

Codecov / codecov/patch

fs/copy.ts#L146-L147

Added lines #L146 - L147 were not covered by tests
await Deno.utime(dest, statInfo.atime, statInfo.mtime);
}
}
Expand All @@ -163,8 +168,8 @@

if (options.preserveTimestamps) {
const statInfo = Deno.lstatSync(src);
assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(statInfo.atime, "statInfo.atime");
assertIsDate(statInfo.mtime, "statInfo.mtime");

Check warning on line 172 in fs/copy.ts

View check run for this annotation

Codecov / codecov/patch

fs/copy.ts#L171-L172

Added lines #L171 - L172 were not covered by tests
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
}
}
Expand All @@ -186,8 +191,8 @@

if (options.preserveTimestamps) {
const srcStatInfo = await Deno.stat(src);
assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(srcStatInfo.atime, "statInfo.atime");
assertIsDate(srcStatInfo.mtime, "statInfo.mtime");

Check warning on line 195 in fs/copy.ts

View check run for this annotation

Codecov / codecov/patch

fs/copy.ts#L194-L195

Added lines #L194 - L195 were not covered by tests
await Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime);
}

Expand Down Expand Up @@ -228,8 +233,8 @@

if (options.preserveTimestamps) {
const srcStatInfo = Deno.statSync(src);
assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`);
assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`);
assertIsDate(srcStatInfo.atime, "statInfo.atime");
assertIsDate(srcStatInfo.mtime, "statInfo.mtime");

Check warning on line 237 in fs/copy.ts

View check run for this annotation

Codecov / codecov/patch

fs/copy.ts#L236-L237

Added lines #L236 - L237 were not covered by tests
Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime);
}

Expand Down
9 changes: 6 additions & 3 deletions fs/expand_glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { resolve } from "@std/path/resolve";
import { SEPARATOR_PATTERN } from "@std/path/constants";
import { walk, walkSync } from "./walk.ts";
import { assert } from "@std/assert/assert";
import { toPathString } from "./_to_path_string.ts";
import {
createWalkEntry,
Expand Down Expand Up @@ -158,7 +157,9 @@
: absRoot;
while (segments.length > 0 && !isGlob(segments[0]!)) {
const seg = segments.shift();
assert(seg !== undefined);
if (seg === undefined) {
throw new ReferenceError("Unexpected undefined segment");
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 162 in fs/expand_glob.ts

View check run for this annotation

Codecov / codecov/patch

fs/expand_glob.ts#L161-L162

Added lines #L161 - L162 were not covered by tests
fixedRoot = joinGlobs([fixedRoot, seg], globOptions);
}

Expand Down Expand Up @@ -316,7 +317,9 @@
: absRoot;
while (segments.length > 0 && !isGlob(segments[0]!)) {
const seg = segments.shift();
assert(seg !== undefined);
if (seg === undefined) {
throw new ReferenceError("Unexpected undefined segment");
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 322 in fs/expand_glob.ts

View check run for this annotation

Codecov / codecov/patch

fs/expand_glob.ts#L321-L322

Added lines #L321 - L322 were not covered by tests
fixedRoot = joinGlobs([fixedRoot, seg], globOptions);
}

Expand Down