api-linter: unexpected lint warning when providing mutiple files
Environment details
$ api-linter --version [22:41:48]
api-linter 1.68.0
$ tree proto [22:44:30]
proto
├── google
│ └── api
│ ├── annotations.proto
│ └── http.proto
└── ....
Steps to reproduce
api-linterworks great when only provided with one file
$ api-linter -I proto proto/google/api/http.proto [22:45:42]
- file_path: proto/google/api/http.proto
problems:
- message: 'Proto package and directory structure mismatch: The proto package must match the proto directory structure.'
location:
start_position:
line_number: 17
column_number: 1
end_position:
line_number: 17
column_number: 19
path: proto/google/api/http.proto
rule_id: core::0191::proto-package
rule_doc_uri: https://linter.aip.dev/191/proto-package
....
$ api-linter -I proto proto/google/api/annotations.proto [22:47:37]
- file_path: proto/google/api/annotations.proto
problems:
- message: 'Proto package and directory structure mismatch: The proto package must match the proto directory structure.'
location:
start_position:
line_number: 17
column_number: 1
end_position:
line_number: 17
column_number: 19
path: proto/google/api/annotations.proto
rule_id: core::0191::proto-package
rule_doc_uri: https://linter.aip.dev/191/proto-package
- Having unexpected lint warning when providing mutiple files
$ api-linter -I proto proto/google/api/http.proto proto/google/api/annotations.proto [22:44:53]
2025/01/31 22:45:42 google/api/http.proto:29:9: symbol "google.api.Http" already defined at proto/google/api/http.proto:29:9
google/api/http.proto:33:21: symbol "google.api.Http.rules" already defined at proto/google/api/http.proto:33:21
google/api/http.proto:41:8: symbol "google.api.Http.fully_decode_reserved_expansion" already defined at proto/google/api/http.proto:41:8
google/api/http.proto:308:9: symbol "google.api.HttpRule" already defined at proto/google/api/http.proto:308:9
google/api/http.proto:313:10: symbol "google.api.HttpRule.selector" already defined at proto/google/api/http.proto:313:10
google/api/http.proto:321:12: symbol "google.api.HttpRule.get" already defined at proto/google/api/http.proto:321:12
google/api/http.proto:324:12: symbol "google.api.HttpRule.put" already defined at proto/google/api/http.proto:324:12
google/api/http.proto:327:12: symbol "google.api.HttpRule.post" already defined at proto/google/api/http.proto:327:12
google/api/http.proto:330:12: symbol "google.api.HttpRule.delete" already defined at proto/google/api/http.proto:330:12
google/api/http.proto:333:12: symbol "google.api.HttpRule.patch" already defined at proto/google/api/http.proto:333:12
google/api/http.proto:339:23: symbol "google.api.HttpRule.custom" already defined at proto/google/api/http.proto:339:23
google/api/http.proto:348:10: symbol "google.api.HttpRule.body" already defined at proto/google/api/http.proto:348:10
google/api/http.proto:356:10: symbol "google.api.HttpRule.response_body" already defined at proto/google/api/http.proto:356:10
google/api/http.proto:361:21: symbol "google.api.HttpRule.additional_bindings" already defined at proto/google/api/http.proto:361:21
google/api/http.proto:318:9: symbol "google.api.HttpRule.pattern" already defined at proto/google/api/http.proto:318:9
google/api/http.proto:365:9: symbol "google.api.CustomHttpPattern" already defined at proto/google/api/http.proto:365:9
google/api/http.proto:367:10: symbol "google.api.CustomHttpPattern.kind" already defined at proto/google/api/http.proto:367:10
google/api/http.proto:370:10: symbol "google.api.CustomHttpPattern.path" already defined at proto/google/api/http.proto:370:10
This behavior is weird and looks like a bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 31
@noahdietz @quirogas I can confirm that everything works just fine on my end, in Neovim, when using a build from the main branch, commit 7ecaa42 😄👍
@fredrikaverpil our previous fix was not as robust as previously believed so @quirogas worked on a more robust fix intended to address the duplication created by the original issue of supplying a subdirectory of the CWD as an
-Iexplicit import. We’ve been testing it in a variety of cases and withdescriptor-set-insans any-Iand we think it is working. If you are interested in trying it out in your neovim set up to be extra sure, please do so when it is merged if you are able to install a commit rather than a release. We aren’t in a rush to release as it is but will likely do so next week.woohoo!! Thanks so much for the responsiveness after hours on your side, and the patience while I got the fix going.
@fredrikaverpil let’s try this again, shall we? v1.69.2 contains the fix.
When you get a chance, please verify that it works for you. I’ve tested various absolute path inputs and I believe it will do the job, even with your
--proto-path=.patch still in placeAlso filed https://github.com/googleapis/api-linter/issues/1479 to come up with a test harness for the CLI. Local testing was not good enough here and we can do better.
Ok so I see what I did incorrectly: If no
--proto-pathare specified, we want only want to attempt resolving against..We still don’t want to supply both
--proto-pathinputs and.together toprotoparse.ResolveFilenamesbecause it may result in an improperly resolved file name and then duplicate proto entry as originally mentioned in this issue.This is very helpful thank you @fredrikaverpil . That points to the exact behavior of
protoparse.ResolveFilenamesthat needs to be handled.Hmmm, weirdly enough I cannot repro exactly what I wrote above. Hang on. I must have missed something… because this definitively broke earlier (for multiple people).
Ok thanks @fredrikaverpil I’ll take another look! Apologies!
I’ve been thinking about that, and spoke to it a bit in the #1466 description. For
ResolveFilenames, if any of the paths-to-resolve are deemed relative to at least one of the provided paths-to-resolve-against, the path-to-resolve is unchanged. This was the problem with including"."in the paths-to-resolve-against, it made any relative path-to-resolve automatically unresolved against the other paths-resolve-against. And when you think about it, a relative path provided to a CLI is typically relative to"."already.I think we should be OK.