square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.26k stars 570 forks source link

Formatting add redundant whitespaces #2705

Open daniszam opened 1 year ago

daniszam commented 1 year ago

I'm not sure if this can be considered a bug.

But my idea is to reformat the file after these changes.

I expected only an empty string between string a = 1; string b = 2;, but I actually got an empty string with two whitespaces.

    @Test
    public void should_format_file_without_empty_line_with_whitespaces() {
        // given
        var loader = new SchemaLoader(FileSystems.getDefault());
        var linker = new Linker(loader, new ErrorCollector(), true, true);
        var testFileLocation = Location.get("<TEST_PROTO_FILE>");
        loader.initRoots(List.of(testFileLocation), List.of(testFileLocation));
        var file = loader.load("test/file.proto");
        var schema = linker.link(List.of(file));

        // when
        var protoFile = schema.protoFile("test/file.proto");

        // then
        assertThat(protoFile.toSchema())
                .isEqualTo("""
                        // Proto schema formatted by Wire, do not edit.
                        // Source: test/file.proto

                        syntax = "proto3";

                        package test.dependency;

                        message TestMessage {
                          message NestedMessage {
                            string a = 1;

                            string b = 2;
                          }
                        }
                        """);
    }
oldergod commented 1 year ago

This is how it works right now. https://github.com/square/wire/blob/master/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt#L59-L71