aspect-build / aspect-build/rules_lint
[Bug]: Buf linter reports incorrect source line numbers
- Dominant language
- Starlark
- Stars
- 154
- Forks
- 125
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 20
Description
### What happened?
The reported line numbers from running the buf_lint_aspect are always `:1:1`, 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.
Contributor guide
Research direction
Reproduce the discrepancy with example/file.proto using the Bazel aspect commands and the direct buf CLI command. Start by tracing the tools/lint:linters.bzl entry point and the protoc-gen-but-lint plugin mentioned in the report, comparing how each formats diagnostics. Done means the aspect output reports the actual source location, such as src/file.proto:3:1, rather than always 1:1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100