-
Notifications
You must be signed in to change notification settings - Fork 269
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
Set top-level LintConfig
and BreakingConfig
and use for image inputs
#3111
Conversation
I've also tested this against the user repro in the issue. |
@@ -34,7 +34,7 @@ var ( | |||
false, | |||
false, | |||
"", | |||
false, | |||
true, // We default to allowing comment ignores in v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkwarren caught an issue with the default v2
lint config, which should default to allowing comment ignores (https://buf.build/docs/configuration/v2/buf-yaml)
# v1 configurations had an allow_comment_ignores option to opt-in to comment ignores. # # In v2, we allow comment ignores by default, and allow opt-out from comment ignores # with the disallow_comment_ignores option. disallow_comment_ignores: false
Co-authored-by: Philip K. Warren <[email protected]>
|
||
func (c *bufYAMLFile) DefaultBreakingConfig() BreakingConfig { | ||
if c.defaultBreakingConfig == nil { | ||
return c.moduleConfigs[0].BreakingConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually correct - this is just choosing a single configuration among potentially many and calling it the default, which is what we've tried to avoid pretty consistently with v2. I think what you're actually looking for in this PR is some concept of "if there is a single configuration, give it to me, otherwise tell me it is not present". What this logic looks like:
SingleLintConfig() (LintConfig, bool)
- If v1, return the v1 configuration.
- If v2:
- If there is one module with attached configuration, return the attached configuration. Else, return the top-level configuation.
- If there is more than one module, return false
If you get false, do nothing, as we do right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if a user passes the following file to --config
:
version: v2
lint:
use:
- MINIMAL
breaking:
use:
- WIRE
modules:
- path: foo
- path: bar
lint:
use:
- DEFAULT
except:
- IMPORT_USED
- path: vendor
Wouldn't we want them to pick up the top-level configs for the default in the case of:
$ buf breaking base.bin --against new.bin --config custom.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd probably want to error, or at least print a warning along the lines of:
WARN Configuration {from flag,at $PATH was used} but this configuration had multiple modules. Buf cannot deduce which {lint,breaking} configuration to use with your image. Ignoring your configuration and using the default configuration instead.
I could see an argument to also modify the logic to "if >1 modules, return the top-level module", but that may just leave us open to even more support stuff in the long-term.
Going a different direction, we could take the position that for image inputs only, we always take the top-level configuration, and never look into specific module configs. This would mean that if you had the following:
version: v2
modules:
- path: .
lint: ...
The modules[0].LintConfig
would not be picked up and propagated. The position here would be that module-specific configuration never applies to an image, and we treat configuration for an image as if it were a "new" module in the modules
list.
This may be what moduleConfigs[0]
does in practice for v1, but not for v2, but I'd also be comfortable with adopting this position, it seems intellectually consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a fan of the latter approach for images. For v1
, the behaviour will stay the same since there should only ever be a single lint/breaking config. For v2
, we check for a top-level config, and if nothing is there, then we would use whatever the version defaults are. And yes, in the case you provided, where there is a single module, path: .
, that would not be considered the default configuration. Changes incoming.
ModuleConfig
and use for image inputs
// For v2 buf.yaml files, if a top-level module config exists, then it will be the top-level | ||
// module config. Otherwise, this will return nil, so callers should be aware this may be | ||
// empty. | ||
TopLevelModuleConfig() ModuleConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a ModuleConfig
? We only want LintConfig
and BreakingConfig
, I don't know what a top-level ModuleConfig
is in terms of v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used ModuleConfig
because it worked better for the warnings and also to account for situations like:
version: v2
name: <remote>/<owner>/<module>
But in that case, it would be the default anyway, so it doesn't super matter, and also since we're not printing out the warnings, I can swap it back to LintConfig
and BreakingConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated back to LintConfig
and BreakingConfig
, and updated the PR title + description.
ModuleConfig
and use for image inputsLintConfig
and BreakingConfig
and use for image inputs
This PR exposes the top-level lint and breaking configs for
buf.yaml
files.For
v1
buf.yaml
files, there is only ever oneModuleConfig
, so thecorresponding lint and breaking configs are used.
For
v2
buf.yaml
files, if a top-level lint and/or breaking config exists, thenwe return those.
Otherwise,
TopLevelLintConfig()
/TopLevelBreakingConfig
will returnnil
.We use the top-level lint/breaking configs, if possible, with image inputs, since we
cannot determine which specific
v2
module config to use with images. Inthe case where there is no top-level config, we fall back to defaults.
Fixes #3080