diff --git a/Makefile b/Makefile index ee9463c49..17ebdd63f 100644 --- a/Makefile +++ b/Makefile @@ -194,7 +194,7 @@ lint: node_modules $(BUILD)/protobuf $(BUILD)/protobuf-test $(BUILD)/protobuf-co .PHONY: format format: node_modules $(BIN)/git-ls-files-unstaged $(BIN)/license-header ## Format all files, adding license headers - npx prettier --write '**/*.{json,js,jsx,ts,tsx,css,mjs}' --loglevel error + npx prettier --write '**/*.{json,js,jsx,ts,tsx,css,mjs}' --log-level error $(BIN)/git-ls-files-unstaged | \ grep -v $(patsubst %,-e %,$(sort $(LICENSE_HEADER_IGNORES))) | \ xargs $(BIN)/license-header \ diff --git a/package-lock.json b/package-lock.json index e69f470a8..d88ae74fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "eslint-import-resolver-typescript": "^3.5.5", "eslint-plugin-import": "^2.28.0", "eslint-plugin-node": "^11.1.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "typescript": "^5.1.6" }, "engines": { @@ -5941,15 +5941,15 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", + "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" diff --git a/package.json b/package.json index d336c2d46..862d815c6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "eslint-import-resolver-typescript": "^3.5.5", "eslint-plugin-import": "^2.28.0", "eslint-plugin-node": "^11.1.0", - "prettier": "^2.8.8", + "prettier": "^3.0.0", "typescript": "^5.1.6" }, "dependencies": { diff --git a/packages/protobuf-conformance/src/conformance.ts b/packages/protobuf-conformance/src/conformance.ts index 47162718c..1472cfa69 100644 --- a/packages/protobuf-conformance/src/conformance.ts +++ b/packages/protobuf-conformance/src/conformance.ts @@ -43,7 +43,7 @@ const registry = createRegistry( Int32Value, TestAllTypesProto3, TestAllTypesProto2, - Any + Any, ); function main() { @@ -54,7 +54,7 @@ function main() { } } catch (e) { process.stderr.write( - `conformance.ts: exiting after ${testCount} tests: ${String(e)}` + `conformance.ts: exiting after ${testCount} tests: ${String(e)}`, ); process.exit(1); } @@ -149,7 +149,7 @@ function test(request: ConformanceRequest): ConformanceResponse["result"] { // Returns true if the test ran successfully, false on legitimate EOF. // If EOF is encountered in an unexpected place, raises IOError. function testIo( - test: (request: ConformanceRequest) => ConformanceResponse["result"] + test: (request: ConformanceRequest) => ConformanceResponse["result"], ): boolean { setBlockingStdout(); const requestLengthBuf = readBuffer(4); @@ -198,7 +198,7 @@ function writeBuffer(buffer: Buffer): void { 1, buffer, totalWritten, - buffer.length - totalWritten + buffer.length - totalWritten, ); } } diff --git a/packages/protobuf-test/src/clone.test.ts b/packages/protobuf-test/src/clone.test.ts index 4d78306c5..c76b39f8a 100644 --- a/packages/protobuf-test/src/clone.test.ts +++ b/packages/protobuf-test/src/clone.test.ts @@ -45,7 +45,7 @@ describe("clone", function () { b.messageField.name = "123"; } expect(b.messageField?.name).not.toBe(a.messageField?.name); - } + }, ); testMT( @@ -82,7 +82,7 @@ describe("clone", function () { const c = a.clone(); c.bytesField.set([0, 1], 0); expect(c.bytesField).not.toStrictEqual(a.bytesField); - } + }, ); testMT( @@ -118,7 +118,7 @@ describe("clone", function () { expect(b).toStrictEqual(a); a.doubleField.push(1.2); expect(b.doubleField).not.toBe(a.doubleField); - } + }, ); testMT({ ts: TS_WrappersMessage, js: JS_WrappersMessage }, (messageType) => { diff --git a/packages/protobuf-test/src/constructor.test.ts b/packages/protobuf-test/src/constructor.test.ts index b77cc9a60..f3ed495bc 100644 --- a/packages/protobuf-test/src/constructor.test.ts +++ b/packages/protobuf-test/src/constructor.test.ts @@ -30,7 +30,7 @@ describe("constructor takes message partial for message field", function () { }, }); expect(m.recursiveMessage?.optionalInt32).toBe(123); - } + }, ); }); @@ -44,7 +44,7 @@ describe("constructor takes message instance for message field", function () { }), }); expect(m.recursiveMessage?.optionalInt32).toBe(123); - } + }, ); }); @@ -68,7 +68,7 @@ describe("constructor takes partial message for oneof field", function () { expect(m.oneofField.value.corecursive).not.toBeUndefined(); expect(m.oneofField.value.corecursive?.optionalInt32).toBe(123); } - } + }, ); }); @@ -91,10 +91,10 @@ describe("constructor takes partial message for map value", function () { expect(m.mapStringNestedMessage["key"].a).toBe(0); expect(m.mapStringNestedMessage["key"].corecursive).not.toBeUndefined(); expect(m.mapStringNestedMessage["key"].corecursive?.optionalInt32).toBe( - 123 + 123, ); } - } + }, ); testMT( { ts: TS_TestAllTypesProto3, js: JS_TestAllTypesProto3 }, @@ -136,21 +136,21 @@ describe("constructor takes partial message for map value", function () { }); expect(t.optionalNestedMessage?.a).toBe(123); expect( - t.optionalNestedMessage?.corecursive?.optionalNestedMessage?.a + t.optionalNestedMessage?.corecursive?.optionalNestedMessage?.a, ).toBe(456); expect( t.optionalNestedMessage?.corecursive?.optionalNestedMessage?.corecursive - ?.optionalNestedMessage?.a + ?.optionalNestedMessage?.a, ).toBe(0); expect(t.repeatedNestedMessage.length).toBe(1); expect(t.repeatedNestedMessage[0]?.a).toBe(123); expect( - t.repeatedNestedMessage[0]?.corecursive?.repeatedNestedMessage[0]?.a + t.repeatedNestedMessage[0]?.corecursive?.repeatedNestedMessage[0]?.a, ).toBe(456); expect( t.repeatedNestedMessage[0]?.corecursive?.repeatedNestedMessage[0] - ?.corecursive?.repeatedNestedMessage[0]?.a + ?.corecursive?.repeatedNestedMessage[0]?.a, ).toBe(0); - } + }, ); }); diff --git a/packages/protobuf-test/src/create-registry-from-desc.test.ts b/packages/protobuf-test/src/create-registry-from-desc.test.ts index 2f28e99c8..6590d6f30 100644 --- a/packages/protobuf-test/src/create-registry-from-desc.test.ts +++ b/packages/protobuf-test/src/create-registry-from-desc.test.ts @@ -49,7 +49,7 @@ describe("createRegistryFromDescriptors()", () => { }); function assertExpectedRegistry( - registry: ReturnType + registry: ReturnType, ): void { expect(registry.findEnum("foo.Foo")).toBeUndefined(); const mt = registry.findMessage(TestAllTypes.typeName); diff --git a/packages/protobuf-test/src/create-registry.test.ts b/packages/protobuf-test/src/create-registry.test.ts index fb7cbdfad..9da83925f 100644 --- a/packages/protobuf-test/src/create-registry.test.ts +++ b/packages/protobuf-test/src/create-registry.test.ts @@ -27,13 +27,13 @@ describe("createRegistry()", () => { test("finds message", () => { const reg = createRegistry(MessageFieldMessage); expect(reg.findMessage(MessageFieldMessage.typeName)).toBe( - MessageFieldMessage + MessageFieldMessage, ); }); test("finds message through field", () => { const reg = createRegistry(MessageFieldMessage); expect(reg.findMessage(MessageFieldMessage_TestMessage.typeName)).toBe( - MessageFieldMessage_TestMessage + MessageFieldMessage_TestMessage, ); }); }); diff --git a/packages/protobuf-test/src/descriptor-set.test.ts b/packages/protobuf-test/src/descriptor-set.test.ts index f60f668fb..945b5958f 100644 --- a/packages/protobuf-test/src/descriptor-set.test.ts +++ b/packages/protobuf-test/src/descriptor-set.test.ts @@ -31,7 +31,7 @@ describe("DescriptorSet", () => { const set = createDescriptorSet(fdsBytes); test("knows extension", () => { const ext = set.extensions.get( - "protobuf_unittest.optional_int32_extension" + "protobuf_unittest.optional_int32_extension", ); expect(ext).toBeDefined(); expect(ext?.name).toBe("optional_int32_extension"); @@ -42,28 +42,28 @@ describe("DescriptorSet", () => { expect(ext?.fieldKind).toBe("scalar"); expect(ext?.scalar).toBe(ScalarType.INT32); expect(ext?.toString()).toBe( - "extension protobuf_unittest.optional_int32_extension" + "extension protobuf_unittest.optional_int32_extension", ); expect(ext?.declarationString()).toBe( - "optional int32 optional_int32_extension = 1" + "optional int32 optional_int32_extension = 1", ); }); test("knows nested extension", () => { const ext = set.extensions.get( - "protobuf_unittest.TestNestedExtension.nested_string_extension" + "protobuf_unittest.TestNestedExtension.nested_string_extension", ); expect(ext).toBeDefined(); expect(ext?.name).toBe("nested_string_extension"); expect(ext?.typeName).toBe( - "protobuf_unittest.TestNestedExtension.nested_string_extension" + "protobuf_unittest.TestNestedExtension.nested_string_extension", ); expect(ext?.extendee.typeName).toBe(TestAllExtensions.typeName); expect(ext?.scalar).toBe(ScalarType.STRING); expect(ext?.toString()).toBe( - "extension protobuf_unittest.TestNestedExtension.nested_string_extension" + "extension protobuf_unittest.TestNestedExtension.nested_string_extension", ); expect(ext?.declarationString()).toBe( - "optional string nested_string_extension = 1003" + "optional string nested_string_extension = 1003", ); const ext2 = set.messages .get(TestNestedExtension.typeName) @@ -77,7 +77,7 @@ describe("DescriptorSet", () => { if (message !== undefined) { const field = message.fields.find((f) => f.number === 1); expect(field?.declarationString()).toBe( - 'string scalar_field = 1 [json_name = "scalarFieldJsonName"]' + 'string scalar_field = 1 [json_name = "scalarFieldJsonName"]', ); } }); @@ -87,7 +87,7 @@ describe("DescriptorSet", () => { if (message !== undefined) { const field = message.fields.find((f) => f.number === 1); expect(field?.declarationString()).toBe( - "repeated double double_field = 1" + "repeated double double_field = 1", ); } }); @@ -110,15 +110,15 @@ describe("DescriptorSet", () => { describe("for file", () => { const file = set.files.find((file) => file.messages.some( - (message) => message.typeName === MessageWithComments.typeName - ) + (message) => message.typeName === MessageWithComments.typeName, + ), ); test("syntax", () => { const comments = file?.getSyntaxComments(); expect(comments).toBeDefined(); if (comments) { expect(comments.leadingDetached[0]).toMatch( - / Copyright .* Buf Technologies/ + / Copyright .* Buf Technologies/, ); expect(comments.leading).toBe(" Comment before syntax.\n"); expect(comments.trailing).toBe(" Comment next to syntax.\n"); @@ -159,7 +159,7 @@ describe("DescriptorSet", () => { "\n Comment after start of message,\n with funny indentation,\n and empty lines on start and end.\n\n", ]); expect(comments.leading).toBe( - " Comment before field with 5 lines:\n line 2, next is empty\n\n line 4, next is empty\n\n" + " Comment before field with 5 lines:\n line 2, next is empty\n\n line 4, next is empty\n\n", ); expect(comments.trailing).toBe(" Comment next to field.\n"); } diff --git a/packages/protobuf-test/src/equals.test.ts b/packages/protobuf-test/src/equals.test.ts index 43f6c3f6b..4affeef92 100644 --- a/packages/protobuf-test/src/equals.test.ts +++ b/packages/protobuf-test/src/equals.test.ts @@ -121,7 +121,7 @@ describe("equals", function () { a.repeatedMessageField[0].name = "changed"; expect(a.equals(b)).toBeFalsy(); }); - } + }, ); describeMT( @@ -161,7 +161,7 @@ describe("equals", function () { expect(a).not.toStrictEqual(b); expect(a.equals(b)).toBeFalsy(); }); - } + }, ); describeMT({ ts: TS_MapsMessage, js: JS_MapsMessage }, (messageType) => { @@ -176,8 +176,8 @@ describe("equals", function () { strMsgField: { a: { strStrField: { e: "f", c: "d" } }, }, - }) - ) + }), + ), ).toBeTruthy(); }); test("added key not equal", () => { @@ -192,8 +192,8 @@ describe("equals", function () { a: {}, b: {}, }, - }) - ) + }), + ), ).toBeFalsy(); }); test("removed key not equal", () => { @@ -207,8 +207,8 @@ describe("equals", function () { strMsgField: { a: { strStrField: { c: "d" } }, }, - }) - ) + }), + ), ).toBeFalsy(); }); test("changed value not equal", () => { @@ -222,8 +222,8 @@ describe("equals", function () { strMsgField: { a: { strStrField: { c: "e" } }, }, - }) - ) + }), + ), ).toBeFalsy(); }); }); diff --git a/packages/protobuf-test/src/google/protobuf/any.test.ts b/packages/protobuf-test/src/google/protobuf/any.test.ts index 9c927cc6f..604057e9b 100644 --- a/packages/protobuf-test/src/google/protobuf/any.test.ts +++ b/packages/protobuf-test/src/google/protobuf/any.test.ts @@ -141,7 +141,7 @@ describe("google.protobuf.Any", () => { }, }), }, - }) + }), ).toJson({ typeRegistry }); expect(got).toStrictEqual(want); }); @@ -156,7 +156,7 @@ describe("google.protobuf.Any", () => { "@type": "type.googleapis.com/google.protobuf.Value", value: 1, }, - { typeRegistry } + { typeRegistry }, ); const got = new Value(); expect(any.unpackTo(got)).toBe(true); diff --git a/packages/protobuf-test/src/google/protobuf/field_mask.test.ts b/packages/protobuf-test/src/google/protobuf/field_mask.test.ts index 3bddc7609..39bb73a8d 100644 --- a/packages/protobuf-test/src/google/protobuf/field_mask.test.ts +++ b/packages/protobuf-test/src/google/protobuf/field_mask.test.ts @@ -41,7 +41,7 @@ describe("google.protobuf.FieldMask", () => { expect(() => { fieldMask.toJson(); }).toThrow( - 'cannot encode google.protobuf.FieldMask to JSON: lowerCamelCase of path name "user.displayName" is irreversible' + 'cannot encode google.protobuf.FieldMask to JSON: lowerCamelCase of path name "user.displayName" is irreversible', ); }); test("fromJson fails on invalid json", () => { @@ -49,7 +49,7 @@ describe("google.protobuf.FieldMask", () => { expect(() => { FieldMask.fromJson(json); }).toThrow( - "cannot decode google.protobuf.FieldMask from JSON: path names must be lowerCamelCase" + "cannot decode google.protobuf.FieldMask from JSON: path names must be lowerCamelCase", ); }); }); diff --git a/packages/protobuf-test/src/google/protobuf/struct.test.ts b/packages/protobuf-test/src/google/protobuf/struct.test.ts index e2f9e418e..ded7159e6 100644 --- a/packages/protobuf-test/src/google/protobuf/struct.test.ts +++ b/packages/protobuf-test/src/google/protobuf/struct.test.ts @@ -47,7 +47,7 @@ describe("google.protobuf.Struct", () => { test("decodes from JSON", () => { const got = Struct.fromJson(json); expect(Object.keys(got.fields).length).toBe( - Object.keys(struct.fields).length + Object.keys(struct.fields).length, ); expect(got.fields["a"].kind.case).toBe(struct.fields["a"].kind.case); expect(got.fields["a"].kind.value).toBe(struct.fields["a"].kind.value); @@ -77,7 +77,7 @@ describe("google.protobuf.Value", () => { // See struct.proto const value = new Value(); expect(() => value.toJson()).toThrowError( - "google.protobuf.Value must have a value" + "google.protobuf.Value must have a value", ); }); test("decodes from JSON", () => { diff --git a/packages/protobuf-test/src/google/protobuf/test_messages_proto3.test.ts b/packages/protobuf-test/src/google/protobuf/test_messages_proto3.test.ts index 57dcfd310..322953388 100644 --- a/packages/protobuf-test/src/google/protobuf/test_messages_proto3.test.ts +++ b/packages/protobuf-test/src/google/protobuf/test_messages_proto3.test.ts @@ -39,5 +39,5 @@ describeMT( > = { ...new messageType() }; expect(got).toStrictEqual(want); }); - } + }, ); diff --git a/packages/protobuf-test/src/google/protobuf/wrappers.test.ts b/packages/protobuf-test/src/google/protobuf/wrappers.test.ts index ec36f5772..75e393711 100644 --- a/packages/protobuf-test/src/google/protobuf/wrappers.test.ts +++ b/packages/protobuf-test/src/google/protobuf/wrappers.test.ts @@ -30,7 +30,7 @@ describe("google.protobuf.DoubleValue", () => { }); test("unwraps", () => { const got = DoubleValue.fieldWrapper.unwrapField( - new DoubleValue({ value: primitive }) + new DoubleValue({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -50,7 +50,7 @@ describe("google.protobuf.FloatValue", () => { }); test("unwraps", () => { const got = FloatValue.fieldWrapper.unwrapField( - new FloatValue({ value: primitive }) + new FloatValue({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -70,7 +70,7 @@ describe("google.protobuf.Int64Value", () => { }); test("unwraps", () => { const got = Int64Value.fieldWrapper.unwrapField( - new Int64Value({ value: primitive }) + new Int64Value({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -90,7 +90,7 @@ describe("google.protobuf.UInt64Value", () => { }); test("unwraps", () => { const got = UInt64Value.fieldWrapper.unwrapField( - new UInt64Value({ value: primitive }) + new UInt64Value({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -110,7 +110,7 @@ describe("google.protobuf.Int32Value", () => { }); test("unwraps", () => { const got = Int32Value.fieldWrapper.unwrapField( - new Int32Value({ value: primitive }) + new Int32Value({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -130,7 +130,7 @@ describe("google.protobuf.UInt32Value", () => { }); test("unwraps", () => { const got = UInt32Value.fieldWrapper.unwrapField( - new UInt32Value({ value: primitive }) + new UInt32Value({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -151,7 +151,7 @@ describe("google.protobuf.BoolValue", () => { }); test("unwraps", () => { const got = BoolValue.fieldWrapper.unwrapField( - new BoolValue({ value: primitive }) + new BoolValue({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -171,7 +171,7 @@ describe("google.protobuf.StringValue", () => { }); test("unwraps", () => { const got = StringValue.fieldWrapper.unwrapField( - new StringValue({ value: primitive }) + new StringValue({ value: primitive }), ); expect(got).toBe(primitive); }); @@ -191,7 +191,7 @@ describe("google.protobuf.BytesValue", () => { }); test("unwraps", () => { const got = BytesValue.fieldWrapper.unwrapField( - new BytesValue({ value: primitive }) + new BytesValue({ value: primitive }), ); expect(got).toBe(primitive); }); diff --git a/packages/protobuf-test/src/helpers.ts b/packages/protobuf-test/src/helpers.ts index d962acc63..45eff1394 100644 --- a/packages/protobuf-test/src/helpers.ts +++ b/packages/protobuf-test/src/helpers.ts @@ -33,7 +33,7 @@ export function describeMT>( ts: MessageType; js: MessageType; }, - fn: (type: MessageType) => void + fn: (type: MessageType) => void, ) { const tsDynType = makeMessageTypeDynamic(opt.ts); type testCase = { name: string; messageType: MessageType }; @@ -57,7 +57,7 @@ export function testMT>( ts: MessageType; js: MessageType; }, - fn: (type: MessageType) => void + fn: (type: MessageType) => void, ) { const tsDynType = makeMessageTypeDynamic(opt.ts); type testCase = { name: string; messageType: MessageType }; @@ -73,7 +73,7 @@ export function testMT>( const dr = createRegistryFromDescriptors(readFileSync("./descriptorset.bin")); export function makeMessageTypeDynamic>( - type: MessageType + type: MessageType, ): MessageType { const dyn = dr.findMessage(type.typeName); if (!dyn) { diff --git a/packages/protobuf-test/src/iterating-fields.test.ts b/packages/protobuf-test/src/iterating-fields.test.ts index 3232d2f29..e453a9c87 100644 --- a/packages/protobuf-test/src/iterating-fields.test.ts +++ b/packages/protobuf-test/src/iterating-fields.test.ts @@ -34,18 +34,18 @@ describe("iterating fields", function () { PES: "Protobuf-ES", CES: "Connect-ES", }, - }) + }), ); expect(r.length).toBe(6); expect(r[0]).toBe("field firstName: John"); expect(r[1]).toBe("field lastName: Smith"); expect(r[2]).toBe("field active: true"); expect(r[3]).toBe( - 'field manager: {"firstName":"Jane","lastName":"Jones","active":false,"locations":[],"projects":{}}' + 'field manager: {"firstName":"Jane","lastName":"Jones","active":false,"locations":[],"projects":{}}', ); expect(r[4]).toBe("field locations: PIT,GER"); expect(r[5]).toBe( - 'field projects: {"PES":"Protobuf-ES","CES":"Connect-ES"}' + 'field projects: {"PES":"Protobuf-ES","CES":"Connect-ES"}', ); }); }); diff --git a/packages/protobuf-test/src/json-names.test.ts b/packages/protobuf-test/src/json-names.test.ts index 9ec7e746c..3f743b276 100644 --- a/packages/protobuf-test/src/json-names.test.ts +++ b/packages/protobuf-test/src/json-names.test.ts @@ -88,7 +88,7 @@ function getProtocJsonName(protoName: string): string | false { ["-I", tempDir, inFilename, "--descriptor_set_out", outFilename], { encoding: "utf-8", - } + }, ); if (result.stderr.length > 0) { if (result.stderr.indexOf("Expected field name.") >= 0) { @@ -105,7 +105,7 @@ function getProtocJsonName(protoName: string): string | false { } if ( result.stderr.indexOf( - "Invalid control characters encountered in text." + "Invalid control characters encountered in text.", ) >= 0 ) { return false; diff --git a/packages/protobuf-test/src/message.test.ts b/packages/protobuf-test/src/message.test.ts index 79d3cb542..d4109da0b 100644 --- a/packages/protobuf-test/src/message.test.ts +++ b/packages/protobuf-test/src/message.test.ts @@ -214,9 +214,9 @@ describe("Message.fromJsonString()", function () { // The regex is so that this test passes in Node 18 and Node 19. // The error message text changed across major versions. expect(() => - TestAllTypesProto3.fromJsonString("this is not json") + TestAllTypesProto3.fromJsonString("this is not json"), ).toThrowError( - /^cannot decode protobuf_test_messages\.proto3\.TestAllTypesProto3 from JSON: Unexpected token '?h'?/ + /^cannot decode protobuf_test_messages\.proto3\.TestAllTypesProto3 from JSON: Unexpected token '?h'?/, ); }); }); diff --git a/packages/protobuf-test/src/mixing-instances.test.ts b/packages/protobuf-test/src/mixing-instances.test.ts index de0722ba6..4a504001e 100644 --- a/packages/protobuf-test/src/mixing-instances.test.ts +++ b/packages/protobuf-test/src/mixing-instances.test.ts @@ -44,7 +44,7 @@ describe("mixing message instances in the constructor", () => { }); expect(message.messageField?.name).toBe("foo"); expect(message.messageField).toBeInstanceOf( - TS_MessageFieldMessage_TestMessage + TS_MessageFieldMessage_TestMessage, ); }); }); diff --git a/packages/protobuf-test/src/msg-json-names.test.ts b/packages/protobuf-test/src/msg-json-names.test.ts index 83b02f5db..c2d720650 100644 --- a/packages/protobuf-test/src/msg-json-names.test.ts +++ b/packages/protobuf-test/src/msg-json-names.test.ts @@ -44,5 +44,5 @@ describeMT( a: "a", }); }); - } + }, ); diff --git a/packages/protobuf-test/src/msg-message.test.ts b/packages/protobuf-test/src/msg-message.test.ts index b9427097c..698a0f728 100644 --- a/packages/protobuf-test/src/msg-message.test.ts +++ b/packages/protobuf-test/src/msg-message.test.ts @@ -47,41 +47,41 @@ describeMT( test("defaults decodes from JSON", () => { const got = messageType.fromJson(defaultJson); expect(got.messageField?.name).toStrictEqual( - defaultFields.messageField?.name + defaultFields.messageField?.name, ); expect(got.repeatedMessageField.length).toStrictEqual( - defaultFields.repeatedMessageField.length + defaultFields.repeatedMessageField.length, ); }); test("example encodes to JSON", () => { /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access */ const got = new messageType(exampleFields).toJson(); expect((got as any).messageField?.name).toStrictEqual( - (exampleJson as any).messageField?.name + (exampleJson as any).messageField?.name, ); expect((got as any).repeatedMessageField.length).toStrictEqual( - (exampleJson as any).repeatedMessageField.length + (exampleJson as any).repeatedMessageField.length, ); expect((got as any).repeatedMessageField[0].name).toStrictEqual( - (exampleJson as any).repeatedMessageField[0].name + (exampleJson as any).repeatedMessageField[0].name, ); expect((got as any).repeatedMessageField[1].name).toStrictEqual( - (exampleJson as any).repeatedMessageField[1].name + (exampleJson as any).repeatedMessageField[1].name, ); }); test("example decodes from JSON", () => { const got = messageType.fromJson(exampleJson); expect(got.messageField?.name).toStrictEqual( - exampleFields.messageField.name + exampleFields.messageField.name, ); expect(got.repeatedMessageField.length).toStrictEqual( - exampleFields.repeatedMessageField.length + exampleFields.repeatedMessageField.length, ); expect(got.repeatedMessageField[0].name).toStrictEqual( - exampleFields.repeatedMessageField[0].name + exampleFields.repeatedMessageField[0].name, ); expect(got.repeatedMessageField[1].name).toStrictEqual( - exampleFields.repeatedMessageField[1].name + exampleFields.repeatedMessageField[1].name, ); }); test("JSON.stringify correctly stringifies defaults", () => { @@ -90,7 +90,7 @@ describeMT( expect(got).toStrictEqual( msg.toJsonString({ emitDefaultValues: true, - }) + }), ); }); test("JSON.stringify correctly stringifies fields with values", () => { @@ -99,8 +99,8 @@ describeMT( expect(got).toStrictEqual( msg.toJsonString({ emitDefaultValues: true, - }) + }), ); }); - } + }, ); diff --git a/packages/protobuf-test/src/msg-scalar.test.ts b/packages/protobuf-test/src/msg-scalar.test.ts index 39822c463..fdf7a59de 100644 --- a/packages/protobuf-test/src/msg-scalar.test.ts +++ b/packages/protobuf-test/src/msg-scalar.test.ts @@ -119,7 +119,7 @@ describeMT( bytesField: new Uint8Array(bytes), }); }); - } + }, ); describeMT( @@ -224,5 +224,5 @@ describeMT( bytesField: [new Uint8Array(bytes)], }); }); - } + }, ); diff --git a/packages/protobuf-test/src/proto-base64.test.ts b/packages/protobuf-test/src/proto-base64.test.ts index ede1729d0..2c907e839 100644 --- a/packages/protobuf-test/src/proto-base64.test.ts +++ b/packages/protobuf-test/src/proto-base64.test.ts @@ -127,7 +127,7 @@ describe("protoBase64", function () { `should throw an error trying to decode %s`, (input) => { expect(() => protoBase64.dec(input)).toThrow("invalid base64 string."); - } + }, ); }); diff --git a/packages/protobuf-test/src/proto-delimited.test.ts b/packages/protobuf-test/src/proto-delimited.test.ts index 598c31f33..b76dbf755 100644 --- a/packages/protobuf-test/src/proto-delimited.test.ts +++ b/packages/protobuf-test/src/proto-delimited.test.ts @@ -100,7 +100,7 @@ describe("protoDelimited", function () { async function* createAsyncIterableBytes( bytes: Uint8Array, chunkSize = 2, - delay = 5 + delay = 5, ): AsyncIterable { let offset = 0; for (;;) { @@ -120,12 +120,12 @@ describe("protoDelimited", function () { .raw(testMessagesBytes[0]) .uint32(testMessagesSizes[1]) .raw(testMessagesBytes[1]) - .finish() + .finish(), ); let i = 0; for await (const dec of protoDelimited.decStream( TestAllTypesProto3, - stream + stream, )) { expect(TestAllTypesProto3.equals(dec, testMessages[i])).toBeTruthy(); i++; @@ -142,13 +142,13 @@ describe("protoDelimited", function () { } writeStream.end(); await new Promise((resolve, reject) => - writeStream.close((err) => (err ? reject(err) : resolve())) + writeStream.close((err) => (err ? reject(err) : resolve())), ); const readStream = createReadStream(path); let i = 0; for await (const m of protoDelimited.decStream( TestAllTypesProto3, - readStream + readStream, )) { expect(TestAllTypesProto3.equals(m, testMessages[i])).toBe(true); i++; @@ -170,7 +170,7 @@ describe("protoDelimited", function () { const got = protoDelimited.peekSize(bytes); expect(got.offset).toBe(bytes.byteLength); }); - } + }, ); describe("with incomplete varint", function () { const complete = new BinaryWriter().uint32(0xffffffff).finish(); // uint32 max is 5 bytes as varint @@ -203,7 +203,7 @@ describe("protoDelimited", function () { it("should return expected offset", function () { const got = protoDelimited.peekSize(bytes); expect(got.offset).toBe( - bytes.byteLength - testMessagesBytes[0].byteLength + bytes.byteLength - testMessagesBytes[0].byteLength, ); }); }); @@ -211,7 +211,7 @@ describe("protoDelimited", function () { async function* createAsyncIterableBytes( bytes: Uint8Array, chunkSize = 2, - delay = 5 + delay = 5, ): AsyncIterable { let offset = 0; for (;;) { @@ -230,7 +230,7 @@ describe("protoDelimited", function () { .raw(testMessagesBytes[0]) .uint32(testMessagesSizes[1]) .raw(testMessagesBytes[1]) - .finish() + .finish(), ); /** * An example implementation for a function decoding size-delimited messages @@ -239,7 +239,7 @@ describe("protoDelimited", function () { */ async function* decStream>( iterable: AsyncIterable, - type: MessageType + type: MessageType, ) { // append chunk to buffer, returning updated buffer function append(buffer: Uint8Array, chunk: Uint8Array): Uint8Array { diff --git a/packages/protobuf-test/src/proto-int64.test.ts b/packages/protobuf-test/src/proto-int64.test.ts index eb50d088d..560d32165 100644 --- a/packages/protobuf-test/src/proto-int64.test.ts +++ b/packages/protobuf-test/src/proto-int64.test.ts @@ -187,7 +187,7 @@ describe("protoInt64", function () { test("should fail to encode invalid", () => { if (protoInt64.supported) { expect(() => protoInt64.enc(BigInt("18446744073709551615"))).toThrow( - "int64 invalid: 18446744073709551615" + "int64 invalid: 18446744073709551615", ); } }); @@ -217,21 +217,21 @@ describe("protoInt64", function () { test("should fail to encode invalid", () => { if (protoInt64.supported) { expect(() => protoInt64.uEnc(BigInt(-127))).toThrow( - "uint64 invalid: -127" + "uint64 invalid: -127", ); expect(() => protoInt64.uEnc(BigInt("-9007199254740991"))).toThrow( - "uint64 invalid: -9007199254740991" + "uint64 invalid: -9007199254740991", ); expect(() => protoInt64.uEnc(BigInt("-9223372036854775808"))).toThrow( - "uint64 invalid: -9223372036854775808" + "uint64 invalid: -9223372036854775808", ); } expect(() => protoInt64.uEnc(-127)).toThrow("uint64 invalid: -127"); expect(() => protoInt64.uEnc("-9007199254740991")).toThrow( - "uint64 invalid: -9007199254740991" + "uint64 invalid: -9007199254740991", ); expect(() => protoInt64.uEnc("-9223372036854775808")).toThrow( - "uint64 invalid: -9223372036854775808" + "uint64 invalid: -9223372036854775808", ); }); }); diff --git a/packages/protobuf-test/src/proto2.test.ts b/packages/protobuf-test/src/proto2.test.ts index 7ce6487f7..546d11ba6 100644 --- a/packages/protobuf-test/src/proto2.test.ts +++ b/packages/protobuf-test/src/proto2.test.ts @@ -54,14 +54,14 @@ describe("setDefaults", () => { new Uint8Array([ 0x00, 0x78, 0x5c, 0x78, 0x78, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x08, 0x0c, 0x0a, 0x0d, 0x09, 0x0b, - ]) + ]), ); expect(msg.int32Field).toBe(128); expect(msg.int46Field).toBe(protoInt64.parse("-256")); expect(msg.floatField).toBe(-512.13); expect(msg.enumField).toBe(TS_Proto2Enum.YES); expect(msg.messageField).toBe(undefined); - } + }, ); }); @@ -78,7 +78,7 @@ describe("verify", () => { expect(verify(msg)).toBe(false); setDefaults(msg); expect(verify(msg)).toBe(true); - } + }, ); }); @@ -96,9 +96,9 @@ describeMT( messageField: {}, bytesField: new Uint8Array(0), stringField: "", - }).toJson() + }).toJson(), ).toThrow( - `cannot encode field ${messageType.typeName}.enum_field to JSON: required field not set` + `cannot encode field ${messageType.typeName}.enum_field to JSON: required field not set`, ); }); test("encode to binary errors on missing required field", () => { @@ -108,12 +108,12 @@ describeMT( messageField: {}, bytesField: new Uint8Array(0), stringField: "", - }).toBinary() + }).toBinary(), ).toThrow( - `cannot encode field ${messageType.typeName}.enum_field to binary: required field not set` + `cannot encode field ${messageType.typeName}.enum_field to binary: required field not set`, ); }); - } + }, ); describeMT( @@ -123,5 +123,5 @@ describeMT( const got = { ...new messageType() }; expect(got).toStrictEqual({}); }); - } + }, ); diff --git a/packages/protobuf-test/src/to-plain-message.test.ts b/packages/protobuf-test/src/to-plain-message.test.ts index cb9d5e4e5..d866f4b25 100644 --- a/packages/protobuf-test/src/to-plain-message.test.ts +++ b/packages/protobuf-test/src/to-plain-message.test.ts @@ -99,7 +99,7 @@ describe("toPlainMessage", () => { case: "e", value: OneofEnum.A, }, - }) + }), ); expect(act).toEqual({ enum: { case: "e", value: OneofEnum.A }, @@ -115,7 +115,7 @@ describe("toPlainMessage", () => { case: "foo", value: new OneofMessageFoo(), }, - }) + }), ); expect(act).toEqual({ message: { @@ -137,7 +137,7 @@ describe("toPlainMessage", () => { case: "value", value: 1, }, - }) + }), ); expect(act).toEqual({ scalar: { case: "value", value: 1 }, diff --git a/packages/protobuf-test/src/wkt-wrappers.test.ts b/packages/protobuf-test/src/wkt-wrappers.test.ts index cdfbe73c0..a94374a87 100644 --- a/packages/protobuf-test/src/wkt-wrappers.test.ts +++ b/packages/protobuf-test/src/wkt-wrappers.test.ts @@ -165,5 +165,5 @@ describeMT( expect(wJson.mapBoolValueField["bar"].value).toBe(false); }); }); - } + }, ); diff --git a/packages/protobuf/src/binary-encoding.ts b/packages/protobuf/src/binary-encoding.ts index 36980471d..54d086da5 100644 --- a/packages/protobuf/src/binary-encoding.ts +++ b/packages/protobuf/src/binary-encoding.ts @@ -577,7 +577,7 @@ export class BinaryReader implements IBinaryReader { wireType = tag & 7; if (fieldNo <= 0 || wireType < 0 || wireType > 5) throw new Error( - "illegal tag: field no " + fieldNo + " wire type " + wireType + "illegal tag: field no " + fieldNo + " wire type " + wireType, ); return [fieldNo, wireType]; } diff --git a/packages/protobuf/src/binary-format.ts b/packages/protobuf/src/binary-format.ts index deca70569..da3bfd2ed 100644 --- a/packages/protobuf/src/binary-format.ts +++ b/packages/protobuf/src/binary-format.ts @@ -29,14 +29,14 @@ export interface BinaryFormat { * Provide options for parsing binary data. */ makeReadOptions( - options?: Partial + options?: Partial, ): Readonly; /** * Provide options for serializing binary data. */ makeWriteOptions( - options?: Partial + options?: Partial, ): Readonly; /** @@ -46,7 +46,7 @@ export interface BinaryFormat { message: Message, reader: IBinaryReader, length: number, - options: BinaryReadOptions + options: BinaryReadOptions, ): void; /** @@ -55,7 +55,7 @@ export interface BinaryFormat { writeMessage( message: Message, writer: IBinaryWriter, - options: BinaryWriteOptions + options: BinaryWriteOptions, ): void; /** @@ -67,7 +67,7 @@ export interface BinaryFormat { * For more details see https://developers.google.com/protocol-buffers/docs/proto3#unknowns */ listUnknownFields( - message: Message + message: Message, ): ReadonlyArray<{ no: number; wireType: WireType; data: Uint8Array }>; /** @@ -92,7 +92,7 @@ export interface BinaryFormat { message: Message, no: number, wireType: WireType, - data: Uint8Array + data: Uint8Array, ): void; } diff --git a/packages/protobuf/src/create-descriptor-set.ts b/packages/protobuf/src/create-descriptor-set.ts index d42dcaf7d..9c4d68d27 100644 --- a/packages/protobuf/src/create-descriptor-set.ts +++ b/packages/protobuf/src/create-descriptor-set.ts @@ -55,7 +55,7 @@ import { protoInt64 } from "./proto-int64.js"; * files in topological order. */ export function createDescriptorSet( - input: FileDescriptorProto[] | FileDescriptorSet | Uint8Array + input: FileDescriptorProto[] | FileDescriptorSet | Uint8Array, ): DescriptorSet { const cart = { enums: new Map(), @@ -95,7 +95,7 @@ function newFile(proto: FileDescriptorProto, cart: Cart): DescFile { proto.syntax === undefined || proto.syntax === "proto3", `invalid FileDescriptorProto: unsupported syntax: ${ proto.syntax ?? "undefined" - }` + }`, ); const file: DescFile = { kind: "file", @@ -177,7 +177,7 @@ function addExtensions(desc: DescFile | DescMessage, cart: Cart): void { */ function addFields(message: DescMessage, cart: Cart): void { const allOneofs = message.proto.oneofDecl.map((proto) => - newOneof(proto, message) + newOneof(proto, message), ); const oneofsSeen = new Set(); for (const proto of message.proto.field) { @@ -210,7 +210,7 @@ function addEnum( proto: EnumDescriptorProto, file: DescFile, parent: DescMessage | undefined, - cart: Cart + cart: Cart, ): void { assert(proto.name, `invalid EnumDescriptorProto: missing name`); const desc: DescEnum = { @@ -224,7 +224,7 @@ function addEnum( values: [], sharedPrefix: findEnumSharedPrefix( proto.name, - proto.value.map((v) => v.name ?? "") + proto.value.map((v) => v.name ?? ""), ), toString(): string { return `enum ${this.typeName}`; @@ -248,7 +248,7 @@ function addEnum( assert(proto.name, `invalid EnumValueDescriptorProto: missing name`); assert( proto.number !== undefined, - `invalid EnumValueDescriptorProto: missing number` + `invalid EnumValueDescriptorProto: missing number`, ); desc.values.push({ kind: "enum_value", @@ -288,7 +288,7 @@ function addMessage( proto: DescriptorProto, file: DescFile, parent: DescMessage | undefined, - cart: Cart + cart: Cart, ): void { assert(proto.name, `invalid DescriptorProto: missing name`); const desc: DescMessage = { @@ -343,7 +343,7 @@ function addMessage( function addService( proto: ServiceDescriptorProto, file: DescFile, - cart: Cart + cart: Cart, ): void { assert(proto.name, `invalid ServiceDescriptorProto: missing name`); const desc: DescService = { @@ -378,13 +378,13 @@ function addService( function newMethod( proto: MethodDescriptorProto, parent: DescService, - cart: Cart + cart: Cart, ): DescMethod { assert(proto.name, `invalid MethodDescriptorProto: missing name`); assert(proto.inputType, `invalid MethodDescriptorProto: missing input_type`); assert( proto.outputType, - `invalid MethodDescriptorProto: missing output_type` + `invalid MethodDescriptorProto: missing output_type`, ); let methodKind: MethodKind; if (proto.clientStreaming === true && proto.serverStreaming === true) { @@ -413,11 +413,11 @@ function newMethod( const output = cart.messages.get(trimLeadingDot(proto.outputType)); assert( input, - `invalid MethodDescriptorProto: input_type ${proto.inputType} not found` + `invalid MethodDescriptorProto: input_type ${proto.inputType} not found`, ); assert( output, - `invalid MethodDescriptorProto: output_type ${proto.inputType} not found` + `invalid MethodDescriptorProto: output_type ${proto.inputType} not found`, ); const name = proto.name; return { @@ -478,7 +478,7 @@ function newField( file: DescFile, parent: DescMessage, oneof: DescOneof | undefined, - cart: Cart + cart: Cart, ): DescField { assert(proto.name, `invalid FieldDescriptorProto: missing name`); assert(proto.number, `invalid FieldDescriptorProto: missing number`); @@ -524,7 +524,7 @@ function newField( if (mapEntry !== undefined) { assert( repeated, - `invalid FieldDescriptorProto: expected map entry to be repeated` + `invalid FieldDescriptorProto: expected map entry to be repeated`, ); return { ...common, @@ -537,7 +537,7 @@ function newField( const message = cart.messages.get(trimLeadingDot(proto.typeName)); assert( message !== undefined, - `invalid FieldDescriptorProto: type_name ${proto.typeName} not found` + `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`, ); return { ...common, @@ -552,7 +552,7 @@ function newField( const e = cart.enums.get(trimLeadingDot(proto.typeName)); assert( e !== undefined, - `invalid FieldDescriptorProto: type_name ${proto.typeName} not found` + `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`, ); return { ...common, @@ -567,7 +567,7 @@ function newField( const scalar = fieldTypeToScalarType[proto.type]; assert( scalar, - `invalid FieldDescriptorProto: unknown type ${proto.type}` + `invalid FieldDescriptorProto: unknown type ${proto.type}`, ); return { ...common, @@ -588,7 +588,7 @@ function newExtension( proto: FieldDescriptorProto, file: DescFile, parent: DescMessage | undefined, - cart: Cart + cart: Cart, ): DescExtension { assert(proto.extendee, `invalid FieldDescriptorProto: missing extendee`); const field = newField( @@ -596,12 +596,12 @@ function newExtension( file, null as unknown as DescMessage, // to safe us many lines of duplicated code, we trick the type system undefined, - cart + cart, ); const extendee = cart.messages.get(trimLeadingDot(proto.extendee)); assert( extendee, - `invalid FieldDescriptorProto: extendee ${proto.extendee} not found` + `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`, ); return { ...field, @@ -652,7 +652,7 @@ function makeTypeName( | EnumDescriptorProto | FieldDescriptorProto, parent: DescMessage | DescService | undefined, - file: DescFile + file: DescFile, ): string { assert(proto.name, `invalid ${proto.getType().typeName}: missing name`); let typeName: string; @@ -674,22 +674,22 @@ function trimLeadingDot(typeName: string): string { } function getMapFieldTypes( - mapEntry: DescMessage + mapEntry: DescMessage, ): Pick { assert( mapEntry.proto.options?.mapEntry, - `invalid DescriptorProto: expected ${mapEntry.toString()} to be a map entry` + `invalid DescriptorProto: expected ${mapEntry.toString()} to be a map entry`, ); assert( mapEntry.fields.length === 2, `invalid DescriptorProto: map entry ${mapEntry.toString()} has ${ mapEntry.fields.length - } fields` + } fields`, ); const keyField = mapEntry.fields.find((f) => f.proto.number === 1); assert( keyField, - `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field` + `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field`, ); const mapKey = keyField.scalar; assert( @@ -699,12 +699,12 @@ function getMapFieldTypes( mapKey !== ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${ keyField.proto.type ?? -1 - }` + }`, ); const valueField = mapEntry.fields.find((f) => f.proto.number === 2); assert( valueField, - `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field` + `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`, ); switch (valueField.fieldKind) { case "scalar": @@ -733,7 +733,7 @@ function getMapFieldTypes( }; default: throw new Error( - "invalid DescriptorProto: unsupported map entry value field" + "invalid DescriptorProto: unsupported map entry value field", ); } } @@ -744,7 +744,7 @@ function getMapFieldTypes( */ function findOneof( proto: FieldDescriptorProto, - allOneofs: DescOneof[] + allOneofs: DescOneof[], ): DescOneof | undefined { const oneofIndex = proto.oneofIndex; if (oneofIndex === undefined) { @@ -757,7 +757,7 @@ function findOneof( oneof, `invalid FieldDescriptorProto: oneof #${oneofIndex} for field #${ proto.number ?? -1 - } not found` + } not found`, ); } return oneof; @@ -769,7 +769,7 @@ function findOneof( */ function isOptionalField( proto: FieldDescriptorProto, - syntax: "proto2" | "proto3" + syntax: "proto2" | "proto3", ): boolean { switch (syntax) { case "proto2": @@ -787,7 +787,7 @@ function isOptionalField( */ export function isPackedFieldByDefault( proto: FieldDescriptorProto, - syntax: "proto2" | "proto3" + syntax: "proto2" | "proto3", ): boolean { assert(proto.type, `invalid FieldDescriptorProto: missing type`); if (syntax === "proto3") { @@ -852,7 +852,7 @@ const fieldTypeToScalarType: Record< */ function findComments( sourceCodeInfo: SourceCodeInfo | undefined, - sourcePath: number[] + sourcePath: number[], ): DescComments { if (!sourceCodeInfo) { return { @@ -979,7 +979,7 @@ function declarationString(this: DescField | DescExtension): string { * Parses a text-encoded default value (proto2) of a scalar or enum field. */ function getDefaultValue( - this: DescField | DescExtension + this: DescField | DescExtension, ): number | boolean | string | bigint | Uint8Array | undefined { const d = this.proto.defaultValue; if (d === undefined) { @@ -999,7 +999,7 @@ function getDefaultValue( const u = unescapeBytesDefaultValue(d); if (u === false) { throw new Error( - `cannot parse ${this.toString()} default value: ${d}` + `cannot parse ${this.toString()} default value: ${d}`, ); } return u; @@ -1157,7 +1157,7 @@ function unescapeBytesDefaultValue(str: string): Uint8Array | false { chunk[4], chunk[5], chunk[6], - chunk[7] + chunk[7], ); break; } diff --git a/packages/protobuf/src/create-registry-from-desc.ts b/packages/protobuf/src/create-registry-from-desc.ts index 9549dd6fc..ffedb75d7 100644 --- a/packages/protobuf/src/create-registry-from-desc.ts +++ b/packages/protobuf/src/create-registry-from-desc.ts @@ -90,7 +90,7 @@ const wkEnums = [getEnumType(NullValue)]; */ export function createRegistryFromDescriptors( input: DescriptorSet | FileDescriptorSet | Uint8Array, - replaceWkt = true + replaceWkt = true, ): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry { const set: DescriptorSet = input instanceof Uint8Array || input instanceof FileDescriptorSet @@ -128,9 +128,9 @@ export function createRegistryFromDescriptors( no: u.number, name: u.name, localName: localName(u), - }) + }), ), - {} + {}, ); enums[typeName] = type; return type; @@ -181,13 +181,13 @@ export function createRegistryFromDescriptors( I, `message "${ method.input.typeName - }" for ${method.toString()} not found` + }" for ${method.toString()} not found`, ); assert( O, `output message "${ method.output.typeName - }" for ${method.toString()} not found` + }" for ${method.toString()} not found`, ); methods[localName(method)] = { name: method.name, @@ -230,7 +230,7 @@ function makeFieldInfo(desc: DescField, resolver: Resolver): PartialFieldInfo { function makeMapFieldInfo( field: DescField & { fieldKind: "map" }, - resolver: Resolver + resolver: Resolver, ): PartialFieldInfo { const base = { kind: "map", @@ -245,7 +245,7 @@ function makeMapFieldInfo( messageType, `message "${ field.mapValue.message.typeName - }" for ${field.toString()} not found` + }" for ${field.toString()} not found`, ); return { ...base, @@ -259,7 +259,9 @@ function makeMapFieldInfo( const enumType = resolver.findEnum(field.mapValue.enum.typeName); assert( enumType, - `enum "${field.mapValue.enum.typeName}" for ${field.toString()} not found` + `enum "${ + field.mapValue.enum.typeName + }" for ${field.toString()} not found`, ); return { ...base, @@ -279,7 +281,7 @@ function makeMapFieldInfo( } function makeScalarFieldInfo( - field: DescField & { fieldKind: "scalar" } + field: DescField & { fieldKind: "scalar" }, ): PartialFieldInfo { const base = { kind: "scalar", @@ -314,12 +316,12 @@ function makeScalarFieldInfo( function makeMessageFieldInfo( field: DescField & { fieldKind: "message" }, - resolver: Resolver + resolver: Resolver, ): PartialFieldInfo { const messageType = resolver.findMessage(field.message.typeName); assert( messageType, - `message "${field.message.typeName}" for ${field.toString()} not found` + `message "${field.message.typeName}" for ${field.toString()} not found`, ); const base = { kind: "message", @@ -353,12 +355,12 @@ function makeMessageFieldInfo( function makeEnumFieldInfo( field: DescField & { fieldKind: "enum" }, - resolver: Resolver + resolver: Resolver, ): PartialFieldInfo { const enumType = resolver.findEnum(field.enum.typeName); assert( enumType, - `enum "${field.enum.typeName}" for ${field.toString()} not found` + `enum "${field.enum.typeName}" for ${field.toString()} not found`, ); const base = { kind: "enum", diff --git a/packages/protobuf/src/json-format.ts b/packages/protobuf/src/json-format.ts index 532af20a1..073c17183 100644 --- a/packages/protobuf/src/json-format.ts +++ b/packages/protobuf/src/json-format.ts @@ -29,14 +29,14 @@ export interface JsonFormat { * Provide options for parsing JSON data. */ makeReadOptions( - options?: Partial + options?: Partial, ): Readonly; /** * Provide options for serializing to JSON. */ makeWriteOptions( - options?: Partial + options?: Partial, ): Readonly; /** @@ -46,7 +46,7 @@ export interface JsonFormat { type: MessageType, jsonValue: JsonValue, options: JsonReadOptions, - message?: T + message?: T, ): T; /** @@ -67,7 +67,7 @@ export interface JsonFormat { writeScalar( type: ScalarType, value: any, - emitDefaultValues: boolean + emitDefaultValues: boolean, ): JsonValue | undefined; /** diff --git a/packages/protobuf/src/message-type.ts b/packages/protobuf/src/message-type.ts index 9fed6ff3e..290fc62de 100644 --- a/packages/protobuf/src/message-type.ts +++ b/packages/protobuf/src/message-type.ts @@ -80,6 +80,6 @@ export interface MessageType = AnyMessage> { */ equals( a: T | PlainMessage | undefined | null, - b: T | PlainMessage | undefined | null + b: T | PlainMessage | undefined | null, ): boolean; } diff --git a/packages/protobuf/src/message.ts b/packages/protobuf/src/message.ts index 6c33fa5d1..683a833d4 100644 --- a/packages/protobuf/src/message.ts +++ b/packages/protobuf/src/message.ts @@ -45,7 +45,7 @@ export class Message = AnyMessage> { return this.getType().runtime.util.equals( this.getType(), this as unknown as T, - other + other, ); } @@ -95,7 +95,7 @@ export class Message = AnyMessage> { throw new Error( `cannot decode ${this.getType().typeName} from JSON: ${ e instanceof Error ? e.message : String(e) - }` + }`, ); } return this.fromJson(json, options); diff --git a/packages/protobuf/src/private/binary-format-common.ts b/packages/protobuf/src/private/binary-format-common.ts index ac21bbadf..c8d6e9095 100644 --- a/packages/protobuf/src/private/binary-format-common.ts +++ b/packages/protobuf/src/private/binary-format-common.ts @@ -44,13 +44,13 @@ const writeDefaults: Readonly = { }; function makeReadOptions( - options?: Partial + options?: Partial, ): Readonly { return options ? { ...readDefaults, ...options } : readDefaults; } function makeWriteOptions( - options?: Partial + options?: Partial, ): Readonly { return options ? { ...writeDefaults, ...options } : writeDefaults; } @@ -60,7 +60,7 @@ export function makeBinaryFormatCommon(): Omit { makeReadOptions, makeWriteOptions, listUnknownFields( - message: Message + message: Message, ): ReadonlyArray<{ no: number; wireType: WireType; data: Uint8Array }> { return (message as any)[unknownFieldsSymbol] ?? []; }, @@ -80,7 +80,7 @@ export function makeBinaryFormatCommon(): Omit { message: Message, no: number, wireType: WireType, - data: Uint8Array + data: Uint8Array, ): void { const m = message as any; if (!Array.isArray(m[unknownFieldsSymbol])) { @@ -92,7 +92,7 @@ export function makeBinaryFormatCommon(): Omit { message: T, reader: IBinaryReader, length: number, - options: BinaryReadOptions + options: BinaryReadOptions, ): void { const type = message.getType(); const end = length === undefined ? reader.len : reader.pos + length; @@ -145,7 +145,7 @@ export function makeBinaryFormatCommon(): Omit { if (repeated) { // safe to assume presence of array, oneof cannot contain repeated values (target[localName] as any[]).push( - readMessageField(reader, new messageType(), options) + readMessageField(reader, new messageType(), options), ); } else { if (target[localName] instanceof Message) { @@ -154,7 +154,7 @@ export function makeBinaryFormatCommon(): Omit { target[localName] = readMessageField( reader, new messageType(), - options + options, ); if ( messageType.fieldWrapper && @@ -162,7 +162,7 @@ export function makeBinaryFormatCommon(): Omit { !field.repeated ) { target[localName] = messageType.fieldWrapper.unwrapField( - target[localName] + target[localName], ); } } @@ -184,7 +184,7 @@ export function makeBinaryFormatCommon(): Omit { function readMessageField( reader: IBinaryReader, message: T, - options: BinaryReadOptions + options: BinaryReadOptions, ): T { const format = message.getType().runtime.bin; format.readMessage(message, reader, reader.uint32(), options); @@ -195,7 +195,7 @@ function readMessageField( function readMapEntry( field: FieldInfo & { kind: "map" }, reader: IBinaryReader, - options: BinaryReadOptions + options: BinaryReadOptions, ): [string | number, any] { const length = reader.uint32(), end = reader.pos + length; @@ -288,7 +288,7 @@ export function writeMapEntry( options: BinaryWriteOptions, field: FieldInfo & { kind: "map" }, key: any, - value: any + value: any, ): void { writer.tag(field.no, WireType.LengthDelimited); writer.fork(); @@ -335,7 +335,7 @@ export function writeMessageField( options: BinaryWriteOptions, type: MessageType, fieldNo: number, - value: any + value: any, ): void { if (value !== undefined) { const message = wrapField(type, value); @@ -350,7 +350,7 @@ export function writeScalar( type: ScalarType, fieldNo: number, value: any, - emitIntrinsicDefault: boolean + emitIntrinsicDefault: boolean, ): void { let [wireType, method, isIntrinsicDefault] = scalarTypeInfo(type, value); if (!isIntrinsicDefault || emitIntrinsicDefault) { @@ -362,7 +362,7 @@ export function writePacked( writer: IBinaryWriter, type: ScalarType, fieldNo: number, - value: any[] + value: any[], ): void { if (!value.length) { return; diff --git a/packages/protobuf/src/private/binary-format-proto2.ts b/packages/protobuf/src/private/binary-format-proto2.ts index 17e7cd2d0..0f6971928 100644 --- a/packages/protobuf/src/private/binary-format-proto2.ts +++ b/packages/protobuf/src/private/binary-format-proto2.ts @@ -33,7 +33,7 @@ export function makeBinaryFormatProto2(): BinaryFormat { writeMessage( message: Message, writer: IBinaryWriter, - options: BinaryWriteOptions + options: BinaryWriteOptions, ): IBinaryWriter { const type = message.getType(); let field: FieldInfo | undefined; @@ -54,7 +54,7 @@ export function makeBinaryFormatProto2(): BinaryFormat { // field is missing a value. if (value === undefined && !field.oneof && !field.opt) { throw new Error( - `cannot encode field ${type.typeName}.${field.name} to binary: required field not set` + `cannot encode field ${type.typeName}.${field.name} to binary: required field not set`, ); } } diff --git a/packages/protobuf/src/private/binary-format-proto3.ts b/packages/protobuf/src/private/binary-format-proto3.ts index c2288fb3f..2f0adb512 100644 --- a/packages/protobuf/src/private/binary-format-proto3.ts +++ b/packages/protobuf/src/private/binary-format-proto3.ts @@ -32,7 +32,7 @@ export function makeBinaryFormatProto3(): BinaryFormat { writeMessage( message: Message, writer: IBinaryWriter, - options: BinaryWriteOptions + options: BinaryWriteOptions, ): IBinaryWriter { const type = message.getType(); for (const field of type.fields.byNumber()) { @@ -69,7 +69,7 @@ export function makeBinaryFormatProto3(): BinaryFormat { scalarType, field.no, value, - !!field.oneof || field.opt + !!field.oneof || field.opt, ); } } diff --git a/packages/protobuf/src/private/enum.ts b/packages/protobuf/src/private/enum.ts index a08e07217..7b22a7ba7 100644 --- a/packages/protobuf/src/private/enum.ts +++ b/packages/protobuf/src/private/enum.ts @@ -48,7 +48,7 @@ export function setEnumType( opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): void { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any (enumObject as any)[enumTypeSymbol] = makeEnumType( @@ -58,7 +58,7 @@ export function setEnumType( name: v.name, localName: enumObject[v.no], })), - opt + opt, ); } @@ -72,7 +72,7 @@ export function makeEnumType( _opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): EnumType { const names = Object.create(null) as Record; const numbers = Object.create(null) as Record; @@ -109,7 +109,7 @@ export function makeEnum( opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): EnumObject { const enumObject: EnumObject = {}; for (const value of values) { @@ -122,7 +122,7 @@ export function makeEnum( } function normalizeEnumValue( - value: EnumValueInfo | Omit + value: EnumValueInfo | Omit, ): EnumValueInfo { if ("localName" in value) { return value; diff --git a/packages/protobuf/src/private/field-list.ts b/packages/protobuf/src/private/field-list.ts index d640a4559..28e9828ff 100644 --- a/packages/protobuf/src/private/field-list.ts +++ b/packages/protobuf/src/private/field-list.ts @@ -32,7 +32,7 @@ export class InternalFieldList implements FieldList { constructor( fields: FieldListSource, - normalizer: (p: FieldListSource) => FieldInfo[] + normalizer: (p: FieldListSource) => FieldInfo[], ) { this._fields = fields; this._normalizer = normalizer; diff --git a/packages/protobuf/src/private/field-wrapper.ts b/packages/protobuf/src/private/field-wrapper.ts index d498821e5..8b4612680 100644 --- a/packages/protobuf/src/private/field-wrapper.ts +++ b/packages/protobuf/src/private/field-wrapper.ts @@ -38,7 +38,7 @@ export interface FieldWrapper = any, U = any> { */ export function wrapField>( type: MessageType, - value: any + value: any, ): T { if (value instanceof Message || !type.fieldWrapper) { return value as T; @@ -51,7 +51,7 @@ export function wrapField>( * the primitive type it wraps. */ export function getUnwrappedFieldType( - field: DescField + field: DescField, ): ScalarType | undefined { if (field.fieldKind !== "message") { return undefined; diff --git a/packages/protobuf/src/private/json-format-common.ts b/packages/protobuf/src/private/json-format-common.ts index a1f0d5b0d..e64bde44e 100644 --- a/packages/protobuf/src/private/json-format-common.ts +++ b/packages/protobuf/src/private/json-format-common.ts @@ -46,13 +46,13 @@ const jsonWriteDefaults: Readonly = { }; function makeReadOptions( - options?: Partial + options?: Partial, ): Readonly { return options ? { ...jsonReadDefaults, ...options } : jsonReadDefaults; } function makeWriteOptions( - options?: Partial + options?: Partial, ): Readonly { return options ? { ...jsonWriteDefaults, ...options } : jsonWriteDefaults; } @@ -60,14 +60,14 @@ function makeWriteOptions( type JsonFormatWriteFieldFn = ( field: FieldInfo, value: any, - options: JsonWriteOptions + options: JsonWriteOptions, ) => JsonValue | undefined; export function makeJsonFormatCommon( makeWriteField: ( writeEnumFn: typeof writeEnum, - writeScalarFn: typeof writeScalar - ) => JsonFormatWriteFieldFn + writeScalarFn: typeof writeScalar, + ) => JsonFormatWriteFieldFn, ): JsonFormat { const writeField = makeWriteField(writeEnum, writeScalar); return { @@ -77,13 +77,13 @@ export function makeJsonFormatCommon( type: MessageType, json: JsonValue, options: JsonReadOptions, - message?: T + message?: T, ): T { if (json == null || Array.isArray(json) || typeof json != "object") { throw new Error( `cannot decode message ${type.typeName} from JSON: ${this.debug( - json - )}` + json, + )}`, ); } message = message ?? new type(); @@ -93,7 +93,7 @@ export function makeJsonFormatCommon( if (!field) { if (!options.ignoreUnknownFields) { throw new Error( - `cannot decode message ${type.typeName} from JSON: key "${jsonKey}" is unknown` + `cannot decode message ${type.typeName} from JSON: key "${jsonKey}" is unknown`, ); } continue; @@ -108,7 +108,7 @@ export function makeJsonFormatCommon( const seen = oneofSeen[field.oneof.localName]; if (seen) { throw new Error( - `cannot decode message ${type.typeName} from JSON: multiple keys for oneof "${field.oneof.name}" present: "${seen}", "${jsonKey}"` + `cannot decode message ${type.typeName} from JSON: multiple keys for oneof "${field.oneof.name}" present: "${seen}", "${jsonKey}"`, ); } oneofSeen[field.oneof.localName] = jsonKey; @@ -123,7 +123,7 @@ export function makeJsonFormatCommon( throw new Error( `cannot decode field ${type.typeName}.${ field.name - } from JSON: ${this.debug(jsonValue)}` + } from JSON: ${this.debug(jsonValue)}`, ); } const targetArray = target[localName] as unknown[]; @@ -132,7 +132,7 @@ export function makeJsonFormatCommon( throw new Error( `cannot decode field ${type.typeName}.${ field.name - } from JSON: ${this.debug(jsonItem)}` + } from JSON: ${this.debug(jsonItem)}`, ); } let val; @@ -169,14 +169,14 @@ export function makeJsonFormatCommon( throw new Error( `cannot decode field ${type.typeName}.${ field.name - } from JSON: ${this.debug(jsonValue)}` + } from JSON: ${this.debug(jsonValue)}`, ); } const targetMap = target[localName] as { [k: string]: unknown }; for (const [jsonMapKey, jsonMapValue] of Object.entries(jsonValue)) { if (jsonMapValue === null) { throw new Error( - `cannot decode field ${type.typeName}.${field.name} from JSON: map value null` + `cannot decode field ${type.typeName}.${field.name} from JSON: map value null`, ); } let val; @@ -188,7 +188,7 @@ export function makeJsonFormatCommon( val = readEnum( field.V.T, jsonMapValue, - options.ignoreUnknownFields + options.ignoreUnknownFields, ); if (val === undefined) continue; break; @@ -216,7 +216,7 @@ export function makeJsonFormatCommon( : jsonMapKey == "false" ? false : jsonMapKey - : jsonMapKey + : jsonMapKey, ).toString() ] = val; } catch (e) { @@ -239,7 +239,7 @@ export function makeJsonFormatCommon( ) { if (field.oneof) { throw new Error( - `cannot decode field ${type.typeName}.${field.name} from JSON: null is invalid for oneof field "${jsonKey}"` + `cannot decode field ${type.typeName}.${field.name} from JSON: null is invalid for oneof field "${jsonKey}"`, ); } continue; @@ -250,7 +250,7 @@ export function makeJsonFormatCommon( target[localName] = messageType.fromJson(jsonValue, options); if (messageType.fieldWrapper && !field.oneof) { target[localName] = messageType.fieldWrapper.unwrapField( - target[localName] + target[localName], ); } } @@ -259,7 +259,7 @@ export function makeJsonFormatCommon( const enumValue = readEnum( field.T, jsonValue, - options.ignoreUnknownFields + options.ignoreUnknownFields, ); if (enumValue !== undefined) { target[localName] = enumValue; @@ -305,7 +305,7 @@ export function makeJsonFormatCommon( jsonValue = writeField( field, (message as AnyMessage)[field.localName], - options + options, ); } if (jsonValue !== undefined) { @@ -443,7 +443,7 @@ function readScalar(type: ScalarType, json: JsonValue): any { function readEnum( type: EnumType, json: JsonValue, - ignoreUnknownFields: boolean + ignoreUnknownFields: boolean, ): number | undefined { if (json === null) { // proto3 requires 0 to be default value for all enums @@ -464,7 +464,7 @@ function readEnum( break; } throw new Error( - `cannot decode enum ${type.typeName} from JSON: ${debugJsonValue(json)}` + `cannot decode enum ${type.typeName} from JSON: ${debugJsonValue(json)}`, ); } @@ -472,7 +472,7 @@ function writeEnum( type: EnumType, value: number | undefined, emitIntrinsicDefault: boolean, - enumAsInteger: boolean + enumAsInteger: boolean, ): JsonValue | undefined { if (value === undefined) { return value; @@ -494,7 +494,7 @@ function writeEnum( function writeScalar( type: ScalarType, value: any, - emitIntrinsicDefault: boolean + emitIntrinsicDefault: boolean, ): JsonValue | undefined { if (value === undefined) { return undefined; @@ -539,7 +539,7 @@ function writeScalar( assert( typeof value == "bigint" || typeof value == "string" || - typeof value == "number" + typeof value == "number", ); // We use implicit conversion with `value != 0` to catch both 0n and "0" // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/packages/protobuf/src/private/json-format-proto2.ts b/packages/protobuf/src/private/json-format-proto2.ts index 84b1cbb47..2e029dba4 100644 --- a/packages/protobuf/src/private/json-format-proto2.ts +++ b/packages/protobuf/src/private/json-format-proto2.ts @@ -31,7 +31,7 @@ export function makeJsonFormatProto2(): JsonFormat { return function writeField( field: FieldInfo, value: any, - options: JsonWriteOptions + options: JsonWriteOptions, ): JsonValue | undefined { if (field.kind == "map") { const jsonObj: JsonObject = {}; @@ -47,7 +47,7 @@ export function makeJsonFormatProto2(): JsonFormat { for (const [entryKey, entryValue] of Object.entries(value)) { // JSON standard allows only (double quoted) string as property key jsonObj[entryKey.toString()] = (entryValue as Message).toJson( - options + options, ); } break; @@ -59,7 +59,7 @@ export function makeJsonFormatProto2(): JsonFormat { enumType, entryValue as number, true, - options.enumAsInteger + options.enumAsInteger, ); assert(val !== undefined); jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key @@ -84,8 +84,8 @@ export function makeJsonFormatProto2(): JsonFormat { field.T, value[i], true, - options.enumAsInteger - ) as JsonValue + options.enumAsInteger, + ) as JsonValue, ); } break; diff --git a/packages/protobuf/src/private/json-format-proto3.ts b/packages/protobuf/src/private/json-format-proto3.ts index 329c57abc..aa23b5a2a 100644 --- a/packages/protobuf/src/private/json-format-proto3.ts +++ b/packages/protobuf/src/private/json-format-proto3.ts @@ -31,7 +31,7 @@ export function makeJsonFormatProto3(): JsonFormat { return function writeField( field: FieldInfo, value: any, - options: JsonWriteOptions + options: JsonWriteOptions, ): JsonValue | undefined { if (field.kind == "map") { const jsonObj: JsonObject = {}; @@ -47,7 +47,7 @@ export function makeJsonFormatProto3(): JsonFormat { for (const [entryKey, entryValue] of Object.entries(value)) { // JSON standard allows only (double quoted) string as property key jsonObj[entryKey.toString()] = (entryValue as Message).toJson( - options + options, ); } break; @@ -59,7 +59,7 @@ export function makeJsonFormatProto3(): JsonFormat { enumType, entryValue as number, true, - options.enumAsInteger + options.enumAsInteger, ); assert(val !== undefined); jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key @@ -84,8 +84,8 @@ export function makeJsonFormatProto3(): JsonFormat { field.T, value[i], true, - options.enumAsInteger - ) as JsonValue + options.enumAsInteger, + ) as JsonValue, ); } break; @@ -104,14 +104,14 @@ export function makeJsonFormatProto3(): JsonFormat { return writeScalar( field.T, value, - !!field.oneof || field.opt || options.emitDefaultValues + !!field.oneof || field.opt || options.emitDefaultValues, ); case "enum": return writeEnum( field.T, value, !!field.oneof || field.opt || options.emitDefaultValues, - options.enumAsInteger + options.enumAsInteger, ); case "message": return value !== undefined diff --git a/packages/protobuf/src/private/message-type.ts b/packages/protobuf/src/private/message-type.ts index 1aba20dcc..d6e7826c4 100644 --- a/packages/protobuf/src/private/message-type.ts +++ b/packages/protobuf/src/private/message-type.ts @@ -38,7 +38,7 @@ export function makeMessageType = AnyMessage>( localName?: string; // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): MessageType { const localName = opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1); @@ -64,7 +64,7 @@ export function makeMessageType = AnyMessage>( }, equals( a: T | PlainMessage | undefined, - b: T | PlainMessage | undefined + b: T | PlainMessage | undefined, ): boolean { return runtime.util.equals(type, a, b); }, diff --git a/packages/protobuf/src/private/names.ts b/packages/protobuf/src/private/names.ts index eee341c62..4c5253745 100644 --- a/packages/protobuf/src/private/names.ts +++ b/packages/protobuf/src/private/names.ts @@ -37,7 +37,7 @@ export function localName( | DescOneof | DescField | DescService - | DescMethod + | DescMethod, ): string { switch (desc.kind) { case "field": @@ -106,7 +106,7 @@ export const fieldJsonName = protoCamelCase; */ export function findEnumSharedPrefix( enumName: string, - valueNames: string[] + valueNames: string[], ): string | undefined { const prefix = camelToSnakeCase(enumName) + "_"; for (const name of valueNames) { diff --git a/packages/protobuf/src/private/proto-runtime.ts b/packages/protobuf/src/private/proto-runtime.ts index 9309dc425..1d9dc3aa0 100644 --- a/packages/protobuf/src/private/proto-runtime.ts +++ b/packages/protobuf/src/private/proto-runtime.ts @@ -43,7 +43,7 @@ export interface ProtoRuntime { localName?: string; // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): MessageType; /** @@ -61,7 +61,7 @@ export interface ProtoRuntime { opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): EnumObject; /** @@ -75,7 +75,7 @@ export interface ProtoRuntime { opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): EnumType; /** @@ -90,7 +90,7 @@ export function makeProtoRuntime( syntax: string, json: JsonFormat, bin: BinaryFormat, - util: Util + util: Util, ): ProtoRuntime { return { syntax, @@ -103,7 +103,7 @@ export function makeProtoRuntime( opt?: { localName?: string; options?: { readonly [extensionName: string]: JsonValue }; - } + }, ) { return makeMessageType(this, typeName, fields, opt); }, diff --git a/packages/protobuf/src/private/reify-wkt.ts b/packages/protobuf/src/private/reify-wkt.ts index 1fead0a7a..9b3c8c1e7 100644 --- a/packages/protobuf/src/private/reify-wkt.ts +++ b/packages/protobuf/src/private/reify-wkt.ts @@ -108,13 +108,13 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { (f) => f.number == 1 && f.fieldKind == "scalar" && - f.scalar === ScalarType.STRING + f.scalar === ScalarType.STRING, ); const value = message.fields.find( (f) => f.number == 2 && f.fieldKind == "scalar" && - f.scalar === ScalarType.BYTES + f.scalar === ScalarType.BYTES, ); if (typeUrl && value) { return { @@ -130,13 +130,13 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { (f) => f.number == 1 && f.fieldKind == "scalar" && - f.scalar === ScalarType.INT64 + f.scalar === ScalarType.INT64, ); const nanos = message.fields.find( (f) => f.number == 2 && f.fieldKind == "scalar" && - f.scalar === ScalarType.INT32 + f.scalar === ScalarType.INT32, ); if (seconds && nanos) { return { @@ -152,13 +152,13 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { (f) => f.number == 1 && f.fieldKind == "scalar" && - f.scalar === ScalarType.INT64 + f.scalar === ScalarType.INT64, ); const nanos = message.fields.find( (f) => f.number == 2 && f.fieldKind == "scalar" && - f.scalar === ScalarType.INT32 + f.scalar === ScalarType.INT32, ); if (seconds && nanos) { return { @@ -183,7 +183,7 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { case "google.protobuf.Value": { const kind = message.oneofs.find((o) => o.name === "kind"); const nullValue = message.fields.find( - (f) => f.number == 1 && f.oneof === kind + (f) => f.number == 1 && f.oneof === kind, ); if ( nullValue?.fieldKind !== "enum" || @@ -196,24 +196,24 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { f.number == 2 && f.fieldKind == "scalar" && f.scalar === ScalarType.DOUBLE && - f.oneof === kind + f.oneof === kind, ); const stringValue = message.fields.find( (f) => f.number == 3 && f.fieldKind == "scalar" && f.scalar === ScalarType.STRING && - f.oneof === kind + f.oneof === kind, ); const boolValue = message.fields.find( (f) => f.number == 4 && f.fieldKind == "scalar" && f.scalar === ScalarType.BOOL && - f.oneof === kind + f.oneof === kind, ); const structValue = message.fields.find( - (f) => f.number == 5 && f.oneof === kind + (f) => f.number == 5 && f.oneof === kind, ); if ( structValue?.fieldKind !== "message" || @@ -222,7 +222,7 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { return undefined; } const listValue = message.fields.find( - (f) => f.number == 6 && f.oneof === kind + (f) => f.number == 6 && f.oneof === kind, ); if ( listValue?.fieldKind !== "message" || @@ -260,7 +260,7 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { f.number == 1 && f.fieldKind == "scalar" && f.scalar === ScalarType.STRING && - f.repeated + f.repeated, ); if (paths) { return { typeName: message.typeName, paths }; @@ -277,7 +277,7 @@ export function reifyWkt(message: DescMessage): DescWkt | undefined { case "google.protobuf.StringValue": case "google.protobuf.BytesValue": { const value = message.fields.find( - (f) => f.number == 1 && f.name == "value" + (f) => f.number == 1 && f.name == "value", ); if (!value) { break; diff --git a/packages/protobuf/src/private/scalars.ts b/packages/protobuf/src/private/scalars.ts index ea0d89d3f..1e84e80b5 100644 --- a/packages/protobuf/src/private/scalars.ts +++ b/packages/protobuf/src/private/scalars.ts @@ -25,7 +25,7 @@ import { protoInt64 } from "../proto-int64.js"; export function scalarEquals( type: ScalarType, a: string | boolean | number | bigint | Uint8Array | undefined, - b: string | boolean | number | bigint | Uint8Array | undefined + b: string | boolean | number | bigint | Uint8Array | undefined, ): boolean { if (a === b) { // This correctly matches equal values except BYTES and (possibly) 64-bit integers. @@ -102,11 +102,11 @@ export function scalarDefaultValue(type: ScalarType): any { */ export function scalarTypeInfo( type: ScalarType, - value?: any + value?: any, ): [ WireType, Exclude, - boolean + boolean, ] { const isUndefined = value === undefined; let wireType = WireType.Varint; diff --git a/packages/protobuf/src/private/util-common.ts b/packages/protobuf/src/private/util-common.ts index 0268a4177..210375c7c 100644 --- a/packages/protobuf/src/private/util-common.ts +++ b/packages/protobuf/src/private/util-common.ts @@ -27,7 +27,7 @@ export function makeUtilCommon(): Omit { setEnumType, initPartial>( source: PartialMessage | undefined, - target: T + target: T, ): void { if (source === undefined) { return; @@ -103,7 +103,7 @@ export function makeUtilCommon(): Omit { const mt = member.T; if (member.repeated) { t[localName] = (s[localName] as any[]).map((val) => - val instanceof mt ? val : new mt(val) + val instanceof mt ? val : new mt(val), ); } else if (s[localName] !== undefined) { const val = s[localName]; @@ -127,7 +127,7 @@ export function makeUtilCommon(): Omit { equals>( type: MessageType, a: T | PlainMessage | undefined | null, - b: T | PlainMessage | undefined | null + b: T | PlainMessage | undefined | null, ): boolean { if (a === b) { return true; @@ -148,11 +148,11 @@ export function makeUtilCommon(): Omit { return (va as any[]).every((a, i) => m.T.equals(a, vb[i])); case "scalar": return (va as any[]).every((a: any, i: number) => - scalarEquals(m.T, a, vb[i]) + scalarEquals(m.T, a, vb[i]), ); case "enum": return (va as any[]).every((a: any, i: number) => - scalarEquals(ScalarType.INT32, a, vb[i]) + scalarEquals(ScalarType.INT32, a, vb[i]), ); } throw new Error(`repeated cannot contain ${m.kind}`); @@ -190,12 +190,12 @@ export function makeUtilCommon(): Omit { return keys.every((k) => messageType.equals(va[k], vb[k])); case "enum": return keys.every((k) => - scalarEquals(ScalarType.INT32, va[k], vb[k]) + scalarEquals(ScalarType.INT32, va[k], vb[k]), ); case "scalar": const scalarType = m.V.T; return keys.every((k) => - scalarEquals(scalarType, va[k], vb[k]) + scalarEquals(scalarType, va[k], vb[k]), ); } break; diff --git a/packages/protobuf/src/private/util.ts b/packages/protobuf/src/private/util.ts index 7200f3ae5..f4241247a 100644 --- a/packages/protobuf/src/private/util.ts +++ b/packages/protobuf/src/private/util.ts @@ -40,7 +40,7 @@ export interface Util { opt?: { // We do not surface options at this time // options?: { readonly [extensionName: string]: JsonValue }; - } + }, ): void; /** @@ -53,7 +53,7 @@ export interface Util { */ initPartial>( source: PartialMessage | undefined, - target: T + target: T, ): void; /** @@ -63,7 +63,7 @@ export interface Util { equals>( type: MessageType, a: T | PlainMessage | undefined | null, - b: T | PlainMessage | undefined | null + b: T | PlainMessage | undefined | null, ): boolean; /** diff --git a/packages/protobuf/src/proto-delimited.ts b/packages/protobuf/src/proto-delimited.ts index 97d993598..b874292c5 100644 --- a/packages/protobuf/src/proto-delimited.ts +++ b/packages/protobuf/src/proto-delimited.ts @@ -43,7 +43,7 @@ export const protoDelimited = { dec>( type: MessageType, bytes: Uint8Array, - options?: BinaryReadOptions + options?: BinaryReadOptions, ): T { const opt = makeBinaryFormatCommon().makeReadOptions(options); return type.fromBinary(opt.readerFactory(bytes).bytes(), opt); @@ -54,7 +54,7 @@ export const protoDelimited = { */ async *decStream>( type: MessageType, - iterable: AsyncIterable + iterable: AsyncIterable, ) { // append chunk to buffer, returning updated buffer function append(buffer: Uint8Array, chunk: Uint8Array): Uint8Array { @@ -104,7 +104,7 @@ export const protoDelimited = { * from a stream. */ peekSize( - data: Uint8Array + data: Uint8Array, ): | { readonly eof: false; readonly size: number; readonly offset: number } | { readonly eof: true; readonly size: null; readonly offset: null } { diff --git a/packages/protobuf/src/proto2.ts b/packages/protobuf/src/proto2.ts index 148695318..54208d358 100644 --- a/packages/protobuf/src/proto2.ts +++ b/packages/protobuf/src/proto2.ts @@ -64,7 +64,7 @@ export const proto2 = makeProtoRuntime( } } }, - } + }, ); /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */ diff --git a/packages/protobuf/src/proto3.ts b/packages/protobuf/src/proto3.ts index f47f1540b..ca8997609 100644 --- a/packages/protobuf/src/proto3.ts +++ b/packages/protobuf/src/proto3.ts @@ -68,7 +68,7 @@ export const proto3 = makeProtoRuntime( } } }, - } + }, ); /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */ diff --git a/packages/protobuf/src/service-type.ts b/packages/protobuf/src/service-type.ts index 213a74596..d2bfe3042 100644 --- a/packages/protobuf/src/service-type.ts +++ b/packages/protobuf/src/service-type.ts @@ -49,7 +49,7 @@ export interface ServiceType { */ export type MethodInfo< I extends Message = AnyMessage, - O extends Message = AnyMessage + O extends Message = AnyMessage, > = | MethodInfoUnary | MethodInfoServerStreaming @@ -69,7 +69,7 @@ export interface MethodInfoUnary, O extends Message> */ export interface MethodInfoServerStreaming< I extends Message, - O extends Message + O extends Message, > extends miShared { readonly kind: MethodKind.ServerStreaming; } @@ -79,7 +79,7 @@ export interface MethodInfoServerStreaming< */ export interface MethodInfoClientStreaming< I extends Message, - O extends Message + O extends Message, > extends miShared { readonly kind: MethodKind.ClientStreaming; } @@ -89,14 +89,14 @@ export interface MethodInfoClientStreaming< */ export interface MethodInfoBiDiStreaming< I extends Message, - O extends Message + O extends Message, > extends miShared { readonly kind: MethodKind.BiDiStreaming; } interface miShared< I extends Message = AnyMessage, - O extends Message = AnyMessage + O extends Message = AnyMessage, > { readonly name: string; readonly I: MessageType; diff --git a/packages/protobuf/src/to-plain-message.ts b/packages/protobuf/src/to-plain-message.ts index c12750654..8795f42b2 100644 --- a/packages/protobuf/src/to-plain-message.ts +++ b/packages/protobuf/src/to-plain-message.ts @@ -24,7 +24,7 @@ import type { AnyMessage, PlainMessage } from "./message.js"; * same logic to all nested message fields as well. */ export function toPlainMessage>( - message: T + message: T, ): PlainMessage { const type = message.getType(); const target = {} as AnyMessage; diff --git a/packages/protoplugin-example/src/index.ts b/packages/protoplugin-example/src/index.ts index 79993384a..1deabc19c 100644 --- a/packages/protoplugin-example/src/index.ts +++ b/packages/protoplugin-example/src/index.ts @@ -21,7 +21,7 @@ const client = new ElizaServiceClient("https://demo.connect.build"); // Query for the common elements and cache them. const containerEl = document.getElementById( - "conversation-container" + "conversation-container", ) as HTMLDivElement; const inputEl = document.getElementById("user-input") as HTMLInputElement; diff --git a/packages/protoplugin-test/src/create-es-plugin.test.ts b/packages/protoplugin-test/src/create-es-plugin.test.ts index ac8247f83..e988ba271 100644 --- a/packages/protoplugin-test/src/create-es-plugin.test.ts +++ b/packages/protoplugin-test/src/create-es-plugin.test.ts @@ -69,7 +69,7 @@ function generateDts(schema: Schema) { function verifyOutFiles( plugin: Plugin, fixture: OutFixture, - req?: CodeGeneratorRequest + req?: CodeGeneratorRequest, ) { const targets = Object.keys(fixture); req = @@ -84,7 +84,7 @@ function verifyOutFiles( // given fixture. const totalExpectedFiles = Object.values(fixture).reduce( (prev, curr) => prev + curr.length, - 0 + 0, ); expect(resp.file.length).toEqual(totalExpectedFiles); @@ -239,7 +239,7 @@ describe("only request one file to generate with variant target outs", function js: ["proto/address_book_proto.js"], dts: ["proto/address_book_proto.dts"], }, - req + req, ); }); test("all targets with no dts generator", () => { @@ -259,7 +259,7 @@ describe("only request one file to generate with variant target outs", function js: ["proto/address_book_proto.js"], dts: ["proto/address_book_proto.d.ts"], }, - req + req, ); }); test("all targets with no js or dts generator", () => { @@ -278,7 +278,7 @@ describe("only request one file to generate with variant target outs", function js: ["proto/address_book_proto.js"], dts: ["proto/address_book_proto.d.ts"], }, - req + req, ); }); }); diff --git a/packages/protoplugin-test/src/custom-options.test.ts b/packages/protoplugin-test/src/custom-options.test.ts index 0649daf1e..183678f31 100644 --- a/packages/protoplugin-test/src/custom-options.test.ts +++ b/packages/protoplugin-test/src/custom-options.test.ts @@ -35,7 +35,7 @@ describe("custom options", function () { for (const file of descriptorSet.files) { if (file.name === fileName) { expect( - findCustomScalarOption(file, 50000, ScalarType.STRING) + findCustomScalarOption(file, 50000, ScalarType.STRING), ).toEqual("Hello"); } } @@ -44,7 +44,7 @@ describe("custom options", function () { const enumeration = descriptorSet.enums.get(enumName); assert(enumeration); expect( - findCustomScalarOption(enumeration, 50004, ScalarType.BOOL) + findCustomScalarOption(enumeration, 50004, ScalarType.BOOL), ).toBeTruthy(); }); test("enum value options", () => { @@ -53,11 +53,11 @@ describe("custom options", function () { for (const enumValue of enumeration.values) { if (enumValue.name === "ACTIVE") { expect( - findCustomScalarOption(enumValue, 50005, ScalarType.UINT32) + findCustomScalarOption(enumValue, 50005, ScalarType.UINT32), ).toEqual(321); } else { expect( - findCustomScalarOption(enumValue, 50005, ScalarType.UINT32) + findCustomScalarOption(enumValue, 50005, ScalarType.UINT32), ).toBeUndefined(); } } @@ -66,7 +66,7 @@ describe("custom options", function () { const msg = descriptorSet.messages.get(msgName); assert(msg); expect(findCustomScalarOption(msg, 50001, ScalarType.INT32)).toEqual( - 1234 + 1234, ); }); test("field options", () => { @@ -76,7 +76,7 @@ describe("custom options", function () { switch (member.kind) { case "oneof": expect( - findCustomScalarOption(member, 50003, ScalarType.INT64) + findCustomScalarOption(member, 50003, ScalarType.INT64), ).toEqual(BigInt(42)); break; default: { @@ -99,7 +99,7 @@ describe("custom options", function () { assert(service); const enumVal: ServiceStatus | undefined = findCustomEnumOption( service, - 50006 + 50006, ); expect(enumVal).toEqual(ServiceStatus.EXPERIMENTAL); }); @@ -122,7 +122,7 @@ describe("custom options", function () { for (const file of descriptorSet.files) { if (file.name === fileName) { expect( - findCustomScalarOption(file, 99999, ScalarType.STRING) + findCustomScalarOption(file, 99999, ScalarType.STRING), ).toBeUndefined(); } } @@ -131,7 +131,7 @@ describe("custom options", function () { const enumeration = descriptorSet.enums.get(enumName); assert(enumeration); expect( - findCustomScalarOption(enumeration, 99999, ScalarType.BOOL) + findCustomScalarOption(enumeration, 99999, ScalarType.BOOL), ).toBeUndefined(); }); test("enum value options", () => { @@ -139,7 +139,7 @@ describe("custom options", function () { assert(enumeration); for (const enumValue of enumeration.values) { expect( - findCustomScalarOption(enumValue, 99999, ScalarType.UINT32) + findCustomScalarOption(enumValue, 99999, ScalarType.UINT32), ).toBeUndefined(); } }); @@ -147,7 +147,7 @@ describe("custom options", function () { const msg = descriptorSet.messages.get(msgName); assert(msg); expect( - findCustomScalarOption(msg, 99999, ScalarType.INT32) + findCustomScalarOption(msg, 99999, ScalarType.INT32), ).toBeUndefined(); }); test("field options", () => { @@ -157,14 +157,14 @@ describe("custom options", function () { assert(quxField); assert(quxField.kind === "oneof"); expect( - findCustomScalarOption(quxField, 99999, ScalarType.INT64) + findCustomScalarOption(quxField, 99999, ScalarType.INT64), ).toBeUndefined(); const fooField = msg?.members.find((m) => m.name === "foo"); assert(fooField); assert(fooField.kind === "field"); expect( - findCustomScalarOption(fooField, 99999, ScalarType.FLOAT) + findCustomScalarOption(fooField, 99999, ScalarType.FLOAT), ).toBeUndefined(); }); test("service options", () => { @@ -177,7 +177,7 @@ describe("custom options", function () { assert(service); for (const method of service.methods) { expect( - findCustomMessageOption(method, 99999, Configuration) + findCustomMessageOption(method, 99999, Configuration), ).toBeUndefined(); } }); diff --git a/packages/protoplugin-test/src/generated-file.test.ts b/packages/protoplugin-test/src/generated-file.test.ts index 8b020b4cf..5b93a7490 100644 --- a/packages/protoplugin-test/src/generated-file.test.ts +++ b/packages/protoplugin-test/src/generated-file.test.ts @@ -25,7 +25,7 @@ import { CodeGeneratorRequest } from "@bufbuild/protobuf"; * The returned string array represents the generated file content created using printFn. */ function generate( - printFn: (f: GeneratedFile, schema: Schema) => void + printFn: (f: GeneratedFile, schema: Schema) => void, ): string[] { const req = new CodeGeneratorRequest({ parameter: "target=ts" }); const plugin = createEcmaScriptPlugin({ diff --git a/packages/protoplugin-test/src/helpers.ts b/packages/protoplugin-test/src/helpers.ts index b6a9d1304..fac61337c 100644 --- a/packages/protoplugin-test/src/helpers.ts +++ b/packages/protoplugin-test/src/helpers.ts @@ -34,7 +34,7 @@ export function assert(condition: unknown, msg?: string): asserts condition { */ export function getCodeGeneratorRequest( parameter = "", - fileToGenerate: string[] + fileToGenerate: string[], ) { const fds = getFileDescriptorSet(); return new CodeGeneratorRequest({ diff --git a/packages/protoplugin-test/src/import_extension.test.ts b/packages/protoplugin-test/src/import_extension.test.ts index 4167d5ac0..3d32a9937 100644 --- a/packages/protoplugin-test/src/import_extension.test.ts +++ b/packages/protoplugin-test/src/import_extension.test.ts @@ -25,7 +25,7 @@ import { CodeGeneratorRequest } from "@bufbuild/protobuf"; */ function generate( printFn: (f: GeneratedFile, schema: Schema) => void, - options: string[] + options: string[], ): string[] { const req = new CodeGeneratorRequest({ parameter: `target=ts,${options.join(",")}`, @@ -54,7 +54,7 @@ describe("import_extension", function () { const Bar = f.import("Bar", "./foo/bar_pb.js"); f.print`${Bar}`; }, - ["import_extension=.ts"] + ["import_extension=.ts"], ); expect(lines).toStrictEqual([ 'import { Bar } from "./foo/bar_pb.ts";', @@ -68,7 +68,7 @@ describe("import_extension", function () { const Bar = f.import("Bar", "./foo/bar_pb.js"); f.print`${Bar}`; }, - ["import_extension=none"] + ["import_extension=none"], ); expect(lines).toStrictEqual([ 'import { Bar } from "./foo/bar_pb";', @@ -82,7 +82,7 @@ describe("import_extension", function () { const Bar = f.import("Bar", "./foo/bar_pb.js"); f.print`${Bar}`; }, - ["import_extension="] + ["import_extension="], ); expect(lines).toStrictEqual([ 'import { Bar } from "./foo/bar_pb";', @@ -96,7 +96,7 @@ describe("import_extension", function () { const json = f.import("json", "./foo/bar_pb.json"); f.print`${json}`; }, - ["import_extension=.ts"] + ["import_extension=.ts"], ); expect(lines).toStrictEqual([ 'import { json } from "./foo/bar_pb.json";', diff --git a/packages/protoplugin-test/src/rewrite_imports.test.ts b/packages/protoplugin-test/src/rewrite_imports.test.ts index 7107a2099..2c0c0c252 100644 --- a/packages/protoplugin-test/src/rewrite_imports.test.ts +++ b/packages/protoplugin-test/src/rewrite_imports.test.ts @@ -27,7 +27,7 @@ import { CodeGeneratorRequest } from "@bufbuild/protobuf"; */ function generate( printFn: (f: GeneratedFile, schema: Schema) => void, - options: string[] + options: string[], ): string[] { const req = new CodeGeneratorRequest({ parameter: `target=ts,${options.join(",")}`, @@ -57,7 +57,7 @@ describe("rewrite_imports", function () { const Baz = f.import("Baz", "./foo/bar/baz_pb.js"); f.print`console.log(${Bar}, ${Baz});`; }, - ["rewrite_imports=./foo/**/*_pb.js:@scope/pkg"] + ["rewrite_imports=./foo/**/*_pb.js:@scope/pkg"], ); expect(lines).toStrictEqual([ 'import { Bar } from "@scope/pkg/foo/bar_pb.js";', @@ -71,7 +71,7 @@ describe("rewrite_imports", function () { (f, schema) => { f.print`${schema.runtime.ScalarType}.INT32`; }, - ["rewrite_imports=@bufbuild/protobuf:@scope/pkg"] + ["rewrite_imports=@bufbuild/protobuf:@scope/pkg"], ); expect(lines).toStrictEqual([ 'import { ScalarType } from "@scope/pkg";', @@ -87,7 +87,7 @@ describe("rewrite_imports", function () { const Foo = f.import("Foo", "@scope/pkg"); f.print`${Foo}`; }, - ["rewrite_imports=@scope/pkg:@other-scope/other-pkg"] + ["rewrite_imports=@scope/pkg:@other-scope/other-pkg"], ); expect(lines).toStrictEqual([ 'import { Foo } from "@other-scope/other-pkg";', diff --git a/packages/protoplugin-test/src/transpile.test.ts b/packages/protoplugin-test/src/transpile.test.ts index 7805b6cb8..52548af08 100644 --- a/packages/protoplugin-test/src/transpile.test.ts +++ b/packages/protoplugin-test/src/transpile.test.ts @@ -25,7 +25,7 @@ import type { Schema } from "@bufbuild/protoplugin/ecmascript"; function transpile( genTs: (schema: Schema) => void, parameter = "target=ts+js+dts", - parseOption?: (key: string, value: string | undefined) => void + parseOption?: (key: string, value: string | undefined) => void, ): (name: string) => string[] { const req = new CodeGeneratorRequest({ parameter, @@ -167,7 +167,7 @@ describe("transpile", function () { "target=ts+js+dts,rewrite_imports=./test/*_pb.js:@buf/test,rewrite_imports=./test/*_web.js:@buf/web,keep_empty_files=true,foo,bar=", () => { /* custom parse fn to allow for custom options without erroring*/ - } + }, ); expect(linesOf("test.ts")).toStrictEqual([ diff --git a/packages/protoplugin/src/create-es-plugin.ts b/packages/protoplugin/src/create-es-plugin.ts index 01a604144..576794021 100644 --- a/packages/protoplugin/src/create-es-plugin.ts +++ b/packages/protoplugin/src/create-es-plugin.ts @@ -80,7 +80,7 @@ interface PluginInit { transpile?: ( files: FileInfo[], transpileJs: boolean, - transpileDts: boolean + transpileDts: boolean, ) => FileInfo[]; } @@ -117,7 +117,7 @@ export function createEcmaScriptPlugin(init: PluginInit): Plugin { keepEmptyFiles, init.name, init.version, - pluginParameter + pluginParameter, ); const targetTs = schema.targets.includes("ts"); @@ -175,7 +175,7 @@ export function createEcmaScriptPlugin(init: PluginInit): Plugin { let files = getFileInfo(); if (!targetTs && tsFiles.length > 0) { files = files.filter( - (file) => !tsFiles.some((tsFile) => tsFile.name === file.name) + (file) => !tsFiles.some((tsFile) => tsFile.name === file.name), ); } @@ -196,7 +196,7 @@ export function createEcmaScriptPlugin(init: PluginInit): Plugin { function parseParameter( parameter: string | undefined, - parseOption: PluginOptionParseFn | undefined + parseOption: PluginOptionParseFn | undefined, ) { let targets: Target[] = ["js", "dts"]; let tsNocheck = true; @@ -260,7 +260,7 @@ function parseParameter( if (parts.length !== 2) { throw new PluginOptionError( `${key}=${value}`, - "must be in the form of :" + "must be in the form of :", ); } const [pattern, target] = parts; @@ -319,7 +319,7 @@ function parseParameter( } function splitParameter( - parameter: string | undefined + parameter: string | undefined, ): { key: string; value: string; raw: string }[] { if (parameter == undefined) { return []; diff --git a/packages/protoplugin/src/ecmascript/custom-options.ts b/packages/protoplugin/src/ecmascript/custom-options.ts index dfd382807..a0bb1f685 100644 --- a/packages/protoplugin/src/ecmascript/custom-options.ts +++ b/packages/protoplugin/src/ecmascript/custom-options.ts @@ -29,7 +29,7 @@ import { export function findCustomScalarOption( desc: AnyDesc, extensionNumber: number, - scalarType: T + scalarType: T, ): ScalarValue | undefined { const reader = createBinaryReader(desc, extensionNumber); if (reader) { @@ -86,7 +86,7 @@ export function findCustomScalarOption( export function findCustomMessageOption>( desc: AnyDesc, extensionNumber: number, - msgType: MessageType + msgType: MessageType, ): T | undefined { const reader = createBinaryReader(desc, extensionNumber); if (reader) { @@ -109,7 +109,7 @@ export function findCustomMessageOption>( */ export function findCustomEnumOption( desc: AnyDesc, - extensionNumber: number + extensionNumber: number, ): number | undefined { return findCustomScalarOption(desc, extensionNumber, ScalarType.INT32); } @@ -156,7 +156,7 @@ type ScalarValue = T extends ScalarType.STRING */ function createBinaryReader( desc: AnyDesc, - extensionNumber: number + extensionNumber: number, ): BinaryReader | undefined { const opt = desc.proto.options; let reader: BinaryReader | undefined = undefined; diff --git a/packages/protoplugin/src/ecmascript/gencommon.ts b/packages/protoplugin/src/ecmascript/gencommon.ts index 5f69d3985..f51db6ca9 100644 --- a/packages/protoplugin/src/ecmascript/gencommon.ts +++ b/packages/protoplugin/src/ecmascript/gencommon.ts @@ -35,7 +35,7 @@ export function makeFilePreamble( pluginName: string, pluginVersion: string, parameter: string, - tsNoCheck: boolean + tsNoCheck: boolean, ): string { const builder: string[] = []; const trimSuffix = (str: string, suffix: string): string => @@ -103,7 +103,7 @@ export function makeJsDoc( | DescField | DescService | DescMethod, - indentation = "" + indentation = "", ): Printable { const comments = desc.getComments(); let text = ""; @@ -166,7 +166,7 @@ export function makeJsDoc( */ export function getFieldTyping( field: DescField, - file: GeneratedFile + file: GeneratedFile, ): { typing: Printable; optional: boolean } { const typing: Printable = []; let optional = false; @@ -264,12 +264,12 @@ export function literalString(value: string): string { export function getFieldExplicitDefaultValue( field: DescField, - protoInt64Symbol: ImportSymbol + protoInt64Symbol: ImportSymbol, ): Printable | undefined { switch (field.fieldKind) { case "enum": { const value = field.enum.values.find( - (v) => v.number === field.getDefaultValue() + (v) => v.number === field.getDefaultValue(), ); if (value !== undefined) { return [value.parent, ".", localName(value)]; diff --git a/packages/protoplugin/src/ecmascript/generated-file.ts b/packages/protoplugin/src/ecmascript/generated-file.ts index 5f83fe4bf..1ba1ff9eb 100644 --- a/packages/protoplugin/src/ecmascript/generated-file.ts +++ b/packages/protoplugin/src/ecmascript/generated-file.ts @@ -122,7 +122,7 @@ export function createGeneratedFile( pluginParameter: string; tsNocheck: boolean; }, - keepEmpty: boolean + keepEmpty: boolean, ): GeneratedFile & GenerateFileToFileInfo { let preamble: string | undefined; const el: El[] = []; @@ -133,7 +133,7 @@ export function createGeneratedFile( preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.pluginParameter, - preambleSettings.tsNocheck + preambleSettings.tsNocheck, ); }, print( @@ -149,7 +149,7 @@ export function createGeneratedFile( // If called with a tagged template literal printables = buildPrintablesFromFragments( printableOrFragments as TemplateStringsArray, - rest + rest, ); } else { // If called with just an array of Printables @@ -191,7 +191,7 @@ type El = ImportSymbol | string; function elToContent( el: El[], importerPath: string, - rewriteImportPath: RewriteImportPathFn + rewriteImportPath: RewriteImportPathFn, ): string { const c: string[] = []; const symbolToIdentifier = processImports( @@ -200,7 +200,7 @@ function elToContent( rewriteImportPath, (typeOnly, from, names) => { const p = names.map(({ name, alias }) => - alias == undefined ? name : `${name} as ${alias}` + alias == undefined ? name : `${name} as ${alias}`, ); const what = `{ ${p.join(", ")} }`; if (typeOnly) { @@ -208,7 +208,7 @@ function elToContent( } else { c.push(`import ${what} from ${literalString(from)};\n`); } - } + }, ); if (c.length > 0) { c.push("\n"); @@ -230,7 +230,7 @@ function printableToEl( printables: Printable[], el: El[], createTypeImport: CreateTypeImportFn, - runtimeImports: RuntimeImports + runtimeImports: RuntimeImports, ): void { for (const p of printables) { if (Array.isArray(p)) { @@ -273,7 +273,7 @@ function printableToEl( function buildPrintablesFromFragments( fragments: TemplateStringsArray, - values: Printable[] + values: Printable[], ): Printable[] { const printables: Printable[] = []; fragments.forEach((fragment, i) => { @@ -289,14 +289,14 @@ function buildPrintablesFromFragments( type MakeImportStatementFn = ( typeOnly: boolean, from: string, - names: { name: string; alias?: string }[] + names: { name: string; alias?: string }[], ) => void; function processImports( el: El[], importerPath: string, rewriteImportPath: RewriteImportPathFn, - makeImportStatement: MakeImportStatementFn + makeImportStatement: MakeImportStatementFn, ) { // identifiers to use in the output const symbolToIdentifier = new Map(); @@ -395,7 +395,7 @@ function processImports( } const from = makeImportPathRelative( importerPath, - rewriteImportPath(s.from) + rewriteImportPath(s.from), ); if (i.types.size > 0) { makeImportStatement(true, from, buildNames(i.types)); @@ -410,7 +410,7 @@ function processImports( function literalNumber( value: number, - runtimeImports: RuntimeImports + runtimeImports: RuntimeImports, ): El[] | string { if (Number.isNaN(value)) { return [runtimeImports.protoDouble, ".NaN"]; diff --git a/packages/protoplugin/src/ecmascript/import-path.ts b/packages/protoplugin/src/ecmascript/import-path.ts index ede8c81ab..c74a014a6 100644 --- a/packages/protoplugin/src/ecmascript/import-path.ts +++ b/packages/protoplugin/src/ecmascript/import-path.ts @@ -64,7 +64,7 @@ const cache = new WeakMap< export function rewriteImportPath( importPath: string, rewriteImports: RewriteImports, - importExtension: string + importExtension: string, ): string { let ri = cache.get(rewriteImports); if (ri === undefined) { @@ -137,7 +137,7 @@ function starToRegExp(star: string): RegExp { export function makeImportPath( file: DescFile, bootstrapWkt: boolean, - filesToGenerate: DescFile[] + filesToGenerate: DescFile[], ): string { // Well-known types are published with the runtime package. We usually want // the generated code to import them from the runtime package, with the @@ -179,7 +179,7 @@ export function deriveImportPath(filename: string): string { */ export function makeImportPathRelative( importer: string, - importPath: string + importPath: string, ): string { if (!relativePathRE.test(importPath)) { // We don't touch absolute imports, like @bufbuild/protobuf diff --git a/packages/protoplugin/src/ecmascript/import-symbol.ts b/packages/protoplugin/src/ecmascript/import-symbol.ts index 7005243c1..afb2bbf81 100644 --- a/packages/protoplugin/src/ecmascript/import-symbol.ts +++ b/packages/protoplugin/src/ecmascript/import-symbol.ts @@ -57,7 +57,7 @@ export type ImportSymbol = { export function createImportSymbol( name: string, from: string, - typeOnly?: boolean + typeOnly?: boolean, ): ImportSymbol { const id = `import("${from}").${name}`; const s: ImportSymbol = { diff --git a/packages/protoplugin/src/ecmascript/runtime-imports.ts b/packages/protoplugin/src/ecmascript/runtime-imports.ts index 8dc9b2d28..543051941 100644 --- a/packages/protoplugin/src/ecmascript/runtime-imports.ts +++ b/packages/protoplugin/src/ecmascript/runtime-imports.ts @@ -65,12 +65,12 @@ export function createRuntimeImports(bootstrapWkt: boolean): RuntimeImports { function infoToSymbol( name: keyof typeof codegenInfo.symbols, - bootstrapWkt: boolean + bootstrapWkt: boolean, ): ImportSymbol { const info = codegenInfo.symbols[name]; const symbol = createImportSymbol( name, - bootstrapWkt ? info.privateImportPath : info.publicImportPath + bootstrapWkt ? info.privateImportPath : info.publicImportPath, ); return info.typeOnly ? symbol.toTypeOnly() : symbol; } diff --git a/packages/protoplugin/src/ecmascript/schema.ts b/packages/protoplugin/src/ecmascript/schema.ts index c73946aec..4024d1330 100644 --- a/packages/protoplugin/src/ecmascript/schema.ts +++ b/packages/protoplugin/src/ecmascript/schema.ts @@ -93,7 +93,7 @@ export function createSchema( keepEmptyFiles: boolean, pluginName: string, pluginVersion: string, - pluginParameter: string + pluginParameter: string, ): SchemaController { const descriptorSet = createDescriptorSet(request.protoFile); const filesToGenerate = findFilesToGenerate(descriptorSet, request); @@ -124,7 +124,7 @@ export function createSchema( pluginParameter, tsNocheck, }, - keepEmptyFiles + keepEmptyFiles, ); generatedFiles.push(genFile); return genFile; @@ -148,7 +148,7 @@ export function createSchema( export function toResponse(files: FileInfo[]): CodeGeneratorResponse { return new CodeGeneratorResponse({ supportedFeatures: protoInt64.parse( - CodeGeneratorResponse_Feature.PROTO3_OPTIONAL + CodeGeneratorResponse_Feature.PROTO3_OPTIONAL, ), file: files.map((f) => { if (f.preamble !== undefined) { @@ -161,15 +161,17 @@ export function toResponse(files: FileInfo[]): CodeGeneratorResponse { function findFilesToGenerate( descriptorSet: DescriptorSet, - request: CodeGeneratorRequest + request: CodeGeneratorRequest, ) { const missing = request.fileToGenerate.filter((fileToGenerate) => - descriptorSet.files.every((file) => fileToGenerate !== file.name + ".proto") + descriptorSet.files.every( + (file) => fileToGenerate !== file.name + ".proto", + ), ); if (missing.length) { throw `files_to_generate missing in the request: ${missing.join(", ")}`; } return descriptorSet.files.filter((file) => - request.fileToGenerate.includes(file.name + ".proto") + request.fileToGenerate.includes(file.name + ".proto"), ); } diff --git a/packages/protoplugin/src/ecmascript/transpile.ts b/packages/protoplugin/src/ecmascript/transpile.ts index 7b69a4b6e..d6890a789 100644 --- a/packages/protoplugin/src/ecmascript/transpile.ts +++ b/packages/protoplugin/src/ecmascript/transpile.ts @@ -97,7 +97,7 @@ function createTranspiler(options: ts.CompilerOptions, files: FileInfo[]) { export function transpile( files: FileInfo[], transpileJs: boolean, - transpileDts: boolean + transpileDts: boolean, ): FileInfo[] { const options: ts.CompilerOptions = { ...defaultOptions, @@ -118,27 +118,27 @@ export function transpile( data: string, writeByteOrderMark: boolean, onError?: (message: string) => void, - sourceFiles?: readonly ts.SourceFile[] + sourceFiles?: readonly ts.SourceFile[], ) => { // We have to go through some hoops here because the header we add to each // file is not part of the AST. So we find the TypeScript file we // generated for each emitted file and add the header to each output ourselves. if (!sourceFiles) { err = new Error( - `unable to map emitted file "${fileName}" to a source file: missing source files` + `unable to map emitted file "${fileName}" to a source file: missing source files`, ); return; } if (sourceFiles.length !== 1) { err = new Error( - `unable to map emitted file "${fileName}" to a source file: expected 1 source file, got ${sourceFiles.length}` + `unable to map emitted file "${fileName}" to a source file: expected 1 source file, got ${sourceFiles.length}`, ); return; } const file = files.find((x) => sourceFiles[0].fileName === x.name); if (!file) { err = new Error( - `unable to map emitted file "${fileName}" to a source file: not found` + `unable to map emitted file "${fileName}" to a source file: not found`, ); return; } @@ -147,14 +147,14 @@ export function transpile( preamble: file.preamble, content: data, }); - } + }, ); if (err) { throw err; } if (result.emitSkipped) { throw Error( - "An problem occurred during transpilation and files were not generated. Contact the plugin author for support." + "An problem occurred during transpilation and files were not generated. Contact the plugin author for support.", ); } return results; diff --git a/packages/protoplugin/src/error.ts b/packages/protoplugin/src/error.ts index b1ce2cac9..94817c280 100644 --- a/packages/protoplugin/src/error.ts +++ b/packages/protoplugin/src/error.ts @@ -17,7 +17,7 @@ export class PluginOptionError extends Error { super( reason === undefined ? `invalid option "${option}` - : `invalid option "${option}: ${reasonToString(reason)}` + : `invalid option "${option}: ${reasonToString(reason)}`, ); } } diff --git a/packages/protoplugin/src/run-node.ts b/packages/protoplugin/src/run-node.ts index 880b93186..b563bcdc6 100644 --- a/packages/protoplugin/src/run-node.ts +++ b/packages/protoplugin/src/run-node.ts @@ -36,7 +36,7 @@ export function runNodeJs(plugin: Plugin): void { } if (args.length !== 0) { process.stderr.write( - `${plugin.name} accepts a google.protobuf.compiler.CodeGeneratorRequest on stdin and writes a CodeGeneratorResponse to stdout\n` + `${plugin.name} accepts a google.protobuf.compiler.CodeGeneratorRequest on stdin and writes a CodeGeneratorResponse to stdout\n`, ); process.exit(1); return; diff --git a/scripts/set-workspace-version.js b/scripts/set-workspace-version.js index 8b74dee5b..5176972b9 100755 --- a/scripts/set-workspace-version.js +++ b/scripts/set-workspace-version.js @@ -27,7 +27,7 @@ if (process.argv.length < 3) { "If a package depends on another package from the workspace, the", "dependency version is updated as well.", "", - ].join("\n") + ].join("\n"), ); process.exit(1); }