Continue linting fixes [#287] (#332)

* make use of ===, if branches, let/const, string templates, var names consistent style.
This commit is contained in:
Brandon Liu
2024-01-29 17:41:12 +08:00
committed by GitHub
parent 3b61cc8b49
commit a6cbc1961e
6 changed files with 181 additions and 195 deletions

View File

@@ -14,22 +14,22 @@ import {
test("stub data", () => {
const dataview = new DataView(
createDirectory([
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, is_dir: false },
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, isDir: false },
{
z: 14,
x: 16383,
y: 16383,
offset: 999999,
length: 999,
is_dir: false,
isDir: false,
},
])
);
var zRaw = dataview.getUint8(17 + 0);
var x = getUint24(dataview, 17 + 1);
var y = getUint24(dataview, 17 + 4);
var offset = getUint48(dataview, 17 + 7);
var length = dataview.getUint32(17 + 13, true);
const zRaw = dataview.getUint8(17 + 0);
const x = getUint24(dataview, 17 + 1);
const y = getUint24(dataview, 17 + 4);
const offset = getUint48(dataview, 17 + 7);
const length = dataview.getUint32(17 + 13, true);
assert.strictEqual(zRaw, 14);
assert.strictEqual(x, 16383);
assert.strictEqual(y, 16383);
@@ -38,24 +38,24 @@ test("stub data", () => {
test("get entry", () => {
const view = new DataView(
createDirectory([
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, is_dir: false },
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, isDir: false },
{
z: 14,
x: 16383,
y: 16383,
offset: 999999,
length: 999,
is_dir: false,
isDir: false,
},
])
);
const entry = queryTile(view, 14, 16383, 16383);
assert.strictEqual(entry!.z, 14);
assert.strictEqual(entry!.x, 16383);
assert.strictEqual(entry!.y, 16383);
assert.strictEqual(entry!.offset, 999999);
assert.strictEqual(entry!.length, 999);
assert.strictEqual(entry!.is_dir, false);
assert.strictEqual(entry?.z, 14);
assert.strictEqual(entry?.x, 16383);
assert.strictEqual(entry?.y, 16383);
assert.strictEqual(entry?.offset, 999999);
assert.strictEqual(entry?.length, 999);
assert.strictEqual(entry?.isDir, false);
assert.strictEqual(queryLeafdir(view, 14, 16383, 16383), null);
});
@@ -68,17 +68,17 @@ test("get leafdir", () => {
y: 16383,
offset: 999999,
length: 999,
is_dir: true,
isDir: true,
},
])
);
const entry = queryLeafdir(view, 14, 16383, 16383);
assert.strictEqual(entry!.z, 14);
assert.strictEqual(entry!.x, 16383);
assert.strictEqual(entry!.y, 16383);
assert.strictEqual(entry!.offset, 999999);
assert.strictEqual(entry!.length, 999);
assert.strictEqual(entry!.is_dir, true);
assert.strictEqual(entry?.z, 14);
assert.strictEqual(entry?.x, 16383);
assert.strictEqual(entry?.y, 16383);
assert.strictEqual(entry?.offset, 999999);
assert.strictEqual(entry?.length, 999);
assert.strictEqual(entry?.isDir, true);
assert.strictEqual(queryTile(view, 14, 16383, 16383), null);
});
@@ -91,14 +91,14 @@ test("derive the leaf level", () => {
y: 3,
offset: 0,
length: 0,
is_dir: true,
isDir: true,
},
])
);
let leaf = deriveLeaf(view, { z: 7, x: 6, y: 6 });
assert.strictEqual(leaf!.z, 6);
assert.strictEqual(leaf!.x, 3);
assert.strictEqual(leaf!.y, 3);
assert.strictEqual(leaf?.z, 6);
assert.strictEqual(leaf?.x, 3);
assert.strictEqual(leaf?.y, 3);
view = new DataView(
createDirectory([
{
@@ -107,7 +107,7 @@ test("derive the leaf level", () => {
y: 3,
offset: 0,
length: 0,
is_dir: false,
isDir: false,
},
])
);
@@ -124,7 +124,7 @@ test("convert spec v1 directory to spec v2 directory", () => {
y: 3,
offset: 3,
length: 3,
is_dir: true,
isDir: true,
},
{
z: 6,
@@ -132,7 +132,7 @@ test("convert spec v1 directory to spec v2 directory", () => {
y: 2,
offset: 2,
length: 2,
is_dir: false,
isDir: false,
},
{
z: 6,
@@ -140,21 +140,21 @@ test("convert spec v1 directory to spec v2 directory", () => {
y: 1,
offset: 1,
length: 1,
is_dir: false,
isDir: false,
},
])
);
let entry = queryLeafdir(view, 7, 3, 3);
assert.strictEqual(entry!.offset, 3);
assert.strictEqual(entry?.offset, 3);
entry = queryTile(view, 6, 2, 2);
assert.strictEqual(entry!.offset, 2);
assert.strictEqual(entry?.offset, 2);
entry = queryTile(view, 6, 2, 1);
assert.strictEqual(entry!.offset, 1);
assert.strictEqual(entry?.offset, 1);
entry = parseEntry(view, 0);
assert.strictEqual(entry!.offset, 1);
assert.strictEqual(entry?.offset, 1);
entry = parseEntry(view, 1);
assert.strictEqual(entry!.offset, 2);
assert.strictEqual(entry?.offset, 2);
entry = parseEntry(view, 2);
assert.strictEqual(entry!.offset, 3);
assert.strictEqual(entry?.offset, 3);
});

View File

@@ -64,8 +64,8 @@ test("a lot of tiles", () => {
});
test("tile extremes", () => {
for (var z = 0; z < 27; z++) {
const dim = Math.pow(2, z) - 1;
for (let z = 0; z < 27; z++) {
const dim = 2 ** z - 1;
const tl = tileIdToZxy(zxyToTileId(z, 0, 0));
assert.deepEqual([z, 0, 0], tl);
const tr = tileIdToZxy(zxyToTileId(z, dim, 0));
@@ -100,9 +100,9 @@ test("tile search for first entry == id", () => {
const entries: Entry[] = [
{ tileId: 100, offset: 1, length: 1, runLength: 1 },
];
const entry = findTile(entries, 100)!;
assert.strictEqual(entry.offset, 1);
assert.strictEqual(entry.length, 1);
const entry = findTile(entries, 100);
assert.strictEqual(entry?.offset, 1);
assert.strictEqual(entry?.length, 1);
assert.strictEqual(findTile(entries, 101), null);
});
@@ -111,32 +111,32 @@ test("tile search with runlength", () => {
{ tileId: 3, offset: 3, length: 1, runLength: 2 },
{ tileId: 5, offset: 5, length: 1, runLength: 2 },
];
const entry = findTile(entries, 4)!;
assert.strictEqual(entry.offset, 3);
const entry = findTile(entries, 4);
assert.strictEqual(entry?.offset, 3);
});
test("tile search with multiple tile entries", () => {
let entries: Entry[] = [{ tileId: 100, offset: 1, length: 1, runLength: 2 }];
let entry = findTile(entries, 101)!;
assert.strictEqual(entry.offset, 1);
assert.strictEqual(entry.length, 1);
let entry = findTile(entries, 101);
assert.strictEqual(entry?.offset, 1);
assert.strictEqual(entry?.length, 1);
entries = [
{ tileId: 100, offset: 1, length: 1, runLength: 1 },
{ tileId: 150, offset: 2, length: 2, runLength: 2 },
];
entry = findTile(entries, 151)!;
assert.strictEqual(entry.offset, 2);
assert.strictEqual(entry.length, 2);
entry = findTile(entries, 151);
assert.strictEqual(entry?.offset, 2);
assert.strictEqual(entry?.length, 2);
entries = [
{ tileId: 50, offset: 1, length: 1, runLength: 2 },
{ tileId: 100, offset: 2, length: 2, runLength: 1 },
{ tileId: 150, offset: 3, length: 3, runLength: 1 },
];
entry = findTile(entries, 51)!;
assert.strictEqual(entry.offset, 1);
assert.strictEqual(entry.length, 1);
entry = findTile(entries, 51);
assert.strictEqual(entry?.offset, 1);
assert.strictEqual(entry?.length, 1);
});
test("leaf search", () => {
@@ -144,8 +144,8 @@ test("leaf search", () => {
{ tileId: 100, offset: 1, length: 1, runLength: 0 },
];
const entry = findTile(entries, 150);
assert.strictEqual(entry!.offset, 1);
assert.strictEqual(entry!.length, 1);
assert.strictEqual(entry?.offset, 1);
assert.strictEqual(entry?.length, 1);
});
// inefficient method only for testing