Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing new line in the generate files #380

Open
slashmili opened this issue Oct 22, 2024 · 2 comments
Open

Missing new line in the generate files #380

slashmili opened this issue Oct 22, 2024 · 2 comments

Comments

@slashmili
Copy link

Problem

After the files are generated, despite the fact that we pass it to Generator.Util.format/1 when they get saved into file the code is missing a \n char.

The problem arias because we expect all the source code in our repo pass mix format check but the formatter doesn't like the files are missing \n at the end of the file. We usually have to run mix format after files are generated which is fine but then on the next regenerate, all the files get changed.

Expected

We add extra \n to all places we generate the code!

Question

Where do you think is the right place to add newline? in Generator.Util.format/1 or add it to all places that call Generator.Util.format/1 ?

@v0idpwn
Copy link
Collaborator

v0idpwn commented Oct 22, 2024

Hi, @slashmili, thanks for the report.
I'm not able to reproduce the behaviour: here, generated files are passing mix format --check-formatted. Would you share instructions to reproduce, and the versions you're using? (Elixir, Erlang, Protobuf)

@slashmili
Copy link
Author

slashmili commented Oct 23, 2024

Sure thing, sorry I forgot to mention the version:

mix new test_proto
cd test_proto
git init
# edit mix.exs and add deps
#  [
#      {:protobuf, "~> 0.10"},
#      {:google_protos, "~> 0.1"}
#  ]
mix deps.get
# Edit formater.exs to add import_deps: [:protobuf],
curl -O https://raw.githubusercontent.com/grpc/grpc/master/examples/protos/helloworld.proto
git add .
protoc --elixir_out=one_file_per_module=true:./lib helloworld.proto
git add lib/helloworld/
mix format
git diff
diff --git a/lib/helloworld/hello_reply.pb.ex b/lib/helloworld/hello_reply.pb.ex
index 0cfaaec..bbf8ec1 100644
--- a/lib/helloworld/hello_reply.pb.ex
+++ b/lib/helloworld/hello_reply.pb.ex
@@ -4,4 +4,4 @@ defmodule Helloworld.HelloReply do
   use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0"

   field :message, 1, type: :string
-end
\ No newline at end of file
+end
diff --git a/lib/helloworld/hello_request.pb.ex b/lib/helloworld/hello_request.pb.ex
index 639a09c..71d7267 100644
--- a/lib/helloworld/hello_request.pb.ex
+++ b/lib/helloworld/hello_request.pb.ex
@@ -4,4 +4,4 @@ defmodule Helloworld.HelloRequest do
   use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0"

   field :name, 1, type: :string
-end
\ No newline at end of file
+end

the diff in highlighted text:

diff --git a/lib/helloworld/hello_reply.pb.ex b/lib/helloworld/hello_reply.pb.ex
index 0cfaaec..bbf8ec1 100644
--- a/lib/helloworld/hello_reply.pb.ex
+++ b/lib/helloworld/hello_reply.pb.ex
@@ -4,4 +4,4 @@ defmodule Helloworld.HelloReply do
   use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0"

   field :message, 1, type: :string
-end
\ No newline at end of file
+end
diff --git a/lib/helloworld/hello_request.pb.ex b/lib/helloworld/hello_request.pb.ex
index 639a09c..71d7267 100644
--- a/lib/helloworld/hello_request.pb.ex
+++ b/lib/helloworld/hello_request.pb.ex
@@ -4,4 +4,4 @@ defmodule Helloworld.HelloRequest do
   use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.13.0"

   field :name, 1, type: :string
-end
\ No newline at end of file
+end

Software versions:

uname -a
Darwin MMP.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 x86_64

elixir --version
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.15.4 (compiled with Erlang/OTP 26)

protoc --version
libprotoc 3.21.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants