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

[Bug]: Buf linter reports incorrect source line numbers #344

Open
sallustfire opened this issue Jul 19, 2024 · 2 comments
Open

[Bug]: Buf linter reports incorrect source line numbers #344

sallustfire opened this issue Jul 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@sallustfire
Copy link
Contributor

sallustfire commented Jul 19, 2024

What happened?

The reported line numbers from running the buf_lint_aspect are always <souce_path>:1:1<messaage>, which adds friction to resolving lint errors especially when the source file is large.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.1.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: HEAD

How to reproduce

This can be reproduced with the file.proto source in example/

Via aspect:

bazel build --aspects=//tools/lint:linters.bzl%buf --@aspect_rules_lint//lint:fail_on_violation --output_groups=rules_lint_report //src:foo_proto
INFO: Analyzed target //src:foo_proto (0 packages loaded, 0 targets configured).

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
--buf-plugin_out: src/file.proto:1:1:Import "src/unused.proto" is unused.
Aspect //tools/lint:linters.bzl%buf of //src:foo_proto failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.168s, Critical Path: 0.03s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully

Via buf cli

bazel run @rules_buf_toolchains//:buf -- lint --config=buf.yaml src/file.proto
WARNING: Build option --@@aspect_rules_lint~//lint:fail_on_violation has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed target @@rules_buf~~buf~rules_buf_toolchains//:buf (0 packages loaded, 1 target configured).
INFO: Found 1 target...
INFO: Elapsed time: 0.224s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: /home/.cache/bazel/_bazel/d387874fc4e6234b1e2f92e13a10d0a3/external/rules_buf~~buf~rules_buf_toolchains/buf lint '--config=buf.yaml' src/file.proto
src/file.proto:3:1:Import "src/unused.proto" is unused.

As a sanity check aspect lint produces the same output:

aspect lint //src:foo_proto
INFO: Analyzed target //src:foo_proto (232 packages loaded, 9814 targets configured).
INFO: Found 1 target...
Aspect //tools/lint:linters.bzl%buf of //src:foo_proto up-to-date:
  bazel-bin/src/foo_proto.AspectRulesLintBuf.report
  bazel-bin/src/foo_proto.AspectRulesLintBuf.report.exit_code
INFO: Elapsed time: 4.369s, Critical Path: 0.03s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
INFO: Build completed successfully, 2 total actions
Lint results for //src:foo_proto:

--buf-plugin_out: src/file.proto:1:1:Import "src/unused.proto" is unused.

Any other information?

I haven't more than glanced at the source code, but I believe this is a problem with the protoc plugin protoc-gen-but-lint and not rules_lint. The buf cli is a go program that lints the sources directly and not as a protoc plugin. It may be the case that using the protoc plugin also introduces subtle differences in the DX if IDE plugins are integrating with the buf cli directly.

@sallustfire sallustfire added the bug Something isn't working label Jul 19, 2024
@sallustfire
Copy link
Contributor Author

@alexeagle Here's what I see, and I saw the same problem with rules_proto_grpc and their buf lint integration in the past. That makes me thing it's a general problem with the protoc plugin, but I don't know how to square that with the smoke test you performed the other day.

@alexeagle
Copy link
Member

To your earlier point, I do think switching to call buf lint instead of protoc --plugin=some-buf-thing is likely more correct and easier to reproduce or get help from the Buf team. Worth investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants