protolint icon indicating copy to clipboard operation
protolint copied to clipboard

Fail to run `protolint lint .` and get go syntax error

Open DoneSpeak opened this issue 2 years ago • 5 comments

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

DoneSpeak avatar Feb 22 '22 17:02 DoneSpeak

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 avatar Feb 22 '22 18:02 DoneSpeak

@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.

yoheimuta avatar Feb 23 '22 01:02 yoheimuta

Same here

image image

CorrM avatar Aug 01 '22 09:08 CorrM

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.

ricsiLT avatar Sep 12 '22 13:09 ricsiLT

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.

yoheimuta avatar Sep 17 '22 07:09 yoheimuta