Use most local buf.yaml configuration
yoitsro opened this issue ยท 4 comments
We use a lerna monorepo to manage our backend and our protobufs are included within a package inside the monorepo. This means that the root path of the schemas is something like:
packages/schemas/schema-store/acmecorp
We have our buf config at packages/schemas/schema-store/buf.yaml
which looks something like:
version: v1beta1
build:
roots:
- .
lint:
use:
- DEFAULT
However, within our actual protobufs, we're seeing this error:
Files with package "acmecorp.authentication.v1" must be within a directory "acmecorp/authentication/v1" relative to root but were in directory "packages/schemas/schema-store/acmecorp/authentication/v1". (PACKAGE_DIRECTORY_MATCH)
Would it be possible for the extension to traverse up the directories to look for the configuration file and run buf relative to that directory, rather than the project's root?
Is this a problem with the buf CLI or just the vscode-buf extension? Are you talking about seeing the error in your editors? Currently the vscode-buf extension assumes that your buf.yaml
is in the root of your repository, which may cause this errors to appear erroneously.
EDIT:
Just realised this is posted on the vscode-buf extension issue tracker, my bad. Yes this is a problem, it's not currently possible to configure where the extension should look for the buf.yaml file.
I guess based on the way other linters work, the usual methodology is in the way I've described.
Further down the line, it could pave the way for specific directories to have a specific configuration which extends a configuration found further up the directory tree but I'm pretty certain that's not the way buf has been built (which may be for the best! ๐).
Would it be possible for the extension to traverse up the directories to look for the configuration file and run buf relative to that directory, rather than the project's root?
I don't think that would be a good idea. The default behavior of other linters is to add the path as additional configuration option(F.ex in the local settings.json
).
I think passing an option to a custom buf.yaml
could be a good approach:
Doing buf lint --help
get's me:
--config string The config file or data to use
Taking ESLint as example, you could add something along the lines of:
"buf.lint.options": "--config src/myApi/buf.yaml"
See: https://github.com/Microsoft/vscode-eslint/#settings-options
This has now been addressed with the latest versions of the vscode-buf
plugin along with the latest version of buf
.
As a couple of points of interest:
Would it be possible for the extension to traverse up the directories to look for the configuration file and run buf relative to that directory, rather than the project's root?
This is basically the methodology we've used -- if you have a buf
configuration defined up the tree from the provided input file, we will use that as our buf
configuration. So this will include lint
configurations, etc.
We do not require users to specify directories for buf
configurations, currently. In the future, we can consider adding the ability to specify config paths and/or proto roots, but for now, this should address the issues reported by the OP.
Thanks!