Skip to content

Commit

Permalink
refactor: cleanup usage of double equals (denoland#3566)
Browse files Browse the repository at this point in the history
Co-authored-by: Yoshiya Hinosawa <[email protected]>
  • Loading branch information
lino-levan and kt3k committed Aug 25, 2023
1 parent c96fff7 commit 2b5d712
Show file tree
Hide file tree
Showing 60 changed files with 182 additions and 190 deletions.
2 changes: 1 addition & 1 deletion _tools/release/02_create_pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getPrBody() {
"```\n";

const actor = Deno.env.get("GH_WORKFLOW_ACTOR");
if (actor != null) {
if (actor !== undefined) {
text += `\ncc @${actor}`;
}

Expand Down
2 changes: 1 addition & 1 deletion _tools/release/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class VersionFile {

get version() {
const version = VersionFile.#versionRe.exec(this.#fileText);
if (version == null) {
if (version === null) {
throw new Error(`Could not find version in text: ${this.#fileText}`);
} else {
return semver.parse(version[1])!;
Expand Down
8 changes: 4 additions & 4 deletions archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class Tar {
if (i < 0 || fileName.length > 100) {
throw new Error(errMsg);
} else {
assert(fileNamePrefix != null);
assert(fileNamePrefix !== undefined);
if (fileNamePrefix.length > 155) {
throw new Error(errMsg);
}
Expand Down Expand Up @@ -226,7 +226,7 @@ export class Tar {
}

const fileSize = info?.size ?? opts.contentSize;
assert(fileSize != null, "fileSize must be set");
assert(fileSize !== undefined, "fileSize must be set");

const type = opts.type
? FileTypes[opts.type as keyof typeof FileTypes]
Expand Down Expand Up @@ -274,13 +274,13 @@ export class Tar {
const headerArr = formatHeader(tarData);
readers.push(new Buffer(headerArr));
if (!reader) {
assert(filePath != null);
assert(filePath !== undefined);
reader = new FileReader(filePath);
}
readers.push(reader);

// to the nearest multiple of recordSize
assert(tarData.fileSize != null, "fileSize must be set");
assert(tarData.fileSize !== undefined, "fileSize must be set");
readers.push(
new Buffer(
clean(
Expand Down
4 changes: 2 additions & 2 deletions assert/assert_instance_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export function assertInstanceOf<T extends AnyConstructor>(
actualTypeStr = typeof actual;
}

if (expectedTypeStr == actualTypeStr) {
if (expectedTypeStr === actualTypeStr) {
msg =
`Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`;
} else if (actualTypeStr == "function") {
} else if (actualTypeStr === "function") {
msg =
`Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`;
} else {
Expand Down
4 changes: 2 additions & 2 deletions async/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function pooledMap<T, R>(
} catch (e) {
if (
e instanceof AggregateError &&
e.message == ERROR_WHILE_MAPPING_MESSAGE
e.message === ERROR_WHILE_MAPPING_MESSAGE
) {
controller.error(e as unknown);
}
Expand Down Expand Up @@ -83,7 +83,7 @@ export function pooledMap<T, R>(
} catch {
const errors = [];
for (const result of await Promise.allSettled(executing)) {
if (result.status == "rejected") {
if (result.status === "rejected") {
errors.push(result.reason);
}
}
Expand Down
2 changes: 1 addition & 1 deletion collections/drop_last_while.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* const numbers = [22, 30, 44];
*
* const notFortyFour = dropLastWhile(numbers, (i) => i != 44);
* const notFortyFour = dropLastWhile(numbers, (i) => i !== 44);
*
* assertEquals(
* notFortyFour,
Expand Down
2 changes: 1 addition & 1 deletion collections/max_with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* The comparator is expected to work exactly like one passed to `Array.sort`,
* which means that `comparator(a, b)` should return a negative number if `a < b`,
* a positive number if `a > b` and `0` if `a == b`.
* a positive number if `a > b` and `0` if `a === b`.
*
* @example
* ```ts
Expand Down
2 changes: 1 addition & 1 deletion collections/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts";
*
* const numbers = [5, 6, 7, 8, 9];
* const [even, odd] = partition(numbers, (it) => it % 2 == 0);
* const [even, odd] = partition(numbers, (it) => it % 2 === 0);
*
* assertEquals(even, [6, 8]);
* assertEquals(odd, [5, 7, 9]);
Expand Down
2 changes: 1 addition & 1 deletion collections/take_while_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Deno.test("[collections/takeWhile] Returns empty array when the first element do
Deno.test("[collections/takeWhile] Returns the same array when all elements match the predicate", () => {
const arr = [1, 2, 3, 4];

const actual = takeWhile(arr, (i) => i != 400);
const actual = takeWhile(arr, (i) => i !== 400);

assertEquals(actual, [1, 2, 3, 4]);
});
2 changes: 1 addition & 1 deletion console/_tools/generate_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Table {

this.entries = this.entries.map((i) => {
const width = this.indexed[i].width();
if (width == null) throw new TypeError("width cannot be null");
if (width === null) throw new TypeError("width cannot be null");
return width;
});

Expand Down
4 changes: 2 additions & 2 deletions csv/_io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ReadOptions {
* Enabling checking number of expected fields for each row.
*
* If positive, each record is required to have the given number of fields.
* If == 0, it will be set to the number of fields in the first row, so that
* If === 0, it will be set to the number of fields in the first row, so that
* future rows must have the same field count.
* If negative, no check is made and records may have a variable number of
* fields.
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function parseRecord(
return [];
}

assert(opt.separator != null);
assert(opt.separator !== undefined);

let fullLine = line;
let quoteError: ParseError | null = null;
Expand Down
4 changes: 1 addition & 3 deletions csv/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class Parser {
return [];
}

assert(this.#options.separator != null);

let fullLine = line;
let quoteError: ParseError | null = null;
const quote = '"';
Expand Down Expand Up @@ -342,7 +340,7 @@ export function parse<const T extends ParseOptions>(

if (opt.skipFirstRow) {
const head = r.shift();
assert(head != null);
assert(head !== undefined);
headers = head;
}

Expand Down
6 changes: 2 additions & 4 deletions datetime/day_of_year.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export function dayOfYear(date: Date): number {
const yearStart = new Date(date);

yearStart.setFullYear(date.getFullYear(), 0, 0);
const diff = date.getTime() -
yearStart.getTime();
const diff = date.getTime() - yearStart.getTime();

return Math.floor(diff / DAY);
}
Expand All @@ -47,8 +46,7 @@ export function dayOfYearUtc(date: Date): number {
const yearStart = new Date(date);

yearStart.setUTCFullYear(date.getUTCFullYear(), 0, 0);
const diff = date.getTime() -
yearStart.getTime();
const diff = date.getTime() - yearStart.getTime();

return Math.floor(diff / DAY);
}
2 changes: 1 addition & 1 deletion dotenv/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function parse(
let match;
const keysForExpandCheck = [];

while ((match = RE_KeyValue.exec(rawDotenv)) != null) {
while ((match = RE_KeyValue.exec(rawDotenv)) !== null) {
const { key, interpolated, notInterpolated, unquoted } = match
?.groups as LineParseResult;

Expand Down
2 changes: 1 addition & 1 deletion encoding/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function decode(src: Uint8Array): Uint8Array {
dst[i] = (a << 4) | b;
}

if (src.length % 2 == 1) {
if (src.length % 2 === 1) {
// Check for invalid char before reporting bad length,
// since the invalid char (if present) is an earlier problem.
fromHexChar(src[dst.length * 2]);
Expand Down
8 changes: 4 additions & 4 deletions flags/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ function get<TValue>(

function getForce<TValue>(obj: Record<string, TValue>, key: string): TValue {
const v = get(obj, key);
assert(v != null);
assert(v !== undefined);
return v;
}

Expand Down Expand Up @@ -638,7 +638,7 @@ export function parse<

if (/^--.+=/.test(arg)) {
const m = arg.match(/^--([^=]+)=(.*)$/s);
assert(m != null);
assert(m !== null);
const [, key, value] = m;

if (flags.bools[key]) {
Expand All @@ -651,11 +651,11 @@ export function parse<
/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))
) {
const m = arg.match(/^--no-(.+)/);
assert(m != null);
assert(m !== null);
setArg(m[1], false, arg, false);
} else if (/^--.+/.test(arg)) {
const m = arg.match(/^--(.+)/);
assert(m != null);
assert(m !== null);
const [, key] = m;
const next = args[i + 1];
if (
Expand Down
4 changes: 2 additions & 2 deletions fmt/printf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class Printf {
this.state = State.PERCENT;
return;
}
flags.width = flags.width == -1 ? 0 : flags.width;
flags.width = flags.width === -1 ? 0 : flags.width;
flags.width *= 10;
flags.width += val;
}
Expand Down Expand Up @@ -710,7 +710,7 @@ class Printf {
esign = r < 0 ? "-" : "+";
}
}
e = e.length == 1 ? "0" + e : e;
e = e.length === 1 ? "0" + e : e;
const val = `${mantissa}.${fractional}${upcase ? "E" : "e"}${esign}${e}`;
return this.padNum(val, n < 0);
}
Expand Down
1 change: 0 additions & 1 deletion fs/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ function copyDirSync(
dest = toPathString(dest);

for (const entry of Deno.readDirSync(src)) {
assert(entry.name != null, "file.name must be set");
const srcPath = join(src, entry.name);
const destPath = join(dest, basename(srcPath as string));
if (entry.isSymlink) {
Expand Down
4 changes: 2 additions & 2 deletions fs/ensure_symlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { getFileInfoType, toPathString } from "./_util.ts";
import { isWindows } from "../_util/os.ts";

function resolveSymlinkTarget(target: string | URL, linkName: string | URL) {
if (typeof target != "string") return target; // URL is always absolute path
if (typeof linkName == "string") {
if (typeof target !== "string") return target; // URL is always absolute path
if (typeof linkName === "string") {
return resolve(dirname(linkName), target);
} else {
return new URL(target, linkName);
Expand Down
24 changes: 12 additions & 12 deletions fs/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ export async function exists(
return false;
}
if (options.isReadable) {
if (stat.mode == null) {
if (stat.mode === null) {
return true; // Exclusive on Non-POSIX systems
}
if (Deno.uid() == stat.uid) {
return (stat.mode & 0o400) == 0o400; // User is owner and can read?
} else if (Deno.gid() == stat.gid) {
return (stat.mode & 0o040) == 0o040; // User group is owner and can read?
if (Deno.uid() === stat.uid) {
return (stat.mode & 0o400) === 0o400; // User is owner and can read?
} else if (Deno.gid() === stat.gid) {
return (stat.mode & 0o040) === 0o040; // User group is owner and can read?
}
return (stat.mode & 0o004) == 0o004; // Others can read?
return (stat.mode & 0o004) === 0o004; // Others can read?
}
}
return true;
Expand Down Expand Up @@ -173,15 +173,15 @@ export function existsSync(
return false;
}
if (options.isReadable) {
if (stat.mode == null) {
if (stat.mode === null) {
return true; // Exclusive on Non-POSIX systems
}
if (Deno.uid() == stat.uid) {
return (stat.mode & 0o400) == 0o400; // User is owner and can read?
} else if (Deno.gid() == stat.gid) {
return (stat.mode & 0o040) == 0o040; // User group is owner and can read?
if (Deno.uid() === stat.uid) {
return (stat.mode & 0o400) === 0o400; // User is owner and can read?
} else if (Deno.gid() === stat.gid) {
return (stat.mode & 0o040) === 0o040; // User group is owner and can read?
}
return (stat.mode & 0o004) == 0o004; // Others can read?
return (stat.mode & 0o004) === 0o004; // Others can read?
}
}
return true;
Expand Down
20 changes: 10 additions & 10 deletions fs/expand_glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ export async function* expandGlob(
} = split(toPathString(glob));

let fixedRoot = isGlobAbsolute
? winRoot != undefined ? winRoot : "/"
? winRoot !== undefined ? winRoot : "/"
: absRoot;
while (segments.length > 0 && !isGlob(segments[0])) {
const seg = segments.shift();
assert(seg != null);
assert(seg !== undefined);
fixedRoot = joinGlobs([fixedRoot, seg], globOptions);
}

Expand All @@ -118,7 +118,7 @@ export async function* expandGlob(
): AsyncIterableIterator<WalkEntry> {
if (!walkInfo.isDirectory) {
return;
} else if (globSegment == "..") {
} else if (globSegment === "..") {
const parentPath = joinGlobs([walkInfo.path, ".."], globOptions);
try {
if (shouldInclude(parentPath)) {
Expand All @@ -128,7 +128,7 @@ export async function* expandGlob(
throwUnlessNotFound(error);
}
return;
} else if (globSegment == "**") {
} else if (globSegment === "**") {
return yield* walk(walkInfo.path, {
skip: excludePatterns,
maxDepth: globstar ? Infinity : 1,
Expand All @@ -144,7 +144,7 @@ export async function* expandGlob(
})
) {
if (
walkEntry.path != walkInfo.path &&
walkEntry.path !== walkInfo.path &&
walkEntry.name.match(globPattern)
) {
yield walkEntry;
Expand Down Expand Up @@ -219,11 +219,11 @@ export function* expandGlobSync(
} = split(toPathString(glob));

let fixedRoot = isGlobAbsolute
? winRoot != undefined ? winRoot : "/"
? winRoot !== undefined ? winRoot : "/"
: absRoot;
while (segments.length > 0 && !isGlob(segments[0])) {
const seg = segments.shift();
assert(seg != null);
assert(seg !== undefined);
fixedRoot = joinGlobs([fixedRoot, seg], globOptions);
}

Expand All @@ -240,7 +240,7 @@ export function* expandGlobSync(
): IterableIterator<WalkEntry> {
if (!walkInfo.isDirectory) {
return;
} else if (globSegment == "..") {
} else if (globSegment === "..") {
const parentPath = joinGlobs([walkInfo.path, ".."], globOptions);
try {
if (shouldInclude(parentPath)) {
Expand All @@ -250,7 +250,7 @@ export function* expandGlobSync(
throwUnlessNotFound(error);
}
return;
} else if (globSegment == "**") {
} else if (globSegment === "**") {
return yield* walkSync(walkInfo.path, {
skip: excludePatterns,
maxDepth: globstar ? Infinity : 1,
Expand All @@ -266,7 +266,7 @@ export function* expandGlobSync(
})
) {
if (
walkEntry.path != walkInfo.path &&
walkEntry.path !== walkInfo.path &&
walkEntry.name.match(globPattern)
) {
yield walkEntry;
Expand Down
Loading

0 comments on commit 2b5d712

Please sign in to comment.