protolint
protolint copied to clipboard
Fail to run `protolint lint .` and get go syntax error
I install protolint with brew install protolint
and run protolint lint .
to verify the following proto file.
message Book {
optional string name = 1;
}
but getting error result:
$ protolint lint .
found "\"message\"(Token=27, Pos=tests/test.proto:1:1)" but expected [syntax] at /home/runner/go/pkg/mod/github.com/yoheimuta/go-protoparser/[email protected]/parser/syntax.go:62. Use -v for more details
How can I fix the problem?
What's more, I want to create my Dockerfile installed protolint and using the image to run pre-commit. I get a same result in the ci.
The project: https://gitlab.com/DoneSpeak/container-image
Here is the docker file:
# syntax=docker/dockerfile:1
FROM golang:1.17.7-bullseye
RUN apt-get update
RUN apt-get -y install python3
RUN apt-get -y install python3-setuptools
RUN apt-get -y install python3-pip
RUN pip install pre-commit==2.17.0
RUN pip install yamllint==1.26.3
RUN mkdir -p /opt/protolint
RUN curl -L https://github.com/yoheimuta/protolint/releases/download/v0.37.0/protolint_0.37.0_Linux_x86_64.tar.gz | tar -xz -C /opt/protolint
RUN ln -s /opt/protolint/protolint /usr/local/bin/protolint
The fail ci job is pre-commit ci job.
another docker file is:
# syntax=docker/dockerfile:1
FROM python:3.8.12-buster
RUN pip install pre-commit==2.17.0
RUN pip install yamllint==1.26.3
RUN mkdir -p /opt/protolint
RUN curl -L https://github.com/yoheimuta/protolint/releases/download/v0.37.0/protolint_0.37.0_Linux_x86_64.tar.gz | tar -xz -C /opt/protolint
RUN ln -s /opt/protolint/protolint /usr/local/bin/protolint
Maybe I have figured out the reason. The parse requires a syntax
key world in the protobuf file which I didn't provide. I think it should be a verify error like the following content instead of a code error which makes me very confused.
[tests/test.proto:4:3] Field "query" should avoid required for proto3
@DoneSpeak
Maybe I have figured out the reason.
That's right.
I think it should be a verify error like the following content instead of a code error which makes me very confused.
I agree with you. The parser should make the error message clearer.
Same here
Yours is different but related to protolint not being able to parse UTF-8-BOM files :D for now just save them as UTF-8 but it should be fixed - no reason this can't be handled.
Thank you for clarifying the issue.
Handling UTF-8 BOM (U+FEFF) properly seems worth it. Whenever I have time, I'm getting to it.