Skip to content

Commit

Permalink
chore: update dlint to v0.37.0 for GitHub Actions (#17295)
Browse files Browse the repository at this point in the history
Updated third_party dlint to v0.37.0 for GitHub Actions. This PR
includes following changes:
 
* fix(prefer-primordials): Stop using array pattern assignments
* fix(prefer-primordials): Stop using global intrinsics except for
`SharedArrayBuffer`
* feat(guard-for-in): Apply new guard-for-in rule
  • Loading branch information
petamoriken authored Jan 16, 2023
1 parent 40134ff commit 6da958d
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .dlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"tags": ["recommended"],
"include": [
"ban-untagged-todo",
"camelcase"
"camelcase",
"guard-for-in"
],
"exclude": [
"no-invalid-triple-slash-reference"
Expand Down
4 changes: 4 additions & 0 deletions cli/js/40_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MapPrototypeSet,
MathCeil,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ObjectPrototypeIsPrototypeOf,
Promise,
SafeArrayIterator,
Expand Down Expand Up @@ -167,6 +168,9 @@

const details = [];
for (const key in post.ops) {
if (!ObjectPrototypeHasOwnProperty(post.ops, key)) {
continue;
}
const preOp = pre.ops[key] ??
{ opsDispatchedAsync: 0, opsCompletedAsync: 0 };
const postOp = post.ops[key];
Expand Down
36 changes: 18 additions & 18 deletions cli/tests/unit/headers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,52 @@ const headerDict: Record<string, string> = {
};
// deno-lint-ignore no-explicit-any
const headerSeq: any[] = [];
for (const name in headerDict) {
headerSeq.push([name, headerDict[name]]);
for (const [name, value] of Object.entries(headerDict)) {
headerSeq.push([name, value]);
}

Deno.test(function newHeaderWithSequence() {
const headers = new Headers(headerSeq);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
assertEquals(headers.get(name), String(value));
}
assertEquals(headers.get("length"), null);
});

Deno.test(function newHeaderWithRecord() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
assertEquals(headers.get(name), String(value));
}
});

Deno.test(function newHeaderWithHeadersInstance() {
const headers = new Headers(headerDict);
const headers2 = new Headers(headers);
for (const name in headerDict) {
assertEquals(headers2.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
assertEquals(headers2.get(name), String(value));
}
});

Deno.test(function headerAppendSuccess() {
const headers = new Headers();
for (const name in headerDict) {
headers.append(name, headerDict[name]);
assertEquals(headers.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
headers.append(name, value);
assertEquals(headers.get(name), String(value));
}
});

Deno.test(function headerSetSuccess() {
const headers = new Headers();
for (const name in headerDict) {
headers.set(name, headerDict[name]);
assertEquals(headers.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
headers.set(name, value);
assertEquals(headers.get(name), String(value));
}
});

Deno.test(function headerHasSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
for (const name of Object.keys(headerDict)) {
assert(headers.has(name), "headers has name " + name);
assert(
!headers.has("nameNotInHeaders"),
Expand All @@ -90,7 +90,7 @@ Deno.test(function headerHasSuccess() {

Deno.test(function headerDeleteSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
for (const name of Object.keys(headerDict)) {
assert(headers.has(name), "headers have a header: " + name);
headers.delete(name);
assert(!headers.has(name), "headers do not have anymore a header: " + name);
Expand All @@ -99,8 +99,8 @@ Deno.test(function headerDeleteSuccess() {

Deno.test(function headerGetSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
for (const [name, value] of Object.entries(headerDict)) {
assertEquals(headers.get(name), String(value));
assertEquals(headers.get("nameNotInHeaders"), null);
}
});
Expand Down
2 changes: 1 addition & 1 deletion ext/broadcast_channel/01_broadcast_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
break;
}

const [name, data] = message;
const { 0: name, 1: data } = message;
dispatch(null, name, new Uint8Array(data));
}

Expand Down
2 changes: 1 addition & 1 deletion ext/cache/01_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
},
);
if (matchResult) {
const [meta, responseBodyRid] = matchResult;
const { 0: meta, 1: responseBodyRid } = matchResult;
let body = null;
if (responseBodyRid !== null) {
body = readableStreamForRid(responseBodyRid);
Expand Down
36 changes: 18 additions & 18 deletions ext/console/02_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
ObjectKeys(value).length > 0 ||
ObjectGetOwnPropertySymbols(value).length > 0
) {
const [propString, refIndex] = inspectRawObject(
const { 0: propString, 1: refIndex } = inspectRawObject(
value,
inspectOptions,
);
Expand Down Expand Up @@ -847,7 +847,7 @@
displayName: "",
delims: ["[", "]"],
entryHandler: (entry, inspectOptions) => {
const [index, val] = entry;
const { 0: index, 1: val } = entry;
let i = index;
lastValidIndex = index;
if (!ObjectPrototypeHasOwnProperty(value, i)) {
Expand Down Expand Up @@ -940,7 +940,7 @@
displayName: "Map",
delims: ["{", "}"],
entryHandler: (entry, inspectOptions) => {
const [key, val] = entry;
const { 0: key, 1: val } = entry;
inspectOptions.indentLevel++;
const inspectedValue = `${
inspectValueWithQuotes(key, inspectOptions)
Expand Down Expand Up @@ -1100,7 +1100,7 @@
const cyan = maybeColor(colors.cyan, inspectOptions);
const red = maybeColor(colors.red, inspectOptions);

const [state, result] = core.getPromiseDetails(value);
const { 0: state, 1: result } = core.getPromiseDetails(value);

if (state === PromiseState.Pending) {
return `Promise { ${cyan("<pending>")} }`;
Expand Down Expand Up @@ -1363,7 +1363,7 @@
);
} else {
// Otherwise, default object formatting
let [insp, refIndex] = inspectRawObject(value, inspectOptions);
let { 0: insp, 1: refIndex } = inspectRawObject(value, inspectOptions);
insp = refIndex + insp;
return insp;
}
Expand Down Expand Up @@ -1568,17 +1568,17 @@
let g_;
let b_;
if (h < 60) {
[r_, g_, b_] = [c, x, 0];
({ 0: r_, 1: g_, 2: b_ } = [c, x, 0]);
} else if (h < 120) {
[r_, g_, b_] = [x, c, 0];
({ 0: r_, 1: g_, 2: b_ } = [x, c, 0]);
} else if (h < 180) {
[r_, g_, b_] = [0, c, x];
({ 0: r_, 1: g_, 2: b_ } = [0, c, x]);
} else if (h < 240) {
[r_, g_, b_] = [0, x, c];
({ 0: r_, 1: g_, 2: b_ } = [0, x, c]);
} else if (h < 300) {
[r_, g_, b_] = [x, 0, c];
({ 0: r_, 1: g_, 2: b_ } = [x, 0, c]);
} else {
[r_, g_, b_] = [c, 0, x];
({ 0: r_, 1: g_, 2: b_ } = [c, 0, x]);
}
return [
MathRound((r_ + m) * 255),
Expand Down Expand Up @@ -1645,7 +1645,7 @@
}

for (let i = 0; i < rawEntries.length; ++i) {
const [key, value] = rawEntries[i];
const { 0: key, 1: value } = rawEntries[i];
if (key == "background-color") {
if (value != null) {
css.backgroundColor = value;
Expand Down Expand Up @@ -1736,12 +1736,12 @@
ansi += `\x1b[47m`;
} else {
if (ArrayIsArray(css.backgroundColor)) {
const [r, g, b] = css.backgroundColor;
const { 0: r, 1: g, 2: b } = css.backgroundColor;
ansi += `\x1b[48;2;${r};${g};${b}m`;
} else {
const parsed = parseCssColor(css.backgroundColor);
if (parsed !== null) {
const [r, g, b] = parsed;
const { 0: r, 1: g, 2: b } = parsed;
ansi += `\x1b[48;2;${r};${g};${b}m`;
} else {
ansi += "\x1b[49m";
Expand Down Expand Up @@ -1770,12 +1770,12 @@
ansi += `\x1b[37m`;
} else {
if (ArrayIsArray(css.color)) {
const [r, g, b] = css.color;
const { 0: r, 1: g, 2: b } = css.color;
ansi += `\x1b[38;2;${r};${g};${b}m`;
} else {
const parsed = parseCssColor(css.color);
if (parsed !== null) {
const [r, g, b] = parsed;
const { 0: r, 1: g, 2: b } = parsed;
ansi += `\x1b[38;2;${r};${g};${b}m`;
} else {
ansi += "\x1b[39m";
Expand All @@ -1799,7 +1799,7 @@
}
if (!colorEquals(css.textDecorationColor, prevCss.textDecorationColor)) {
if (css.textDecorationColor != null) {
const [r, g, b] = css.textDecorationColor;
const { 0: r, 1: g, 2: b } = css.textDecorationColor;
ansi += `\x1b[58;2;${r};${g};${b}m`;
} else {
ansi += "\x1b[59m";
Expand Down Expand Up @@ -2045,7 +2045,7 @@
return;
}

const [first, ...rest] = args;
const [first, ...rest] = new SafeArrayIterator(args);

if (typeof first === "string") {
this.error(
Expand Down
2 changes: 1 addition & 1 deletion ext/fetch/21_formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="`;

// deno-lint-ignore prefer-primordials
for (const [name, value] of formData) {
for (const { 0: name, 1: value } of formData) {
if (typeof value === "string") {
ArrayPrototypePush(
chunks,
Expand Down
5 changes: 4 additions & 1 deletion ext/fetch/22_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
JSONParse,
ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf,
// TODO(lucacasonato): add SharedArrayBuffer to primordials
// SharedArrayBufferPrototype
TypedArrayPrototypeSlice,
TypeError,
Uint8Array,
Expand Down Expand Up @@ -185,7 +187,7 @@
* @returns {InnerBody}
*/
clone() {
const [out1, out2] = this.stream.tee();
const { 0: out1, 1: out2 } = this.stream.tee();
this.streamOrStatic = out1;
const second = new InnerBody(out2);
second.source = core.deserialize(core.serialize(this.source));
Expand Down Expand Up @@ -447,6 +449,7 @@
if (typeof V === "object") {
if (
ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) ||
// deno-lint-ignore prefer-primordials
ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V)
) {
return webidl.converters["ArrayBuffer"](V, opts);
Expand Down
9 changes: 6 additions & 3 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@
let size = 0;
let alignment = 1;
for (const field of new SafeArrayIterator(type.struct)) {
const [fieldSize, fieldAlign] = getTypeSizeAndAlignment(field, cache);
const { 0: fieldSize, 1: fieldAlign } = getTypeSizeAndAlignment(
field,
cache,
);
alignment = MathMax(alignment, fieldAlign);
size = MathCeil(size / fieldAlign) * fieldAlign;
size += fieldSize;
Expand Down Expand Up @@ -319,7 +322,7 @@
"Invalid UnsafeCallback, cannot be nonblocking",
);
}
const [rid, pointer] = ops.op_ffi_unsafe_callback_create(
const { 0: rid, 1: pointer } = ops.op_ffi_unsafe_callback_create(
definition,
callback,
);
Expand Down Expand Up @@ -362,7 +365,7 @@
symbols = {};

constructor(path, symbols) {
[this.#rid, this.symbols] = ops.op_ffi_load({ path, symbols });
({ 0: this.#rid, 1: this.symbols } = ops.op_ffi_load({ path, symbols }));
for (const symbol in symbols) {
if (!ObjectPrototypeHasOwnProperty(symbols, symbol)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion ext/flash/01_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
// Date header: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2
let str = `HTTP/1.1 ${status} ${statusCodes[status]}\r\nDate: ${date}\r\n`;
for (let i = 0; i < headerList.length; ++i) {
const [name, value] = headerList[i];
const { 0: name, 1: value } = headerList[i];
// header-field = field-name ":" OWS field-value OWS
str += `${name}: ${value}\r\n`;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/http/01_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
return null;
}

const [streamRid, method, url] = nextRequest;
const { 0: streamRid, 1: method, 2: url } = nextRequest;
SetPrototypeAdd(this.managedResources, streamRid);

/** @type {ReadableStream<Uint8Array> | undefined} */
Expand Down
Loading

0 comments on commit 6da958d

Please sign in to comment.