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

[WIP] Use dprint for internal js/ts formating #4507

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions cli/js/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ListenerImpl implements Listener {
async *[Symbol.asyncIterator](): AsyncIterator<Conn> {
while (true) {
try {
yield await this.accept();
yield (await this.accept());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed in swc so is not necessary anymore.

} catch (error) {
if (error instanceof errors.BadResource) {
break;
Expand Down Expand Up @@ -115,7 +115,7 @@ export class DatagramImpl implements DatagramConn {
async *[Symbol.asyncIterator](): AsyncIterator<[Uint8Array, Addr]> {
while (true) {
try {
yield await this.receive();
yield (await this.receive());
} catch (error) {
if (error instanceof errors.BadResource) {
break;
Expand Down
12 changes: 6 additions & 6 deletions cli/js/tests/text_encoding_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ unitTest(function btoaFailed(): void {
});

unitTest(function textDecoder2(): void {
// prettier-ignore
// dprint-ignore
const fixture = new Uint8Array([
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
Expand All @@ -75,7 +75,7 @@ unitTest(function textDecoder2(): void {
});

unitTest(function textDecoderIgnoreBOM(): void {
// prettier-ignore
// dprint-ignore
const fixture = new Uint8Array([
0xef, 0xbb, 0xbf,
0xf0, 0x9d, 0x93, 0xbd,
Expand All @@ -88,7 +88,7 @@ unitTest(function textDecoderIgnoreBOM(): void {
});

unitTest(function textDecoderNotBOM(): void {
// prettier-ignore
// dprint-ignore
const fixture = new Uint8Array([
0xef, 0xbb, 0x89,
0xf0, 0x9d, 0x93, 0xbd,
Expand Down Expand Up @@ -120,7 +120,7 @@ unitTest(function textDecoderErrorEncoding(): void {
unitTest(function textEncoder(): void {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
// prettier-ignore
// dprint-ignore
assertEquals(Array.from(encoder.encode(fixture)), [
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
Expand All @@ -136,7 +136,7 @@ unitTest(function textEncodeInto(): void {
const result = encoder.encodeInto(fixture, bytes);
assertEquals(result.read, 4);
assertEquals(result.written, 4);
// prettier-ignore
// dprint-ignore
assertEquals(Array.from(bytes), [
0x74, 0x65, 0x78, 0x74, 0x00,
]);
Expand All @@ -149,7 +149,7 @@ unitTest(function textEncodeInto2(): void {
const result = encoder.encodeInto(fixture, bytes);
assertEquals(result.read, 8);
assertEquals(result.written, 16);
// prettier-ignore
// dprint-ignore
assertEquals(Array.from(bytes), [
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
Expand Down
4 changes: 2 additions & 2 deletions cli/js/web/decode_utf8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function decodeUtf8(
state = 0;
}

// prettier-ignore
// dprint-ignore
type = [
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
Expand All @@ -87,7 +87,7 @@ export function decodeUtf8(
state !== 0
? (input[i] & 0x3f) | (codepoint << 6)
: (0xff >> type) & input[i];
// prettier-ignore
// dprint-ignore
state = [
0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
Expand Down
2 changes: 1 addition & 1 deletion cli/js/web/text_encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const decoders = new Map<string, (options: DecoderOptions) => Decoder>();

// Single byte decoders are an array of code point lookups
const encodingIndexes = new Map<string, number[]>();
// prettier-ignore
// dprint-ignore
encodingIndexes.set("windows-1252", [
8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,
8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376,160,161,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/error_syntax.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

// prettier-ignore
// dprint-ignore
(the following is a syntax error ^^ ! )
2 changes: 1 addition & 1 deletion cli/tests/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// prettier-ignore
// dprint-ignore
const wasmCode = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127,
3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/wasm_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// i32.add)
// (export "add" (func $add))
// )
// prettier-ignore
// dprint-ignore
const bytes = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60,
0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01,
Expand Down
4 changes: 2 additions & 2 deletions core/encode_decode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ function assertArrayEquals(a1, a2) {
}

function main() {
// prettier-ignore
// dprint-ignore
const fixture1 = [
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
0xf0, 0x9d, 0x94, 0x81,
0xf0, 0x9d, 0x93, 0xbd
];
// prettier-ignore
// dprint-ignore
const fixture2 = [
72, 101, 108, 108,
111, 32, 239, 191,
Expand Down
2 changes: 1 addition & 1 deletion std/fs/testdata/0-link.ts
2 changes: 1 addition & 1 deletion std/ws/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test("[ws] read unmasked ping / pong frame", async () => {
const ping = await readFrame(buf);
assertEquals(ping.opcode, OpCode.Ping);
assertEquals(new Buffer(ping.payload).toString(), "Hello");
// prettier-ignore
// dprint-ignore
const pongFrame= [0x8a, 0x85, 0x37, 0xfa, 0x21, 0x3d, 0x7f, 0x9f, 0x4d, 0x51, 0x58]
const buf2 = new BufReader(new Buffer(new Uint8Array(pongFrame)));
const pong = await readFrame(buf2);
Expand Down
13 changes: 12 additions & 1 deletion tools/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def main():
did_fmt = False
if args.js:
prettier()
dprint()
did_fmt = True
if args.py:
yapf()
Expand All @@ -29,6 +30,7 @@ def main():

if not did_fmt:
prettier()
dprint()
yapf()
rustfmt()

Expand All @@ -37,12 +39,21 @@ def prettier():
print "prettier"
script = os.path.join(third_party_path, "node_modules", "prettier",
"bin-prettier.js")
source_files = git_ls_files(root_path, ["*.js", "*.json", "*.ts", "*.md"])
source_files = git_ls_files(root_path, ["*.json", "*.md", "*.d.ts"])
run(["node", script, "--write", "--loglevel=error", "--"] + source_files,
shell=False,
quiet=True)


def dprint():
print "dprint"
source_files = git_ls_files(root_path, ["*.js", "*.ts"])
source_files = filter(lambda x: ("d.ts" in x) == False, source_files)
run(["cargo", "run", "--", "fmt", "-q"] + source_files,
shell=False,
quiet=True)


def yapf():
print "yapf"
script = os.path.join(third_party_path, "python_packages", "bin", "yapf")
Expand Down